一.問題追溯
國內公司的單點登錄服務器需要通過VPN鏈路和新加坡財務服務器做對接,但是網絡不通。經過網絡設備內部排查,確定是本台服務器設備路由問題。
二.問題檢查及思考
[root@localhost ~]# ifconfig //通命令查看本台服務器的IP地址
docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
inet6 fe80::42:e0ff:fe8d:6180 prefixlen 64 scopeid 0x20<link>
ether 02:42:e0:8d:61:80 txqueuelen 0 (Ethernet)
RX packets 5371877 bytes 15977882070 (14.8 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 5921077 bytes 640912453 (611.2 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.19.5.5 netmask 255.255.255.0 broadcast 172.19.5.255
inet6 fe80::d8d2:cb16:11a8:879d prefixlen 64 scopeid 0x20<link>
ether fa:16:3e:d1:b2:d0 txqueuelen 1000 (Ethernet)
RX packets 24581668 bytes 13724588280 (12.7 GiB)
RX errors 0 dropped 9 overruns 0 frame 0
TX packets 9598006 bytes 16637924695 (15.4 GiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
docker這個接口讓人格外的注意,因為這個接口地址是172.17.0.1,而需要對接的地址是172.17.8.220,172.17.0.1的掩碼地址為16位,明顯包含了新加坡服務器的地址。然后繼續查看服務器的路由信息。
[root@localhost ~]# route
1.通過查看,很明顯的可以看出172.17路由出現了路由黑洞。原因是在默認情況下,靜態路由優先於默認路由。
2.解決這個問題,可以有很多方法,例如刪除docker的接口,或者關閉接口,或者把docker的地址改成其他私網地址。但是這些方法都比較麻煩,有可能影響用戶的使用,並且docker已經在使用了。
我認為比較簡單的就是加一條明細的靜態路由,這個方法更加快捷,方便,安全。
接下來就是添加路由的方法:
三.解決方法,增加靜態路由,並且永久添加,防止服務器重啟或者重置網絡之后路由丟失。
1. 首先增加臨時路由,保障用戶正常使用,使用route命令添加。
[root@localhost ~]# route
-bash: route: command not found
該情況表示沒有安裝該命令,需要先安裝net-tools , sudo yum install net-tools -y
[root@localhost ~]# route add -net 172.17.8.0/24 gw 172.19.5.1
增加一條172.17.8.0/24的路由,網關是172.19.5.1,也就是eth0接口所指向的網關
[root@localhost ~]# route
使用route命令查看
如果不需要該路由,同樣可以刪除。
[root@localhost ~]# route del -net 172.17.0.0/24 gw 172.19.5.1
2. 添加永久路由
在/etc/sysconfig/network-scripts/ 增加加一下文件,命名規則為 route-網卡名
例route-eth0
[root@localhost ~]# vim /etc/sysconfig/network-scripts/route-eth0
##static-route
172.17.8.0/24 via 172.19.5.1 dev eth0