尝试配置 eth0 和 eth1 但无法启动 eth1

Tes*_*234 14 networking interface ethernet

尝试在 Ubuntu 12.04 上执行以下操作。

尝试配置 eth0 和 eth1,eth0 工作正常,但无法带 eth1。

以下是设置/etc/network/interfaces:

auto eth0 eth1

iface eth0 inet static
address 172.19.20.186
netmask 255.255.255.252
network 172.19.20.184
broadcast 172.19.20.187
gateway 172.19.20.185

iface eth1 inet static
address 172.18.182.55
netmask 255.255.254.0
gateway 172.18.182.1

up route add -net 172.19.26.0/23 gw 172.19.20.185 dev eth0
up route add -net 172.19.24.0/23  gw 172.19.20.185 dev eth0
up route add default  gw 172.18.182.1 dev eth1
Run Code Online (Sandbox Code Playgroud)

当/etc/init.d/networking restart完成后,得到下述错误:

$ /etc/init.d/networking restart
RTNETLINK answers: File exists
Failed to bring up eth1
Run Code Online (Sandbox Code Playgroud)

甚至ifdown eth1并ifup eth1给出上述错误。

任何人都可以帮助解决这个问题吗?

Eri*_*lho 15

我认为您只需要一个默认网关。您已设置 3: gateway 172.19.20.185,gateway 172.18.182.1和up route add default gw 172.18.182.1 dev eth1。

尝试以下接口文件:

auto eth0 eth1

iface eth0 inet static
  address 172.19.20.186
  netmask 255.255.255.252

iface eth1 inet static
  address 172.18.182.55
  netmask 255.255.254.0
  gateway 172.18.182.1
  up route add -net 172.19.26.0/23 gw 172.19.20.185 dev eth0
  up route add -net 172.19.24.0/23 gw 172.19.20.185 dev eth0
Run Code Online (Sandbox Code Playgroud)

编辑:试试这个手动配置接口,这样我们就可以看到错误在哪里。

  1. 关闭所有接口: ifconfig eth0 down; ifconfig eth1 down; ifconfig eth2 down; ifconfig eth3 down
  2. 配置 eth0: ifconfig eth0 172.19.20.186 netmask 255.255.255.252 up
  3. 配置 eth1: ifconfig eth1 172.18.182.55 netmask 255.255.254.0 up
  4. 设置默认网关: route add default gw 172.18.182.1
  5. 设置第一个静态路由: route add -net 172.19.26.0/23 gw 172.19.20.185 dev eth0
  6. 设置第二条静态路由: route add -net 172.19.24.0/23 gw 172.19.20.185 dev eth0


小智 7

有时在启动之前刷新界面有效:

ip addr flush dev enp2s0
Run Code Online (Sandbox Code Playgroud)