Server Administration & Management

How to add static route in linux

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).

Display Current Routing Table Using following 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 eth0

Alternatively, you can use old good route command:

# route add -net netmask gw dev eth0

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. 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:

# service network restart

Verify new routing table:

# route -n

To make the routing information persistent, add the “route add” line as seen above into the /etc/rc.local file.


February 8, 2012 - Posted by | Tips & Tricks, Unix/Linux | , , ,

No comments yet.

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 )

Google+ photo

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

%d bloggers like this: