/增加路由表:指定从192.168.100.241来的数据包访问目标网络为:00网段时,用table100路由表
ip route add 192.168.100.0 dev em2 src 192.168.100.241 table 100
ip route add 192.168.100.0 dev em3 src 192.168.100.242 table 200
ip route add 192.168.100.0 dev p1p2 src 192.168.100.243 table 300
ip route add 192.168.100.0 dev p1p3 src 192.168.100.244 table 400
//
增加路由:指定到100网段的路由从em2网卡出去,使用table 100路由表
ip route add 192.168.100.0/24 dev em2 table 100
ip route add 192.168.100.0/24 dev em3 table 200
ip route add 192.168.100.0/24 dev p1p2 table 300
ip route add 192.168.100.0/24 dev p1p3 table 400
//增加流量规则:来自192.168.100.241的流量使用table100路由表
ip rule add from 192.168.100.241 table 100
ip rule add from 192.168.100.242 table 200
ip rule add from 192.168.100.243 table 300
ip rule add from 192.168.100.244 table 400
还有一种解决思路,特别麻烦,还要配网关等,可以放弃,仅做记录:
ip route add 192.168.100.21 equalize nexthop via 192.168.101.1 dev em3 weight 1 nexthop via 192.168.102.1 dev p1p2 weight 1 nexthop via 192.168.103.1 dev p1p3 weight 1 nexthop via 192.168.104.1 dev em2 weight 1
一般用这样的脚本就行:
ip route add 192.168.100.0 dev eth2 src 192.168.100.160 table 100
ip route add 192.168.100.0 dev eth3 src 192.168.100.161 table 105
ip route add 192.168.100.0 dev eth4 src 192.168.100.162 table 110
ip route add 192.168.100.0/24 dev eth2 table 100
ip route add 192.168.100.0/24 dev eth3 table 105
ip route add 192.168.100.0/24 dev eth4 table 110
ip rule add from 192.168.100.160 table 100
ip rule add from 192.168.100.161 table 105
ip rule add from 192.168.100.162 table 110