Understand, Learn and Implement.. LINUX / UNIX DEVOPS CONTAINERS OPENSHIFT KUBERNETES DEVOPS TOOLS VIRTUALIZATION STORAGE BACKUP SCRIPTS MONITORING MIDDLEWARE

Tuesday, August 26, 2014

Static Route Configuration Linux

Static routes are for traffic that must not, or should not, go through the default gateway. Routing is usually handled by routing devices and therefore it is often not necessary to configure static routes on Red Hat Enterprise Linux servers or clients. Exceptions include traffic that must pass through an encrypted VPN tunnel or traffic that should take a less costly route. The default gateway is for any and all traffic which is not destined for the local network and for which no preferred route is specified in the routing table. The default gateway is traditionally a dedicated network router.
Suppose if you want that all the traffic to network 172.168.102.0/24 should use 172.168.101.1 as gateway. This can be done by adding a static route in the kernel routing table as shown below.

ADDING STATIC ROUTE IN LINUX FROM THE COMMAND LINE :


# route add -net 172.168.102.0 netmask 255.255.255.0 gw 172.168.101.1 dev eth0

OR

# ip route add 172.168.102.0/24 via 172.168.101.1 dev eth0

OR 

Add Route
# sudo route add -net 192.168.2.0 gw 192.168.1.1 netmask 255.255.255.0 dev eth0

Delete Route
# sudo route del -net 192.168.2.0 gw 192.168.1.1 netmask 255.255.255.0 dev eth0

Above Commands will make changes to the routing table temporary and not permanent. Use any of below mention command To check Routing tables in Linux :

# route -n
# netstat -nr

Steps to make the static Route Persistent Across the reboot :

In case of RHEL5.X / CentOS 5.X
Create a file  route file

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

172.168.102.0/24 via 172.168.101.1 dev eth0

Save and close the file and  Restart network service

# service network restart

In case of RHEL6.X / CentOS 6.X

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

GATEWAY0= 172.168.101.1
NETMASK0=255.255.255.0
ADDRESS0= 172.168.102.0

Save and close the file and  Restart network service

# service network restart

0 comments:

Post a Comment