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 dev ppp0
route add -net yyy.yyy.0.0 netmask 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).

  • I am not sure I follow what xxx.xxx.0.0 should be. Public IP ranges or private ones? If the remote subnet is, and I need to connect to a machine at via the VPN, shall I use – László Jul 14 '14 at 15:56

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 dev ppp0\nroute add -net yyy.yyy.0.0 netmask dev ppp0\n&\n|' /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 dev ppp0\n&\n|' /tmp/pptpd_client/ip-up
sed -i '' -e 's|exit 0|route add -net xxx.xxx.0.0 netmask dev ppp0\n&\n|' /tmp/pptpd_client/ip-up
sed -i '' -e 's|exit 0|route add -net xxx.xxx.0.0 netmask dev ppp0\n&\n|' /tmp/pptpd_client/ip-up

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


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.

  • 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 May 25 '11 at 11:35
  • How should this work if I want to use the router as a link in a chain of VPNs: a PPTP server for an incoming connection and then route the outgoing traffic to a VPN channel? The router itself uses the subnet locally and also for its own VPN clients, the network it connects to as a client uses – László Jul 14 '14 at 16:01

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?

  • ip-up then, makes sense. The poster on your link couldn't find it either :) – Tim Jan 6 '11 at 16:50

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

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.