我有来自两个不同 ISP 的两个互联网连接,我需要平衡和故障转移两个 ISP 之间往返于我的网络的流量。
我的设置:
FIRST ISP (eth0): 152.152.104.226
SECOND ISP (eth1): 172.110.132.115
LOCAL NETWORK IP (eth2): 192.168.110.26
我的脚本:
#DELETE DEFAULT GW
ip route del default
#ADD ROUTE FOR PORT 0
ip route add 152.152.104.224/29 dev eth0 src 152.152.104.226 table tetra
ip route add default via 152.152.104.225 table tetra
#ADD ROUTE FOR PORT 1
ip route add 172.110.132.112/28 dev eth1 src 172.110.132.115 table vega
ip route add default via 172.110.132.113 table vega
#ADD RULES FOR WAN(s)
ip rule add from 152.152.104.226 table tetra
ip rule add from 172.110.132.115 table vega
#DIVIDE TRAFFIC GIVE 1 ISP MORE WEIGHT. USE weight 1 FOR BOTH INTERFACES TO DIVIDE EVENLY
ip route add default scope global nexthop via 152.152.104.225 dev eth0 weight 4 nexthop via 172.110.132.113 dev eth1 weight 1
并且它可以工作。但是当我重新启动网络(重启系统)或者当我对其中一个接口执行“ifconfig down”时,我的规则就会弹出。
我可以在哪里保存它的规则永久化?我需要网关的范围
ip route add default scope global nexthop via 152.152.104.225 dev eth0 weight 4 nexthop via 172.110.132.113 dev eth1 weight 1
重启网络或重启系统后即可工作。
答案1
我建议您不要使用命令,而是编辑:
/etc/sysconfig/network
/etc/sysconfig/network-scripts/ifcfg-[eth0,enp0s3]
确保一切ONBOOT="yes"
正常/etc/sysconfig/network-scripts/ifcfg-[eth0,enp0s3]
,您就可以出发了。