centos7 双ip双网关设置策略路由

centos7 双ip双网关

双网卡设完ip 不设网关

vi /etc/iproute2/rt_tables   加上
 
251     net0
252     net30

数值越小优先级越高


vim route.sh 内容如下:


ip route flush table net0
ip route add default via 192.168.0.1 dev em1 src 192.168.0.16 table net0
ip rule add from 192.168.0.16 table net0

ip route flush table net30
ip route add default via 192.168.30.254 dev em2 src 192.168.30.216 table net30
ip rule add from 192.168.30.216 table net30

route add default gw 192.168.0.1

cd /etc/NetworkManager/dispatcher.d/ 
cp route.sh /etc/NetworkManager/dispatcher.d/
chmod +x route.sh

(之前在Centos 6的时代可以直接把命令写入到rc.local然后开机自动执行一遍 但是因为在Centos 7中切换到NetworkManager 已经失
效 不过解决方法也很简单啦 只需要把写好的route.sh脚本放到 

/etc/NetworkManager/dispatcher.d/ 

中chmod +x route.sh就可以在开机自动执行了) 
要是一条条执行语句  重启后失效
 

猜你喜欢

转载自my.oschina.net/u/3367404/blog/1536768