I have a ppp0 interface set up as a VPN tunnel using this guide. Now I need to route traffic on specific ports (80, 443) through the ppp0 interface. Ideally, if the VPN server is down, all the HTTP(S) requests should fail.

There are a lot of answers for similar issues suggesting to use iptables, so I guess that's the way the go, but I can't figure out the right commands to use for this particular scenario.


Here we shall take www as the service for routing. Use mangle table of iptable for modifying the www packets.

sudo iptables -t mangle -A OUTPUT -p tcp --dport 80 -j MARK --set-mark 0x1

We are marking all packets with destination port 80 as 0x1 .

Now save and restart iptables.

service iptables save
service iptables restart

Next, create a new IP route table in /etc/iproute2/rt_tables by just giving an entry

100 wwwtable

Write rule for www packets.

ip rule add fwmark 0x1 lookup wwwtable

Add route at new table wwwtable. All other traffic will go through the default gateway, which can be seen by ip route show command.

We copy all entries except default gateway entry from main table.

sudo ip route show table main | grep -Ev ^default | while read ROUTE ; do ip route add table wwwtable $ROUTE; done

Add default gateway entry for www packets to table wwwtable

sudo ip route add default dev ppp0 table wwwtable

Use ip route show table wwwtable to show all routes at wwwtable.

Repeat everything for https on port 443.

  • Thank you for the detailed answer, however, the first command doesn't seem to work, it returns an error saying Bad argument '80'. I'm on 14.04 LTS. – blade Sep 15 '15 at 8:04
  • sorry, typo error. I fix them. – 2707974 Sep 15 '15 at 8:25
  • This seems to be the right direction, but it's not working for me. While the routing is changed somehow, it doesn't load websites, all the requests just time out. BTW: there's another typo in /etc/iproute2/rt_table, it should be rt_tables and there is no iptables service, at least not on my system. And I think you can specify --dports 80,443 both at the same time. – blade Sep 18 '15 at 10:46

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.