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

centos7 双ip双网关vim

双网卡设完ip 不设网关centos

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

数值越小优先级越高spa


vim route.sh 内容以下:ip


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 net0table

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 net30route

route add default gw 192.168.0.1方法

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

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

/etc/NetworkManager/dispatcher.d/ 

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

相关文章
相关标签/搜索