当前位置: 代码迷 >> 综合 >> Ubuntu下多网卡配置RTNETLINK answers: File exists的解决方案
  详细解决方案

Ubuntu下多网卡配置RTNETLINK answers: File exists的解决方案

热度:17   发布时间:2024-02-02 15:11:57.0

Ubuntu下多网卡配置RTNETLINK answers: File exists的解决方案

  • 现象
  • 原因分析
  • 解决办法

现象

在Ubuntu 16.04内核的开发板系统上配置多个网卡,开发板上有3个网口,配置如下

auto lo
iface lo inet loopbackauto eth0
iface eth0 inet static
address 192.168.1.18
netmask 255.255.255.0
gateway 192.168.1.1auto eth1
iface eth1 inet static
address 192.168.1.231
netmask 255.255.255.0
gateway 192.168.1.1auto eth2
iface eth2 inet static
address 192.168.1.10
netmask 255.255.255.0
gateway 192.168.1.1

启动时出现

[FAILED] Failed to start Raise network interfaces.
See 'systemctl status networking.service' for details.

然后查看,systemctl status networking.service,有错误如下:

 networking.service - Raise network interfacesLoaded: loaded (/lib/systemd/system/networking.service; enabled; vendor preset: enabled)Drop-In: /run/systemd/generator/networking.service.d└─50-insserv.conf-$network.confActive: failed (Result: exit-code) since Fri 2016-02-12 00:28:03 CST; 26min agoDocs: man:interfaces(5)Process: 620 ExecStart=/sbin/ifup -a --read-environment (code=exited, status=1/FAILURE)Process: 461 ExecStartPre=/bin/sh -c [ "$CONFIGURE_INTERFACES" != "no" ] && [ -n "$(ifquery --read-environment --list --exMain PID: 620 (code=exited, status=1/FAILURE)Feb 12 00:28:01 NanoPi-NEO-Plus2 systemd[1]: Starting Raise network interfaces...
Feb 12 00:28:03 NanoPi-NEO-Plus2 ifup[620]: /sbin/ifup: waiting for lock on /run/network/ifstate.eth1
Feb 12 00:28:03 NanoPi-NEO-Plus2 ifup[620]: RTNETLINK answers: File exists
Feb 12 00:28:03 NanoPi-NEO-Plus2 ifup[620]: Failed to bring up eth1.
Feb 12 00:28:03 NanoPi-NEO-Plus2 ifup[620]: RTNETLINK answers: File exists
Feb 12 00:28:03 NanoPi-NEO-Plus2 ifup[620]: Failed to bring up eth2.
Feb 12 00:28:03 NanoPi-NEO-Plus2 systemd[1]: networking.service: Main process exited, code=exited, status=1/FAILURE
Feb 12 00:28:03 NanoPi-NEO-Plus2 systemd[1]: Failed to start Raise network interfaces.
Feb 12 00:28:03 NanoPi-NEO-Plus2 systemd[1]: networking.service: Unit entered failed state.
Feb 12 00:28:03 NanoPi-NEO-Plus2 systemd[1]: networking.service: Failed with result 'exit-code'.

原因分析

因为之前一直只使用一个网卡,只配置了一个,现在想试试使用多个,就增加了两个配置,所以应该是新增的配置导致的。
查了一些资料,在网络配置中给多块网卡都配置了网关,去网上搜了一下,发现不能同时设置多个网关会导致路由表中出现多个默认路由,如果你有两个默认路由,在路由表中就会有两个0.0.0.0条目,系统不能处理这种情况,就会出现上面的错误。

解决办法

在/etc/network/interface 中配置多张网卡的信息,只有连接外网的网卡需要配置网关以及nameserver,然后重启网络,ifup eth1或者重启电脑即可看到多张网卡的信息。
我这里因为

  相关解决方案