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.

Right now I have a PPTP VPN set up on my remote ubuntu VPS. I would like to have certain applications use the VPN to access the internet (rtorrent, irssi, among others). Currently, it is set up like this:

eth0 Link encap:Ethernet HWaddr 00:16:3e:94:38:ce inet addr:66.xxx.xxx.xxx Bcast:66.xxx.xxx.xxx Mask:255.255.255.0

eth1 Link encap:Ethernet HWaddr 00:16:3e:d7:58:a1 inet addr:10.2.0.111 Bcast:10.255.255.255 Mask:255.0.0.0

lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0

ppp0 Link encap:Point-to-Point Protocol inet addr:192.168.10.244 P-t-P:192.168.9.1 Mask:255.255.255.255

Essentially, the way I've seen this issue manifest is like this.

When I run

curl --interface eth0 checkip.dyndns.com

I get

<html><head><title>Current IP Check</title></head><body>Current IP Address: 66.xxx.xxx.xxx</body></html>

And when I run

curl --interface ppp0 checkip.dyndns.com

I get

<html><head><title>Current IP Check</title></head><body>Current IP Address: 95.xxx.xxx.xxx</body></html>

Which is correct.

However, when I run

curl --interface 192.168.10.244 checkip.dyndns.com

it times out and I get nothing. Which doesn't seem to make any sense, as 192.168.10.244 is the IP address of ppp0, and it doesn't seem to me that it should be any different from the above command. Am I missing something? If I can get this to work in curl, I'll be able to get it to work in rtorrent and irssi as I would like as well, curl is just easier to test for this sort of thing. Are there any good starting points for tackling this problem?

EDIT: Fixed it! Here is how I did it.

First I created a new routing table:

# echo "200 vpn" >> /etc/iproute2/rt_tables

Then, I created a rule for requests sourced from my ppp0 IP address to lookup from that new table

# ip rule add from 192.168.10.244 table 200

Then, I created a rule in that table to use ppp0.

# ip route add default dev ppp0 table 200

It works perfectly! Now when I attempt the previously failing curl command:

# curl --interface 192.168.10.244 checkip.dyndns.com
<html><head><title>Current IP Check</title></head><body>Current IP Address: 95.xxx.xxx.xxx</body></html>
share|improve this question
    
which commands did you use for that configuration ? i'm looking for a solution but couldn't find anything works. –  motto Feb 20 '13 at 1:19
add comment

1 Answer

Your reasoning is incorrect. Binding to an IP address only chooses the source IP address. It has no effect on the route taken to the destination, which is what you want to control.

To do what you want to do, you need to set up a form of policy routing called source based routing. This is typically done by creating two routing tables, one for each connection, and deciding the routing table to use based on the local source IP address. See any of the many howtos on policy routing.

share|improve this answer
    
I tried this, and am having the following issue #echo 200 vpns >> /etc/iproute2/rt_tables #ip rule add from 192.168.10.244 table vpns #ip route add default via 192.168.9.1 dev ppp0 table vpns RTNETLINK answers: No such process –  user127658 Apr 11 '12 at 9:52
    
ugh, tried to make it look correct, but basically when I perform the command "ip route add default via 192.168.9.1 dev ppp0 table vpns" I get "RNETLINK answers: No such process". Is that the incorrect command? –  user127658 Apr 11 '12 at 9:56
    
You mean "table 200", right? Routing tables are numbered. –  David Schwartz Apr 11 '12 at 10:16
    
Still the same result. RNETLINK answers: No such process. –  user127658 Apr 12 '12 at 0:12
    
Maybe your VPS doesn't support policy routing. –  David Schwartz Apr 12 '12 at 0:17
show 2 more comments

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.