[CentOS] Static routing on CentOS

Wed Feb 26 14:00:24 UTC 2014
Ljubomir Ljubojevic <centos at plnet.rs>

On 02/26/2014 07:28 AM, Jatin Davey wrote:
> Hi All
>
> I have two hosts. Host A and Host B
>
> Host A routing table
> ------------------------
> [root at localhost ~]# route -n
> Kernel IP routing table
> Destination     Gateway         Genmask         Flags Metric Ref    Use
> Iface
> 172.29.110.0    172.29.109.1    255.255.255.0   UG    0 0        0 eth0
> 172.29.109.0    0.0.0.0         255.255.255.0   U     0 0        0 eth0
> 169.254.0.0     0.0.0.0         255.255.0.0     U     0 0        0 eth0
> 0.0.0.0         172.29.109.1    0.0.0.0         UG    0 0        0 eth0
>
> HOST A IP address : 172.29.109.254
>
>
>
> Host B routing table
> -------------------------
> [jatin at localhost ~]$ route -n
> Kernel IP routing table
> Destination     Gateway         Genmask         Flags Metric Ref    Use
> Iface
> 172.29.110.0    0.0.0.0         255.255.255.0   U     1 0        0 eth0
> 20.20.20.0      0.0.0.0         255.255.255.0   U     0 0        0 eth0
> 169.254.0.0     0.0.0.0         255.255.0.0     U     1002 0        0 eth0
> 0.0.0.0         172.29.110.1    0.0.0.0         UG    0 0        0 eth0
>
> HOST B Ip address : 172.29.110.93
>
>
> Host B basically houses some simulated devices which are configured in
> the ip address range of 20.20.20.1 to 20.20.20.254. The netmask being
> used here is 255.255.255.0
>
> I want to configure a static route on HOST A so that they can reach the
> simulated devices running on HOST B which are in the ip address range
> 20.20.20.1-20.20.20.254 , I am trying the following command but it does
> not configure the static route for me.
>
> [root at localhost ~]# route add -net 20.20.20.0 netmask 255.255.255.0 gw
> 172.29.110.93
> SIOCADDRT: Network is unreachable
>

On B first add route to A's subnet:
route add -net 172.29.109.0 netmask 255.255.255.0 gw 172.29.110.1

Also, 172.29.109.1 and 172.29.110.1 must know how to find each other. 
Use ping and traceroute to test availability for every subnet between you.

And see if they can ping each other. Once ping works, your route should 
have looked like this:

route add -net 20.20.20.0 netmask 255.255.255.0 gw 172.29.109.1 (always 
the first gateway on your way to some IP/subnet!)

BUT considering 172.29.109.1 is ALREADY your DEFAULT gateway, there is 
no need to added above route, but fix the other side, that HOST B can 
see/ping HOST A.

Consider routing as sending package by mail. You do write destination 
address on the package, but you do not carry it yourself. You take it to 
closest Post office, clerk looks at the address, finds closest post 
office/depot in that direction and sends it on it's way THERE, so 
another clerk (router) there looks for closest post office/depo in the 
direction of the destination address. BUT, no post clerk/ router only 
needs to know NEXT office/depot to sent it to.

Important to take care of is that same applies to returning packet, 
routers need to know where the to return the package, NEXT router at the 
time.

-- 
Ljubomir Ljubojevic
(Love is in the Air)
PL Computers
Serbia, Europe

StarOS, Mikrotik and CentOS/RHEL/Linux consultant