Using route command

Assume you want to route the traffic for network 192.168.5.0 
  through interface  eth1 serving  192.168.1.0 network

Verify current routing info :

[root@gract1 Desktop]# ifconfig eth1
eth1      Link encap:Ethernet  HWaddr 08:00:27:29:54:EF  
          inet addr:192.168.1.111  Bcast:192.168.1.255  Mask:255.255.255.0

[root@gract1 ~]#  netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.1.1     0.0.0.0         UG        0 0          0 eth1
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth2
192.168.1.0     0.0.0.0         255.255.255.0   U         0 0          0 eth1
192.168.2.0     0.0.0.0         255.255.255.0   U         0 0          0 eth2
192.168.3.0     0.0.0.0         255.255.255.0   U         0 0          0 eth3
[root@gract1 ~]# ping 192.168.5.50
PING 192.168.5.50 (192.168.5.50) 56(84) bytes of data.
From 192.168.1.111 icmp_seq=2 Destination Host Unreachable
From 192.168.1.111 icmp_seq=3 Destination Host Unreachable
From 192.168.1.111 icmp_seq=4 Destination Host Unreachable

Add routing info :
[root@gract1 ~]# ip route add 192.168.5.0/24 dev eth1
[root@gract1 ~]# netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.1.1     0.0.0.0         UG        0 0          0 eth1
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth2
192.168.1.0     0.0.0.0         255.255.255.0   U         0 0          0 eth1
192.168.2.0     0.0.0.0         255.255.255.0   U         0 0          0 eth2
192.168.3.0     0.0.0.0         255.255.255.0   U         0 0          0 eth3
192.168.5.0     0.0.0.0         255.255.255.0   U         0 0          0 eth1

Verify that ping and nslookup are working 
[root@gract1 ~]# ping  192.168.5.50
PING 192.168.5.50 (192.168.5.50) 56(84) bytes of data.
64 bytes from 192.168.5.50: icmp_seq=1 ttl=64 time=0.929 ms
64 bytes from 192.168.5.50: icmp_seq=2 ttl=64 time=0.264 ms
--- 192.168.5.50 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1004ms
rtt min/avg/max/mdev = 0.264/0.596/0.929/0.333 ms

[root@gract1 ~]# nslookup ns1
Server:        192.168.1.50
Address:    192.168.1.50#53
Name:    ns1.example.com
Address: 192.168.5.50

To delete the above created route run :
[root@gract1 ~]#  ip route del 192.168.5.0/24 dev eth1

Leave a Reply

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