Static routes will be added usually through “route add” or “ip route” command. However, “route add” command configures routing on the runtime and doesn’t persist the configuration after a reboot. To make it persistent across reboots, you have to add it to /etc/sysconfig/network-scripts/route-<interface-file> . For example, static routes for the eth0 interface would be stored in the /etc/sysconfig/network-scripts/route-eth0 file. Here are the Steps to configure static routing in Linux.

To add static route using “route add” in command line:

# route add -net 192.168.100.0 netmask 255.255.255.0 gw 192.168.10.1 dev eth0

1# route add -net 192.168.100.0 netmask 255.255.255.0 gw 192.168.10.1 dev eth0

To add static route using “ip route” command:

# ip route add 192.168.100.0/24 via 192.168.10.1 dev eth1

1# ip route add 192.168.100.0/24 via 192.168.10.1 dev eth1

Adding Persistent static route:

You need to edit /etc/sysconfig/network-scripts/route-eth0 file to define static routes for eth0 interface. This configuration will be persistent even after the server is rebooted.

GATEWAY0=192.168.10.1 NETMASK0=255.255.255.0 ADDRESS0=192.168.100.0

123GATEWAY0=192.168.10.1 NETMASK0=255.255.255.0 ADDRESS0=192.168.100.0

GATEWAY1=10.64.34.1 NETMASK1= 255.255.255.240 ADDRESS1=10.64.34.10

123GATEWAY1=10.64.34.1 NETMASK1= 255.255.255.240 ADDRESS1=10.64.34.10

Save and close the file. Restart networking:
# service network restart

1# service network restart

There are various ways to verify the routing table in Linux. Few commands are listed below:
# route –n

1# route –n

# netstat –nr

1# netstat –nr

# ip route show

1# ip route show
1 Shares:
Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like
Read More

strace hint

To see the timestamp at which a system call executes and how much time spent on each system,…
Read More

Useful Netapp commands

Here are some useful Netapp Storage Administation commands. Some commands are for experience netapp administrators. For learning purpose…
Read More

Linux hugepages

Hugepages is a mechanism that allows the Linux kernel to utilize the multiple page size capabilities of modern…