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.

My home network in the USA is behind a Buffalo router (G300NH) running their version of DD-WRT. I use the built-in PPTP VPN client to connect to a VPN provider in the UK. I route certain traffic over the VPN (so it has a UK source address, for various entirely legal reasons) which I achieved by following the instructions in the DD-WRT docs and my VPN provider's own instructions. I placed two commands like this in the firewall script:

route add -net xxx.xxx.0.0 netmask 255.255.0.0 dev ppp0
route add -net yyy.yyy.0.0 netmask 255.255.0.0 dev ppp0

I didn't put any of the iptables rules in since it my setup doesn't seem to need them. It works like a charm. Traffic to the xxx subnets goes over the VPN, everything else goes out over my ISP's own pipes.

The problem comes when the VPN drops, which it does occasionally. DD-WRT does a fine job of reconnecting it automatically, but the routes are trashed every time that happens.

How do I automate the process of re-establishing my routes? I thought about static routes, but the IP address of the VPN connection is dynamically assigned (which is why I'm using dev ppp0).

share|improve this question
add comment

4 Answers

up vote 2 down vote accepted

The sed command works fine except that dd-wrt does not create the ip-up file until after the pptpd daemon is started. So I added a delay to the startup script to give time and also execute the ip-up command after adding the routes. This should solve it for you.

Here is the startup command for your router:

sleep 40
sed -i '' -e 's|exit 0|route add -net xxx.xxx.0.0 netmask 255.255.0.0 dev ppp0\nroute add -net yyy.yyy.0.0 netmask 255.255.0.0 dev ppp0\n&\n|' /tmp/pptpd_client/ip-up
/tmp/pptpd_client/ip-up

You could alternatively do this:

sleep 40
sed -i '' -e 's|exit 0|route add -net xxx.xxx.0.0 netmask 255.255.0.0 dev ppp0\n&\n|' /tmp/pptpd_client/ip-up
sed -i '' -e 's|exit 0|route add -net xxx.xxx.0.0 netmask 255.255.0.0 dev ppp0\n&\n|' /tmp/pptpd_client/ip-up
sed -i '' -e 's|exit 0|route add -net xxx.xxx.0.0 netmask 255.255.0.0 dev ppp0\n&\n|' /tmp/pptpd_client/ip-up
/tmp/pptpd_client/ip-up

adding as many routes as needed. The & replaces the exit 0.

share|improve this answer
add comment

The problem with dd-wrt's implementation is that the pptp client sets up the route table correctly, but the server does not. Typically you can connect in from the client but not out from the server. This will fix the route table on the server side every time the connection comes up and will work across reboots and reconnects.

From the DD-WRT running as the pptp SERVER, click on the 'administration' tab then on the 'command' tab, then enter this:

/bin/sh -c 'echo "ip route add XX.XX.XX.0/24 dev ppp0" >> /tmp/pptpd/ip-up'

Then save as 'Startup Script' to make it permanent. Of course change the XX's to the subnet of the CLIENT network. If you have multiple client subnets, then just add multiple lines of the above with the correct subnets for each client network.

share|improve this answer
    
Thanks for the answer. It didn't work for me: I have no /tmp/pptpd directory; there's a /tmp/pptpd_client with an ip-up script, but appending the route command to that will not work since the last line in that file is 'exit 0'. –  Tim Kemp May 25 '11 at 11:35
add comment

You would want to put the route commands into an ip-up script that is called when the link comes up. I'm not sure exactly where to put these in dd-wrt; I've switched to openwrt but here is a link that might help?

http://83.141.4.210/phpBB2/viewtopic.php?p=93158

share|improve this answer
    
ip-up then, makes sense. The poster on your link couldn't find it either :) –  Tim Kemp Jan 6 '11 at 16:50
add comment

You cannot edit or add files that easily on some ddwrt routers.

All 4 ddwrt routers I use generate these files when pptp client is run, making it impossible to just change or add files.

Here is a workaround that seems to work on most routers http://stadar.org/content/ddwrt-pptp-client-add-routes-after-connection

share|improve this answer
add comment

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.