Wednesday, February 8, 2017

Configuring 2 Gateways on the same Linux Box permanently

Suppose you have 2 network on a PC says
192.168.1.5/24 (eth0 - Private Network)
172.16.10.4/24 (eth1 - Public Network)

Let's assume the 172.16.10.254 is the Default Gateway for 172.16.10.0 network. If there is a router at 192.168.1.254 for the internal network and you wish to connect to other networks says 192.168.5.0 192.168.6.0 and 192.168.7.0 networks. You will need to add "static routes" to these networks

route add -net 192.168.5.0 netmask 255.255.255.0 gw 192.168.1.254
route add -net 192.168.6.0 netmask 255.255.255.0 gw 192.168.1.254
route add -net 192.168.7.0 netmask 255.255.255.0 gw 192.168.1.254


To make the setting permanent, edit /etc/sysconfig/network-scripts/route-eth0
192.168.5.0/24 via 192.168.1.154 dev eth0 
192.168.6.0/24 via 192.168.1.154 dev eth0 
192.168.7.0/24 via 192.168.1.154 dev eth0 

To check the setting is ok
# ip route show

No comments: