在上一篇博文中,用到了添加路由的方法让不一样的网络互通,但这种方法会形成部分旧网络环境不能访问宿主主机的状况。html
如今咱们在宿主主机上作策略路由,让不一样网络环境过来的访问按原线路回去linux
宿主主机上:bash
旧网络环境业务网段:br2服务器
10.1.7.206网络
gw:10.1.4.3ide
新网络环境业务网段:br0测试
10.100.241.206spa
gw:10.100.241.254.net
路由表rest
route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.200.241.0 0.0.0.0 255.255.255.0 U 0 0 0 br1
10.100.241.0 0.0.0.0 255.255.255.0 U 0 0 0 br0
10.1.4.0 0.0.0.0 255.255.252.0 U 0 0 0 br2
20.1.4.0 0.0.0.0 255.255.252.0 U 0 0 0 br3
127.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 lo
0.0.0.0 10.100.241.254 0.0.0.0 UG 0 0 0 br0
能够看到,只设置了
添加路由表(参考资料:http://linux-ip.net/html/routing-tables.html)
vi /ect/iproute2/rt_tables
#
# reserved values
#
255 local
254 main
253 default
0 unspec
#
# local
#
#1 inr.ruhep
100 f3
101 f5
添加开机启动脚本
vi /etc/rc.d/after.local
#!/bin/bash
#配置原线路返回路由
ip route flush table f5
ip route add default via 10.100.241.254 dev br0 src 10.100.241.206 table f5
ip rule add from 10.100.241.206 table f5
ip route flush table f3
ip route add default via 10.1.4.3 dev br2 src 10.1.7.206 table f3
ip rule add from 10.1.7.206 table f3
#end
加载脚本
#source /etc/rc.d/after.local
把脚本加在network 重启脚本里
# vi /sbin/rcnetwork
restart|force-reload)
$0 stop $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
$0 start $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
rc_status
. /etc/rc.d/after.local
rc_exit
重启网络服务
测试:
ping 10.1.7.206
ping 10.100.241.206
两个均可以ping 通,完成
但这里有个问题,就是宿主主机主动去访问旧网络主机时,走的倒是***
# traceroute 10.1.3.250
traceroute to 10.1.3.250 (10.1.3.250), 30 hops max, 40 byte packets using UDP
1 10.100.241.251 (10.100.241.251) 33.245 ms 32.513 ms 30.033 ms
2 10.100.240.1 (10.100.240.1) 0.513 ms 0.329 ms 0.291 ms
3 * * *
4 10.1.3.250 (10.1.3.250) 9.120 ms 5.150 ms 2.387 ms
并无像上一篇添加路由同样直接走相应网卡出去,看来这种设置适合双线提供服务的服务器