Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
0.0.0.0         172.31.0.1      0.0.0.0         UG    100    0        0 eth0
172.31.0.0      0.0.0.0         255.255.240.0   U     0      0        0 eth0
192.168.68.35   0.0.0.0         255.255.255.255 UH    0      0        0 ppp0
209.99.22.18    172.31.0.1      255.255.255.255 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

1 Answer 1


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 1.2.3.4 --dport 80 -j MARK --set-mark 0x1

Where 1.2.3.4 - 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 192.168.68.35 dev ppp0 table crawl

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

share|improve this answer

Your Answer

 
discard

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.