We first tried to use pptp as our site-to-site VPN protocol and it required some static routes to allow LAN traffic (eth0 for example) to be routed to another site (ppp0 for example). These commands can help to add a static route on a Linux server:


Advantages of Static Routes

  • Easy to configure
  • No routing protocol overhead

Disadvantages of Static Routes

  • Network changes require manual reconfiguration
  • Network outages cannot be automatically routed around
  • Does not scale well in large networks.


Add a Static route using “route” command

route add [-net|-host] <IP/Net> netmask <Mask> gw <Gateway IP> dev <Int>X


route add -net netmask gw dev eth0
route add -host netmask gw dev eth0

This adds the route immediatly to the Kernel IP routing table. To confirm the route has been successfully, simply type the “route” command with no arguements:


Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface * U 0 0 0 eth0
localnet * U 0 0 0 eth0 * U 0 0 0 eth0 * U 0 0 0 eth0
default UG 0 0 0 eth0


netstat -rn

to print the Kernel IP Routing table.

To keep the Static Route persistent or you want to add the route entries to the network script files (not using the route command) then all you need to do is to edit the file


and the static routes in the following format:

up route add [-net|-host] <host/net>/<mask> gw <host/IP> dev <Interface>


up route add -net gw dev eth1

And the file will like the following

sudo cat /etc/network/interfaces

The output should show something like this

sudo cat /etc/network/interfaces

The output should show something like this

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0 eth1

iface eth0 inet static
# dns-* options are implemented by the resolvconf package, if installed

iface eth1 inet static

# static route
up route add -net gw dev eth1

The above has 2 Ethernet interfaces and the static route is added to the interface eth1.

For the change to /etc/network/interface to take effect. please restart the “networking” service as follows:

sudo /etc/init.d/networking restart

NOTE: If you added the route already using the “route” then there is no need to restart the networking service because, the next time server is restarted this takes effect.



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s