Wednesday, July 16, 2014

Adding multiple route on Linux




Adding default route manually.
# route add default gw 192.168.20.20

# route add -host 192.168.20.20 gw 192.168.10.20
# route add default gw 192.168.10.20 eth0 # specify the interface if you have multiple.
# ip route add 192.168.20.0/24 dev eth0
# route add -net 192.168.20.0 netmask 255.255.255.0 gw 192.168.20.20 dev eth0

# service network restart

lxbl55% nexec lxapp23 cat etc/sysconfig/network-scripts/route-eth0
#default via 192.168.20.25 -- the original entry.
# Sample
GATEWAY0=Your gateway/router
NETMASK0=Your subnet Mask
ADDRESS0=Your network
#
# 172.16.0.0
GATEWAY0=192.168.20.25
NETMASK0=255.240.0.0
ADDRESS0=172.16.0.0
#
# 10.0.0.0
GATEWAY1=192.168.20.25
NETMASK1=255.0.0.0
ADDRESS1=10.0.0.0
#
# 192.168.0.0
GATEWAY2=192.168.20.25
NETMASK2=255.255.0.0
ADDRESS2=192.168.0.0
#
#192.168.20.0
GATEWAY3=0.0.0.0
NETMASK3=255.255.255.0
ADDRESS3=192.168.20.0
#
#192.168.16.0
GATEWAY4=192.168.20.20
NETMASK4=255.255.255.0
ADDRESS4=192.168.16.0
#
#0.0.0.0
GATEWAY5=192.168.20.20
NETMASK5=0.0.0.0
ADDRESS5=0.0.0.0
lxbl55%

lxbl55% nexec lxapp23 netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
192.168.16.0    192.168.20.20    255.255.255.0   UG        0 0          0 eth2
192.168.20.0     0.0.0.0         255.255.255.0   U         0 0          0 eth2
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth2
192.168.0.0     192.168.20.25    255.255.0.0     UG        0 0          0 eth2
172.16.0.0      192.168.20.25    255.240.0.0     UG        0 0          0 eth2
10.0.0.0        192.168.20.25    255.0.0.0       UG        0 0          0 eth2
0.0.0.0         192.168.20.20    0.0.0.0         UG        0 0          0 eth2

lxbl55% nexec lxapp23 cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
USERCTL=no
BOOTPROTO=static
NETMASK=255.255.255.0
IPADDR=192.168.20.30
PEERDNS=no
check_link_down() {
 return 1;
}

lxbl55% nexec lxapp23 cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=lxapp23
lxbl55%

Reboot the confirm the change and run netstat -rn

No comments:

Post a Comment