Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I installed and ran successfully a pptp vpn client on a ubuntu server (aws ec2).

I want to be able access certain websites through this vpn. However, still able to ssh and connect to server.

$ route -n  #after connecting to vpn

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface         UG    100    0        0 eth0   U     0      0        0 eth0 UH    0      0        0 ppp0 UGH   0      0        0 eth0

The routing table is as above after connection. If, I make ppp0 as default gateway, i am not able to ssh to server again.

So, I want to add some rules, so that whenever an application/script request for certain web address or HTTP/HTTPS requests, it will redirect the traffic over ppp0 or the vpn connection but not other connections.

Is it possible?

Thanks in advance!

share|improve this question

You can mark packets with iptables and route marked packets via iproute2.
It is described in LARTC
In your case first you need create iptables rule:

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

Where - ip address of target website.
Then add routing table with iprule

echo 201 crawl >> /etc/iproute2/rt_tables
ip rule add fwmark 1 table crawl

Check it

ip rule ls
0:  from all lookup local 
32765:  from all fwmark 0x1 lookup crawl 
32766:  from all lookup main 
32767:  from all lookup default

Now add default route to table crawl:

ip route add default via dev ppp0 table crawl

That's all, packets with address destination and destination port 80 will be routed via ppp0 interface.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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