linux route

当服务器有两张网卡时,需要添加路由指定流量进出口优先级

1.先设置路由优先级

vi /etc/iproute2/rt_tables

255     local
254     main
253     default
0       unspec
251     SZ
252     HK

2.添加路由

vi /etc/rc.local
ip route flush table SZ(SZ代表网卡别名)
ip route add default via 192.168.1.1 dev eth0 src 192.168.1.100 table SZ
ip rule add from 192.168.1.100 table SZ

ip route flush table hk(hk代表网卡别名)
ip route add default via 192.168.2.1 dev eth1 src 192.168.2.100 table hk
ip rule add from 192.168.2.100 table hk

3.最后执行

/etc/rc.local

4.注意centos7要对rc.local添加执行权限

原文地址:https://www.cnblogs.com/yunweiweb/p/11248288.html