Ubuntu Linux Add Static Route

by on October 25, 2012 · 6 comments· LAST UPDATED October 25, 2012

in ,

I've two network interfaces. One connected to eth0 and another connected to eth1 as follows:

eth0 => private network with private IP in 10.x.x.x/8 range.
eth1 => ISP router with public IP via

How do I setup persistent static route so that traffic route via router only?

Tutorial details
DifficultyIntermediate (rss)
Root privilegesYes
Estimated completion timeN/A

You need to edit /etc/network/interfaces file. This file describes the network interfaces available on your system and how to activate them including ubuntu Linux server static routing.


The syntax is as follows:

route add -net $NET netmask $MASK gw $GATEWAY
route add -net netmask gw

You need to add above syntax to post-up command as follows:

post-up command
post-up route add -net netmask gw

Given command will run after bringing the interface up.


Edit /etc/network/interfaces, enter:
$ sudo vi /etc/network/interfaces

# Feel free to change IP and gateway    #
# as per your local setup and routing   #
# policy                                #
# Last edited by root @ 23/Oct/2012     #
# Setup the loopback network interface (lo0) #
auto lo
iface lo inet loopback
# Setup eth0 - connected to private LAN/VLAN #
auto eth0
allow-hotplug eth0
iface eth0 inet static
        ### Ubuntu Linux add persistent route command ###
        post-up route add -net netmask gw
# Setup eth1 - connected to the Internet #
auto eth1
allow-hotplug eth1
iface eth1 inet static
        ### Ubuntu Linux - This is your default gateway ###

Save and close the file. You need to restart the networking as follows:
$ sudo service networking restart
OR as root user:
# service networking restart

How do I verify that my Ubuntu Linux interfaces static routing working correctly?

Type the following command to see current routing table, run:
$ /sbin/route -n
$ ip route show
Send ICMP ECHO_REQUEST to network hosts on your lan/vlan:
$ ping lan-ip-address
$ ping

Send ICMP ECHO_REQUEST to network hosts using the ISP gateway (ping requests to public sites such as Google/Yahoo):
$ ping google.com
$ ping cyberciti.biz

Tweet itFacebook itG+ itDownload PDF versionFound an error/typo on this page?

{ 6 comments… read them below or add one }

1 Balakrishnan B October 25, 2012 at 5:33 pm

I am trying to do something similar but not the same. I have two interfaces
eth0 -> wired has connectivity to internet (tikona broadband)
eth1 -> wireless connecting to a local Beetel 450TC1 modem configured in bridge mode
I have two issues :
1) If I connect to wireless router. I am not able to access to internet (most of the times). How do I fix this?
2) I have a android tablet connecting to same wireless router. I want to setup the rules such that I am able to acess internet from my tablet. I first tried to create a wifi hot spot directly from laptop but it is not recognized in the tablet. So trying if I can do something with the wireless router. Tablet is able to connect to the router and also access the web server hosted in the laptop


2 Alexander October 27, 2012 at 5:40 am

At you the mistake in an example seems. It seems to me the correct address of a router comes to an end on 61 or I am mistaken?

post-up route add -net netmask gw (1)


3 Govind Tiwari February 17, 2013 at 1:25 pm

Respected Sir,
I try following thing please guide me .
at this time i am using ubuntu 12.04 server edition and i have two network interface in my server. i want using one for direct internet static ip or second for LAN network
My server Eth0 interface ip is :- , subnet, gat-, dns –,
And the second eth1 ip is none :-
but i want use to class ip for My LAN network
so please guide me how can i do this . please tell me. also i want use my eth1 is realising ip for local network user accordingly like dhcp. so please guide me the configuration .


4 james Cordell February 20, 2013 at 11:33 am


I wanted to add additionally that deleting specific routes can be done like so.

x.x.x.22 x.x.x.173 UGH 0 0 0 bond0
x.x.x.21 x.x.x.12 UGH 0 0 0 bond0

route del -net x.x.x.22 netmask gw x.x.x.173


5 Sibin October 29, 2013 at 5:02 am

Hi, Im not able to access internet when i change my linux(rhel6) in static mode from dhcp..can anyone tell me whats the issue…??
I did put the same ip ( in static mode when it was in dhcp..
gw, mask
restarted network…but im not able to access interent..


6 Tim Macking November 6, 2013 at 7:02 pm

I think this should be: post-up route add -net netmask gw (1)


Leave a Comment

Tagged as: , , , , ,

Previous Faq:

Next Faq: