一次只能调出一个界面

我看了一个最相关的问题 ,并且更进了一步,但不知道该从哪里出发。

我目前正试图连接两个以太网接口,但同时无法build立到两个接口的连接。 当我连接第二个接口enx000acd2f045e我的连接通过enp0s31f6到Internet被断开连接。 而不像引用的答案,当我运行sudo lshw -c network时,我的networking都没有被禁用。

 $ sudo lshw -c network [sudo] password for maxgitt: *-network description: Ethernet interface product: Ethernet Connection (5) I219-LM vendor: Intel Corporation physical id: 1f.6 bus info: pci@0000:00:1f.6 logical name: enp0s31f6 version: 00 serial: 50:9a:4c:18:ad:9f size: 1Gbit/s capacity: 1Gbit/s width: 32 bits clock: 33MHz capabilities: pm msi bus_master cap_list ethernet physical tp 10bt 10bt-fd 100bt 100bt-fd 1000bt-fd autonegotiation configuration: autonegotiation=on broadcast=yes driver=e1000e driverversion=3.2.6-k duplex=full firmware=0.1-4 ip=130.207.34.53 latency=0 link=yes multicast=yes port=twisted pair speed=1Gbit/s resources: irq:138 memory:f7100000-f711ffff *-network description: Ethernet interface physical id: 1 bus info: usb@2:3.1 logical name: enx000acd2f045e serial: 00:0a:cd:2f:04:5e size: 1Gbit/s capacity: 1Gbit/s capabilities: ethernet physical tp mii 10bt 10bt-fd 100bt 100bt-fd 1000bt 1000bt-fd autonegotiation configuration: autonegotiation=on broadcast=yes driver=ax88179_178a duplex=full ip=192.168.3.4 link=yes multicast=yes port=MII speed=1Gbit/s 

答案确实提到检查我的路由表,说明我不能有多个网关。 所以我跑了以下几点:

连接到enx000之前

  $ route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 130.207.34.1 0.0.0.0 UG 100 0 0 enp0s31f6 130.207.34.0 0.0.0.0 255.255.255.0 U 100 0 0 enp0s31f6 143.215.251.5 130.207.34.1 255.255.255.255 UGH 100 0 0 enp0s31f6 169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 enp0s31f6 

连接到enx000

 $ route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.3.3 0.0.0.0 UG 0 0 0 enx000acd2f045e 0.0.0.0 130.207.34.1 0.0.0.0 UG 100 0 0 enp0s31f6 130.207.34.0 0.0.0.0 255.255.255.0 U 100 0 0 enp0s31f6 143.215.251.5 130.207.34.1 255.255.255.255 UGH 100 0 0 enp0s31f6 169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 enp0s31f6 192.168.3.0 0.0.0.0 255.255.255.0 U 0 0 0 enx000acd2f045e 

最后,他说:“如果你有两个网关,那么你的路由表将会有一个dest 0.0.0.0的双重入口,系统不能处理这个。” 我对networking比较陌生,不确定我能做些什么来解决这个问题。 看起来我可能在我的路由表的前两行有冲突。

  • 我应该更新:
    • 在Ubuntu的“networking”菜单中find的默认网关
    • 编辑/etc/network/interfaces ,这在Ubuntu的最新版本中似乎并没有被使用,更不用说16.04了

你引用的答案已经指出了这个问题 – 它在路由表中。 发生什么事情是你创build了两个“默认路由”(0.0.0.0路由)。 这是匹配的路由,如果没有其他的被发现,因此默认名称。

在你的情况下,一旦第二个接口启动,你可以看到两个默认路由,系统使用第一个匹配的,因此是enxXXX适配器。

说你不能拥有两条默认路由是很简单的,因为一切都是可能的,你可以在两者之间实现stream量平衡,但是出于你的目的,你似乎只是想为你的Internetstream量使用原始的enpXXX接口? 只有通过其他接口的LANstream量?

这很容易实现 – 您需要禁用enxXXX适配器作为默认路由(这将添加一条路由到局域网但不是全球0.0.0.0),或者设置路由顺序,以便enpXXX接口在路由表中位于第一位。

这里有一个很好的描述如何在Ubuntu上使用多个NIC: https : //askubuntu.com/questions/310355/networking-with-multiple-nics

感谢您的参考。 它帮助我解决了这个问题。 我必须在以前的默认网关中添加我的路由表。 您可以检查并确保在运行ip route show您只有1个默认网关:

之前

 $ ip route show default via 192.168.3.3 dev enx000acd2f045e proto static default via 130.207.34.1 dev enp0s31f6 proto static metric 100 

我所要做的只是通过以下方式删除第二条路线:

 sudo route del default gw 192.168.3.3 enx000acd2f045e 

 $ ip route show default via 130.207.34.1 dev enp0s31f6 proto static metric 100