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 205.153.203.98 via 205.153.203.97.
How do I setup persistent static route so that 10.0.0.0/255.0.0.0 traffic route via 10.70.201.61 router only?
| Tutorial details | |
|---|---|
| Difficulty | Intermediate (rss) |
| Root privileges | Yes |
| Requirements | Ubuntu |
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.
Syntax
The syntax is as follows:
route add -net $NET netmask $MASK gw $GATEWAY route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.254
You need to add above syntax to post-up command as follows:
post-up command post-up route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.254
Given command will run after bringing the interface up.
Example
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 address 10.70.201.5 netmask 255.255.255.192 ### Ubuntu Linux add persistent route command ### post-up route add -net 10.0.0.0 netmask 255.0.0.0 gw 10.70.201.6 #----------------------------------------# # Setup eth1 - connected to the Internet # #----------------------------------------# auto eth1 allow-hotplug eth1 iface eth1 inet static address 205.153.203.98 netmask 255.255.255.248 ### Ubuntu Linux - This is your default gateway ### gateway 205.153.203.97
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
OR
$ ip route show
Send ICMP ECHO_REQUEST to network hosts on your lan/vlan:
$ ping lan-ip-address
$ ping 10.70.201.6
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
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop












{ 4 comments… read them below or add one }
Hi
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
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 10.0.0.0 netmask 255.0.0.0 gw 10.70.201.6 (1)
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 :- 117.239.18.213 , subnet 255.255.255.248, gat- 117.239.18.209, dns – 218.248.255.193,218.248.240.179
And the second eth1 ip is none :-
but i want use 192.168.100.1 to 192.168.100.255 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 .
Hi
I wanted to add additionally that deleting specific routes can be done like so.
x.x.x.22 x.x.x.173 255.255.255.255 UGH 0 0 0 bond0
x.x.x.21 x.x.x.12 255.255.255.255 UGH 0 0 0 bond0
route del -net x.x.x.22 netmask 255.255.255.255 gw x.x.x.173