CentOS7 - Multiple gateway & multiple routing table
NIC1 (enp192) 192.168.98.238/24 --> This is the main network already with default gateway
NIC2 (enp224) 192.168.97.238/24 --> This is the second network (vlan public) I wanna add default gateway (97.254)
Step 1 - Create a custom routing table for NIC2
vi /etc/iproute2/rt_tables
"1 vl_public"
Please process one of persistent setting method as below :
## Option 1 - "rc.local" persistent setting method :
Step 2 - Create the iproute2 default gateway & route script file for NIC2
vi /root/multigateway-ruleadd-routeadd.sh
/sbin/ip rule add from 192.168.97.0/24 table vl_public
/sbin/ip rule add to 192.168.97.0/24 table vl_public
/sbin/ip route add default via 192.168.97.254 table vl_public
Step 3 - Save the script file, change mode as executable then add in "rc.local" :
chmod +x /root/multigateway-ruleadd-routeadd.sh
chmod +x /etc/rc.d/rc.local
vi /etc/rc.local
/root/multigateway-ruleadd-routeadd.sh
Step 4 - Reboot the server and validate the iproute2 rules and routing for new default gateway NIC2
# ip rule show
0: from all lookup local
32764: from all to 192.168.97.0/24 lookup vl_public <-- THIS
32765: from 192.168.97.0/24 lookup vl_public <-- THIS
32766: from all lookup main
32767: from all lookup default
## Option 2 - "ifup-route & ifup-rule" persistent method :
Step 2 - Create the iproute2 default gateway file for NIC2
vi /etc/sysconfig/network-scripts/route-ens224
default via 192.168.97.254 table vl_public
Step 3 - Create the iproute2 rules file for NIC2
vi /etc/sysconfig/network-scripts/rule-ens224
from 192.168.97.0/24 table vl_public
Step 4 - Reboot the server and validate the iproute2 rules and routing for new default gateway NIC2
# ip rule show
0: from all lookup local
32765: from 192.168.97.0/24 lookup vl_public <--- THIS
32766: from all lookup main
32767: from all lookup default
Server is hosted by Alanstudio
Linux Operating System
Recommend screen resolution 1024 x 768 / IE / FireFox
Alan Studio © 2007 by Alan Cheung Hin Lun. All rights reserved.
|