RHEL6-(11)-ROUTES
& DEFAULT GATEWAY -P3
Next is to have two default routes on system.
Till we have one default gateway configured in our system and all traffic
was routed with that.
Now the requirement is as follows,
192.168.234.0 – eth1 & eth2 – via 192.168.234.2
192.168.110.0 – eth0 & eth3 – via 192.168.110.1
Solution,
To accomplish this, we will need to setup the routing tables on each
additional interface excluding the interface managing the default gateway for
the system.
Linux has advanced routing capabilities made possible through
iproute2 tools. This allows us to specify more than one default gateways or
router addresses.
Take a look at our target file,
/etc/iproute2/rt_tables
[root@rhel6-server /]# cat /etc/iproute2/rt_tables
#
# reserved values
#
255 local
254 main
253 default
0 unspec
#
# local
#
#1 inr.ruhep
[root@rhel6-server ~]# cp /etc/iproute2/rt_tables
/etc/iproute2/rt_tables.org
[root@rhel6-server ~]# ip rule list
0: from all lookup local
32766: from all lookup main
32767: from all lookup default
[root@rhel6-server ~]# echo "1 eth1"
>>/etc/iproute2/rt_tables
[root@rhel6-server ~]# ip route add 192.168.234.0/24
dev eth1 src 192.168.234.146 table eth1
[root@rhel6-server ~]# ip route add default via
192.168.234.2 dev eth1 table eth1
[root@rhel6-server ~]# ip rule add from 192.168.234.146/24 table eth1
[root@rhel6-server ~]# ip rule add to 192.168.234.146/24 table eth1
[root@rhel6-server ~]# ip route flush cache
[root@rhel6-server ~]# ip rule list
0: from all lookup local
32764: from all to
192.168.234.146/24 lookup eth1
32765: from 192.168.234.146/24
lookup eth1
32766: from all lookup main
32767: from all lookup default
[root@rhel6-server ~]# echo "2 eth2"
>>/etc/iproute2/rt_tables
[root@rhel6-server ~]# ip route add 192.168.234.0/24
dev eth2 src 192.168.234.147 table eth2
[root@rhel6-server ~]# ip route add default via
192.168.234.2 dev eth2 table eth2
[root@rhel6-server ~]# ip rule add from 192.168.234.147/24 table eth2
[root@rhel6-server ~]# ip rule add to 192.168.234.147/24 table eth2
[root@rhel6-server ~]# ip route flush cache
[root@rhel6-server ~]# ip rule list
0: from all lookup local
32762: from all to
192.168.234.147/24 lookup eth2
32763: from 192.168.234.147/24
lookup eth2
32764: from all to
192.168.234.146/24 lookup eth1
32765: from 192.168.234.146/24
lookup eth1
32766: from all lookup main
32767: from all lookup default
[root@rhel6-server ~]#
[root@rhel6-server ~]# echo "3 eth3"
>>/etc/iproute2/rt_tables
[root@rhel6-server ~]# ip route add 192.168.110.0/24
dev eth3 src 192.168.110.135 table eth3
[root@rhel6-server ~]# ip route add default via
192.168.110.1 dev eth3 table eth3
[root@rhel6-server ~]# ip rule add from 192.168.110.135/24 table eth3
[root@rhel6-server ~]# ip rule add to 192.168.110.135/24 table eth3
[root@rhel6-server ~]# ip route flush cache
[root@rhel6-server ~]# ip rule list
0: from all lookup local
32760: from all to
192.168.110.135/24 lookup eth3
32761: from 192.168.110.135/24
lookup eth3
32762: from all to
192.168.234.147/24 lookup eth2
32763: from 192.168.234.147/24
lookup eth2
32764: from all to
192.168.234.146/24 lookup eth1
32765: from 192.168.234.146/24
lookup eth1
32766: from all lookup main
32767: from all lookup default
[root@rhel6-server ~]# ip route list table eth3
192.168.110.0/24 dev eth3
scope link src 192.168.110.135
default via 192.168.110.1 dev eth3
Policies are implemented and in action but it are not persistent.
Then what…??
[root@rhel6-server ~]# cp /etc/rc.d/rc.local /etc/rc.d/rc.local.org
Add all commands to,
[root@rhel6-server ~]# vi /etc/rc.d/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
echo "1 eth1" >>/etc/iproute2/rt_tables
ip route add 192.168.234.0/24 dev eth1 src 192.168.234.146 table eth1
ip route add default via 192.168.234.2 dev eth1 table eth1
ip rule add from 192.168.234.146/24 table eth1
ip rule add to 192.168.234.146/24 table eth1
echo "3 eth3" >>/etc/iproute2/rt_tables
ip route add 192.168.110.0/24 dev eth3 src 192.168.110.135 table eth3
ip route add default via 192.168.110.1 dev eth3 table eth3
ip rule add from 192.168.110.135/24 table eth3
ip rule add to 192.168.110.135/24 table eth3
echo "2 eth2" >>/etc/iproute2/rt_tables
ip route add 192.168.234.0/24 dev eth2 src 192.168.234.147 table eth2
ip route add default via 192.168.234.2 dev eth2 table eth2
ip rule add from 192.168.234.147/24 table eth2
ip rule add to 192.168.234.147/24 table eth2
References and very good read:
No comments:
Post a Comment