Setup Steps for Raspberry Pi (or VM) with 4G Dongle and Squid Proxy

ATuringtest

Elite Member
Joined
Mar 8, 2019
Messages
1,625
Reaction score
2,848
Now I know a lot of people don't want to pay the stupid costs to make 4g proxies.
Or some dick writes a script then when they make money with it delete it off git hub, leave the page on their website so it gets traffic.
So I used chatgpt-4 and some basic knowledge of Debian.
And, before people get confused I used a VM workstation - found a a very simple guide on YT to install Raspi in a VM. Shit loads of YT videos on how to use VMware.
This avoids setting up routing tables and firewalls in the router - so less hassle by about 50%.
This should work 99% of the time on a physical Raspi - but you will have to do the router table stuff.

Note* Attached is a text file of the entire Chatgpt conversation. Its RAW no formatting but you may get some more help if you come across problems with your setup.
++ I like to test and debug constantly each step.

  1. Next step is to make a script I can rotate on a timer. Add it as a monitored service
  2. Script that can be trigger from a local machine to rotate the IP.
  3. Build a Web interface to show usage etc.
  4. Add more 4 dongles.
== I'll add them as I do it to this thread. ==

Theoretically you can just keep adding 4g dongles by just changing the dongles IP to a static in IP tables - we will see lol

Just to show this worked I tested it from a another Win10 VMware on the same Host machine as the VMRaspi

DEBUG:urllib3.connectionpool:Starting new HTTP connection (1): 192.168.1.136:3128
send: b'GET http://httpbin.org/ip HTTP/1.1\r\nHost: httpbin.org\r\nUser-Agent: python-requests/2.31.0\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\n\r\n'
DEBUG:urllib3.connectionpool:http://192.168.1.136:3128 "GET http://httpbin.org/ip HTTP/1.1" 200 49
reply: 'HTTP/1.1 200 OK\r\n'
header: Date: Sat, 10 Feb 2024 22:14:29 GMT
header: Content-Type: application/json
header: Content-Length: 49
header: Server: gunicorn/19.9.0
header: Access-Control-Allow-Origin: *
header: Access-Control-Allow-Credentials: true
header: Expires: Sat, 10 Feb 2024 22:17:13 GMT
header: X-Cache: MISS from raspberry
header: X-Cache-Lookup: HIT from raspberry:3128
header: Via: 1.1 raspberry (squid/4.13)
header: Connection: keep-alive
Successfully accessed through proxy
Response content: {
"origin": "192.168.1.244, 148.252.129.138"

148.252.129.138 - This was my 4g WAN IP


Rich (BB code):
Setup Steps for Raspberry Pi with 4G Dongle and Squid Proxy

  1. Install Squid: sudo apt-get update && sudo apt-get install squid
  2. Edit Squid Configuration: sudo nano /etc/squid/squid.conf
    • Add: http_access allow localnet
    • Add your local network: acl localnet src 192.168.1.0/24 (adjust IP range accordingly)
  3. Enable IP Forwarding:
    • Edit sysctl: sudo nano /etc/sysctl.conf
    • Add: net.ipv4.ip_forward=1
    • Apply: sudo sysctl -p
  4. Set up IP Tables for NAT:
    • sudo iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
    • sudo iptables -A FORWARD -i eth1 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
    • sudo iptables -A FORWARD -i eth0 -o eth1 -j ACCEPT
  5. Make IP Tables rules persistent:
    • Install: sudo apt-get install iptables-persistent
  6. Identify the 4G Dongle Interface (e.g., eth1) and its Gateway IP.
  7. Adjust Routing:
    • Delete existing default route: sudo ip route del default via 192.168.1.254 dev eth0
    • Add new default route via 4G dongle: sudo ip route add default via 192.168.3.1 dev eth1 metric 100
  8. Restart Squid: sudo systemctl restart squid
  9. Test the proxy using your device or directly via: curl -x http://raspberry_pi_ip:3128 http://example.com
 

Attachments

Back
Top