As subtle as a flying brick.

Configuring Static Routes

Static routes improves overall performance of your network (especially bandwidth saving). They are also useful in stub networks (i.e. there is only one link to the network). For example, each LAN (located at different offices) is connected to HQ IDC (Internet data center) using single T1/LL/Wan links.

For example under Red Hat/Fedora Linux you can add static router for eth0 network interface by editing /etc/sysconfig/network-scripts/route-eth0 file. Under Debian Linux add static route by editing /etc/network/interface file.

Display Current Routing Table Using ip command

By using the ip command, you can setup and view static route. For example, to display current routing table you can type command:
# ip route show

Sample output: dev eth1 proto kernel  scope link  src dev eth0  proto kernel  scope link  src
default via dev eth0

You can add static route using following command:

ip route add {NETWORK} via {IP} dev {DEVICE}

For example network available via

# ip route add via dev eth1

Alternatively, you can use old good route command:

# route add -net netmask gw dev eth1

Linux Persistence Routes

The drawback of ‘ip’ or ‘route’ command is that, when Linux reboots it will forget static routes. So store them in configuration file. Static routing describes a system that does not implement adaptive routing. In these systems routes through a data network are described by fixed paths (statically). These routes are usually entered into the router by the system administrator

Red Hat (RHEL) / CentOS / Fedora Linux Persistence Static Routing

You need to open /etc/sysconfig/network-scripts/route-eth0 file to define static routes for eth0 interface:

# cat /etc/sysconfig/network-scripts/route-eth0

Sample Output:

default dev eth0 via dev eth0 via dev eth0

How do I define static routing for network via router?

Open /etc/sysconfig/network-scripts/route-eth0:

# vi /etc/sysconfig/network-scripts/route-eth0

Append following line: via

Save and close the file. Restart networking:

# service network restart

Verify new routing table:

# route -n

Debian / Ubuntu Linux Persistence Static Routing

Open configuration file /etc/network/interfaces

# cat /etc/network/interfaces


auto eth0
iface eth0 inet static
up route add -net netmask gw
down route del -net netmask gw

Debian / Ubuntu Linux Static Routing for 2 interfaces:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
	### static routing ###
        post-up route add -net netmask gw
        pre-down route del -net netmask gw

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

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your 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 )

Connecting to %s