iptables -A PREROUTING -i usb0 -t mangle -p tcp --dport 8080 -j MARK --set-mark 1

iptables -L

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination   

// route the traffic with mark 1 to myusb0 table

ip rule add fwmark 1 table myusb0

ip route ls dev usb1  proto kernel  scope link  src  metric 1 dev usb0  proto kernel  scope link  src  metric 1 

ip rule ls

0:  from all lookup local 
32762:  from all fwmark 0x1 lookup myusb0 
32763:  from lookup myusb0 
32764:  from lookup myusb1 
32766:  from all lookup main 
32767:  from all lookup default 

ip route ls table myusb0

default via dev usb0 

ip route ls table myusb1

default via dev usb1

// open up socks on port 8080

ssh -f -N -D root@

// check if it works

curl --socks5 ip.appspot.com

channel 1: open failed: administratively prohibited: open failed
curl: (7) Failed to receive SOCKS5 connect request ack.

I have two Internet connections from two different ISPs and I would like to open up a proxy/socks5 on each one. I thought it would make sense to associate each interface with a port number so that we can manage the connections.

I've created two routing tables (myusb0 and myusb1) for each device (usb1 and usb0), then marked the traffic based on the port number (e.g. on port 8080 I mark it 1) and route the traffic on that mark to the specific table (myusb0). Then I tried to open a socks5 on that IP and tried it locally but for some reasons it doesn't work.

Once I get it working locally I think I should open up the socks in a reverse manner so that I can make it available to the remote server(s) that need to use it.

Any idea why it's not currently working and how I should fix it? For some reasons I think the socks connection is trying the default gateway from the main table which is not set instead to follow the port 8080 mark rule and try the myusb0 table. I'm using Ubuntu (latest version).

Should be mentioned that both ISPs provide dynamic IPs


As I suspected it seems that the traffic to port 8080 is not being routed (nevermind the socks issue) but I don't know why

 curl portquiz.net:8080 
curl: (7) Couldn't connect to server

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.