ip route add 192.168.6.0/24 dev br0 table 10 ip route add default via 192.168.6.1 table 10 ip route add 192.168.9.0/24 dev br1 table 12 ip route add default via 192.168.9.1 table 12 ip rule add from 192.168.6.0/24 table 10 priority 1 ip rule add from 192.168.9.0/24 table 12 priority 2 # 添加 docker 网络 ip route add 172.17.0.0/16 dev docker0 table 10 ip route add 172.17.0.0/16 dev docker0 table 12 # 刷新配置 ip route flush cache # 校验 $ ip route show table 12 default via 192.168.9.1 dev br1 172.17.0.0/16 dev docker0 scope link 192.168.9.0/24 dev br1 scope link
示例
1 2 3 4 5 6 7 8 9 10 11 12 13
# out ip route add default via 192.168.6.1 dev ens8 table 10 ip route add default via 192.168.9.1 dev ens9 table 12 # in ip rule add from 192.168.6.0/24 table 10 priority 1 ip rule add from 192.168.9.0/24 table 12 priority 2 # 可以不设置 priority # 如果有设置了默认的路由,可以忽略其中的一个,比如有如下默认路由 ip route add default via 192.168.6.1 dev ens8 # 那么只需要设置 192.168.9.0/24 # ip route add default via 192.168.9.1 dev ens9 table 12 ip route add 192.168.9.0/24 dev ens9 proto kernel scope link src 192.168.9.8 ip rule add from 192.168.9.0/24 table 12
$ lshw -c network WARNING: you should run this program as super-user. *-network ... logical name: enp0s31f6 ... *-network DISABLED ... logical name: enxf8e43b1a1229 ...