Automatically add routes when PPTP client connects

Average: 3.3 (886 votes)

Recently i faced the problem of connecting two LANs using PPTP and an intermediate PPTP server. I had to use this approach  because the network setup was such that none of the LAN routers (DD-WRT) could contact the other but both could contact an intermediate server.

In order to achieve this PPTP clients must be always assigned the same IP and when connected, routes to each LAN must be added to the routing table of the intermediate server.

Network setup

Network name IP range
PPTP Server network


PPTP Clients and server

I installed a PPTP server on a CentOS server using this HOWTO and i assigned static IPs for the two routers. To assign static IPs on PPTP clients you must enter the desired IP in the chap-secrets file.

chap-secrets file on the intermediate server:

# Secrets for authentication using CHAP
# client server secret IP addresses

LAN1 *   LAN1pass
LAN2 *   LAN2pass

This way each client (router) gets always the same IP. Make sure that these static IPs are not in the PPTP client IP range.

Then setup DD-WRT PPTP clients to connect to the intermediate server:

Server IP or DNS Name

Remote Subnet

Remote Subnet Mask

MPPE Encryption

mppe required,no40,no56,stateless


The final step is to add a route to each router's LAN when it connects.
There is a file for running commands when PPP goes up or down. On CentOS it is located at /etc/ppp/ip-up.local or /etc/ppp/ip-up

Adding the following lines does the trick:


case "$5" in
                /sbin/route add -net gw
                /sbin/route add -net gw

Make the script executable: chmod 755 ip-up.local

Arguments available in ip-up and ip-up.local scripts

Argument Description
$1 the interface name used by pppd (e.g. ppp3)
$2 the tty device name
$3 the tty device speed
$4 the local IP address for the interface
$5 the remote IP address
$6 the current IP address before connecting to the VPN


glqxz9283 sfy39587stf02 mnesdcuix8