服务器配置多网卡多网关时,为了避免是不是的去添加相关回程路由,因此需要配置一下策略路由
服务器系统版本:CentOS Linux release 7.3.1611
1.
vi /etc/iproute2/rt_tables 后面加上
101 innerRoute
102 globalRoute
2.添加路由配置脚本(脚本执行已验证可用)
ip route flush table globalRoute
ip rule add dev eth1 table globalRoute
if ! ip rule show | grep x.x.x.x ; then
ip rule add from x.x.x.x table globalRoute
fi
ip route add default via y.y.y.y dev eth1 table globalRoute
ip route flush table innerRoute
ip rule add dev eth2 table innerRoute
if ! ip rule show | grep 172.16.x.x ; then
ip rule add from 172.16.x.x table innerRoute
fi
ip route add default via 172.16.y.y dev eth2 table innerRoute
上面x.x.x.x是配置在网口eth1上的ip,y.y.y.y是该ip的网关,172.16.x.x是eth2的ip,我这里是内网ip,172.16.y.y是172网关的网关。
3.赋予脚本可执行权限并开机启动(这一步未验证,服务器运行中不好开机测试)
1、(/opt/script/autostart.sh是你的脚本路径)
chmod +x /opt/script/autostart.sh
2、打开/etc/rc.d/rc.local文件,在末尾增加如下内容
/opt/script/autostart.sh
3、在centos7中,/etc/rc.d/rc.local的权限被降低了,所以需要执行如下命令赋予其可执行权限
chmod +x /etc/rc.d/rc.local
注释:centos 7.5系统配置命令都是需要id(101,102) 不再是名字
本文介绍在CentOS 7系统下,如何为服务器配置多网卡及多网关策略路由,避免频繁添加回程路由,通过设置策略路由表、编写并执行配置脚本来实现网络流量的智能调度。
4127

被折叠的 条评论
为什么被折叠?



