多个网卡的路由,有时会出现错误的路由顺序

多个网卡的路由,有时会出现错误的路由顺序

我全新安装了 ubuntu server 17.04,有 3 个网卡,它提供许多服务,如(SAMBA、postgres、LAMPP、openvpn 等),有时候一切正常,有时候则不行,因为某种原因,我不知道在启动时交换路由表最后两行的顺序。

*Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         gateway         0.X.X.0         UG    0      0        0 enp0s31f6
10.X.X.0        10.X.X.2        255.X.X.0   UG    0      0        0 tun0
10.X.X.2        0.0.0.0         255.X.X.255 UH    0      0        0 tun0
10.X.X.0    172.X.X.5    255.X.X.252 UG    0      0        0 enp2s0
172.X.X.4    0.X.X.0         255.X.X.252 U     0      0        0 enp2s0
localnet        0.X.X.0         255.X.X.0   U     0      0        0 enp0s31f6
localnet        0.X.X.0         255.X.X.0   U     0      0        0 enp6s0*

错误的!!!

其他时候

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.X.X.0         192.X.X.254   0.X.X.0         UG    0      0        0 enp0s31f6
10.X.X.0        10.X.X.2        255.X.X.0   UG    0      0        0 tun0
10.X.X.2        0.X.X.0         255.X.X.255 UH    0      0        0 tun0
172.X.X.4    0.X.X.0         255.X.X.252 U     0      0        0 enp2s0
192.X.X.0     0.X.X.0         255.X.X.0   U     0      0        0 enp6s0
192.X.X.0     0.X.X.0         255.X.X.0   U     0      0        0 enp0s31f6

所有服务均运行良好。

我的界面

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto enp0s31f6
iface enp0s31f6 inet static
    address 192.X.X.245
    netmask 255.X.X.0
    network 192.X.X.0
    broadcast 192.X.X.255
    gateway 192.X.X.254
    # dns-* options are implemented by the resolvconf package, if installed
    dns-nameservers 186.X.X.X 186.X.X.X

# LAN
auto enp0s6
iface enpXXX inet static
    address 192.X.X.2
    netmask 255.X.X.0
    network 192.X.X.0
    broadcast 192.X.X.255

# VPN
auto enp2s0
iface enp2s0 inet static
    address 172.X.X.6
netmask 255.X.X.252
network 127.X.X.4
broadcast 172.X.X.7
up route add -net 10.X.X.0/30 gw 172.X.X.5 dev enp2s0

有人知道这个问题或解决方案吗?

答案1

我发现的解决方案是在 enp0s31f6 定义之后从接口文件中的动态路由中删除 de 网络“post-up route del -net 192.168.1.0/24 gw 0.0.0.0 dev enp0s31f6”

不是优雅的解决方案,但是......

不管怎么说,还是要谢谢你!!

相关内容