Is there a way to redirect all traffic, UDP and TCP, coming to and from eth1 and eth2 through a SOCKS proxy (Tor) which then passes it through eth0?
eth0:
Internet in – leads to the main router, then the cable modem
eth1:
A USB Ethernet port setup as a modem (I think that's the word I'm looking for, right?)
eth2:
A USB WiFi antenna setup as a WiFi hotspot
Could I use something like iptables to directly route it through Tor or would I need an adapter like Privoxy?
Best Answer
First, you need tun2socks (often a part of the 'badvpn' package). tun2socks sets up a virtual interface which you can route traffic through, and that traffic will get sent through the target socks proxy.
Setting it up gets a little tricky as you only want to route certain traffic through the tunnel.
This script should do what you want:
Explanation:
This is the socks server we will use.
These generate a random ID to use for the tunnel. Since you may have other tunnels on the system, we can't just use
tun0
ortun1
. 99% of the time this will work fine. Adjust accordingly though.These set up the tunnel interface
tun2socks
will use.These create a routing table with a single rule which sends any traffic with firewall mark
$id
(covered next) through the tunnel.These set firewall mark
$id
on any TCP packets coming ineth1
oreth2
. We only want to match TCP. Socks can't handle UDP or ICMP (tun2socks does have a way to forward UDP, but it's more complicated, and so I'm leaving it out).This starts tun2socks up. It'll sit in the foreground until terminated.
These tear down everything we created during the setup process. They will only run once
badvpn-tun2socks
exits.