Pages

Welcome to My Blog

This is to share my IT experience with friends all around the world.
I have been working in Linux Fedora Systems for more than 8 years. Its fun to share knowledge and learn..
As everyone knows when a problem arises in your systems "googling" is the way that many depend on..

All the posts here are my working experiences during my working life.. So you can count on it..

I have added the references where I got help in solving IT issues


Thursday, January 5, 2012

Static Routers in Linux

Adding a static route in Linux is a basic but essential requirement. We need to do this in 2 situations.
One is just adding a static route to the Kernel's IP routing table through the command line. This is mainly for testing purposes.
The commands that  can be used are;
    1. ip route add
    2. route add

I have tested the second one 'route add' with following format.
    route add -net <destination_network_ipblock> netmask <subnet_mask> gw <gateway_interface_ip>
    e.g.    route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.200.254

The above given example will add a route to 192.168.2.0/24 network via 192.168.200.254. The important thing here is, a route to 192.168.200.254 should already be installed in the Kernel's routing table (i.e. the server you are configuring static routes, should know how the communicate with 192.168.200.254)

More details related to the second method can be observed with 'man route' command;

The other situation is to install static routes permanently in to the kernel's routing table.
This can be achieved with static-route file.
I have used it in several servers. You need to create a file with the name 'static-routes' at /etc/sysconfig directory.

The static routes you with to apply should be given in line by line. Format of a routing line is as follows;
any net <destination_network_ipblock> netmask <subnet_mask> gw <gateway_interface_ip>
e.g
any net 192.168.2.0 netmask 255.255.255.0 gw 192.168.200.254

The example shows an entry related to the same routing described above.
When the OS is loading, this file will be executed and routing will be applied to the kernel.

Good reference:
http://www.cyberciti.biz/tips/configuring-static-routes-in-debian-or-red-hat-linux-systems.html