出现第二个虚拟网络接口的问题

nwa*_*lke 2 networking interface ubuntu-12.04

我在向一个接口添加第二个 IP 地址时遇到问题。下面是我的/etc/networking/interfaces

   # The loopback network interface
auto lo
iface lo inet loopback

#eth0 is our main IP address
auto eth0
iface eth0 inet static
 address 198.58.103.*
 netmask 255.255.255.0
 gateway 198.58.103.1

#eth0:0 is our private address
auto eth0:0
iface eth0:0 inet static
 address 192.168.129.134
 netmask 255.255.128.0

#eth0:1 is for www.site.com
auto eth0:1
iface eth0:1 inet static
 address 198.58.104.*
 netmask 255.255.255.0
 gateway 198.58.104.1
Run Code Online (Sandbox Code Playgroud)

当我运行时/etc/init.d/networking restart,我收到一个关于启动失败的错误eth0:1

RTNETLINK answers: File exists
Failed to bring up eth0:1.
Run Code Online (Sandbox Code Playgroud)

有什么原因吗?我第一次设置eth0eth0:0.

hoo*_*enz 5

编辑:

问题是您定义了 2 个默认网关。您需要删除其中之一。我认为 eth0:1 设备上的那个。

通过尝试再次添加已经到位的默认路由,将引发文件存在错误。


首先,我假设 * 作为主机号是一个有效数字,而不是字面上的“*”?

现在试试这个方法。我怀疑启动脚本中自动行的解析有问题 - 只是一种预感,我没有看过。

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
#eth0 is our main IP address
auto eth0
iface eth0 inet static
 address 198.58.103.*
 netmask 255.255.255.0
 gateway 198.58.103.1
 # Put your nameserver address here!
 dns-nameservers x.x.x.x 

#eth0:0 is our private address
auto eth0:0
iface eth0:0 inet static
 address 192.168.129.134
 netmask 255.255.128.0

#eth0:1 is for www.site.com
auto eth0:1
iface eth0:1 inet static
 address 198.58.104.*
 netmask 255.255.255.0
 # This shouldn't be here!  remove it.
 #gateway 198.58.104.1
Run Code Online (Sandbox Code Playgroud)

其次,要摆脱烦人的 resolv.conf 错误,请运行:

sudo dpkg-reconfigure resolvconf
Run Code Online (Sandbox Code Playgroud)

虽然这是一个单独的问题。