我对 Linux 和 Vagrant 还比较陌生。我不久前将我的 VM 来宾系统(Windows 主机上的 VirtualBox 5.0.18 + Vagrant 1.8.1)从 Xubuntu 15.10 更新到 Xubuntu 16.04。在那一刻或不久之后,我注意到一些奇怪的现象,例如鼠标光标未对齐(偏离了几个像素)和缺少共享目录。我的猜测是,这是由于在 期间报告了以下错误vagrant up
:
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
default: Adapter 2: hostonly
==> default: Forwarding ports...
default: 8080 (guest) => 8080 (host) (adapter 1)
default: 9000 (guest) => 9000 (host) (adapter 1)
default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
==> default: Machine booted and ready!
GuestAdditions 5.0.18 running --- OK.
==> default: Checking for guest additions in VM...
==> default: Configuring and enabling network interfaces...
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!
/sbin/ifup eth1
Stdout from the command:
Failed to bring up eth1.
Stderr from the command:
mesg: ttyname failed: Inappropriate ioctl for device
run-parts: /etc/network/if-up.d/ubuntu-fan exited with return code 1
我结合Vagrant和VirtualBox在网上查找了错误,但我找到的案例似乎与我的有点不同。人们写了/etc/udev/rules.d/70-persistent-net.rules
- 但它似乎不存在于我的机器上,也不存在/etc/sysconfig
。
/sbin/ifup eth1
登录后尝试运行以获取更多信息会给出以下信息:
vagrant@IDE-machine ~ $ sudo /sbin/ifup -v eth1
Configuring interface eth1=eth1 (inet)
/bin/run-parts --exit-on-error --verbose /etc/network/if-pre-up.d
run-parts: executing /etc/network/if-pre-up.d/bridge
run-parts: executing /etc/network/if-pre-up.d/ethtool
run-parts: executing /etc/network/if-pre-up.d/wireless-tools
run-parts: executing /etc/network/if-pre-up.d/wpasupplicant
/bin/ip addr add 192.168.56.21/255.255.255.0 broadcast 192.168.56.255 dev eth1 label eth1
RTNETLINK answers: File exists
Failed to bring up eth1.
我的 Vagrant 文件如下所示:
Vagrant.configure(2) do |config|
# a locally stored box
config.vm.box = "IDE-machine"
config.ssh.private_key_path = "ssh/id_rsa"
config.vm.network "forwarded_port", guest: 8080, host: 8080
config.vm.network "forwarded_port", guest: 9000, host: 9000
config.vm.network "private_network", ip: "192.168.56.21"
config.vm.provider "virtualbox" do |vb|
vb.gui = true
vb.memory = "12288"
vb.cpus = 2
vb.name = "my_IDE-machine"
vb.customize ["modifyvm", :id, "--monitorcount", "1"]
vb.customize ["modifyvm", :id, "--vram", "64"]
vb.customize ["storageattach", :id, "--storagectl", "SATA", "--port", 1, "--device", 0, "--type", "hdd", "--medium", "V:/BoxStorage/Projects.vdi"]
end
config.vm.provision "shell", inline: "/vagrant/provision.sh"
end
来宾添加已安装,我使用vagrant-vbguest
之前设置了正确的来宾插件版本的插件。
有人知道可能是什么问题,或者暗示我如何进一步挖掘?
更新: 我被指出了这一点:https://github.com/mitchellh/vagrant/issues/7155(这并不完全适用于我的情况)这导致我这样做:https://askubuntu.com/questions/689070/network-interface-name-changes-after-update-to-15-10-udev-changes/732638#732638
我尝试更改/etc/default/grub
,GRUB_CMDLINE_LINUX="net.ifnames=0"
然后update-grub
以 root 身份重新启动,但无济于事。
更多的探索向我展示了这一点:
vagrant@IDE-machine ~ $ cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
auto eth1
iface eth1 inet static
address 192.168.56.21
netmask 255.255.255.0
#VAGRANT-END
更新2:这里要求的是 dmesg 的输出和 ubuntu-fan 的内容:
vagrant@IDE-machine ~ $ dmesg | grep eth
[ 1.692133] e1000 0000:00:03.0 eth0: (PCI:33MHz:32-bit) 08:00:27:af:31:b4
[ 1.692144] e1000 0000:00:03.0 eth0: Intel(R) PRO/1000 Network Connection
[ 2.068113] e1000 0000:00:08.0 eth1: (PCI:33MHz:32-bit) 08:00:27:94:1e:dc
[ 2.068120] e1000 0000:00:08.0 eth1: Intel(R) PRO/1000 Network Connection
[ 5.732516] e1000: eth1 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX
[ 5.732980] IPv6: ADDRCONF(NETDEV_UP): eth1: link is not ready
[ 5.733061] IPv6: ADDRCONF(NETDEV_CHANGE): eth1: link becomes ready
[ 6.790923] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
[ 6.793512] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
[ 6.795646] e1000: eth0 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX
[ 6.796069] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
vagrant@IDE-machine ~ $ cat /etc/network/if-up.d/ubuntu-fan
#!/bin/sh
set -e
case "$IFACE" in
lo) exit 0 ;;
fan-*) exit 0 ;;
esac
case "$ADDRFAM" in
inet) ;;
*) exit 0 ;;
esac
# NOTE: NetworkManager simply does not call out to the normal
# down hooks as it only checks _after_ the interface has
# been lost. Roll with this.
case "$PHASE::$METHOD" in
post-up::static|post-up::dhcp|post-up::NetworkManager) ;;
pre-down::static|pre-down::dhcp|post-down::NetworkManager) ;;
*) exit 0 ;;
esac
case "$MODE" in
start|stop) ;;
*) exit 0 ;;
esac
/usr/sbin/fanctl net "$MODE" "$IFACE"
答案1
你检查过你的/etc/network/interfaces
配置文件吗?也许您有多个网关这里。
无论如何,稍微调整一下该文件并使用它ifconfig
可以帮助您解决问题。还要检查权限,我怀疑它来自那里,但仍然:/
/etc/network/interfaces
如果还没有这种情况,您可以尝试返回到更简单的配置,然后一点一点返回到原始配置文件。我会这么做的。
编辑:从您的dmesg
输出看来,链接已准备就绪,因此网络部分应该没问题。如果制作的话dmesg | grep eth
,有相关信息吗?
还有,你能养猫/etc/network/if-up.d/ubuntu-fan
吗?它以退出代码 1 退出,检查那里发生的情况可能很有趣。
更新:
您的dmesg
输出看起来没问题,链接 eth0/1 最终已准备就绪,因此网络应该可以正常工作。
您应该尝试ubuntu-fan
逐行执行脚本并检查退出代码(echo $?
,应该是0
)。我想知道问题是否出在fanctl
最后的程序上。它通常用于控制机器上的风扇,但这里是一个虚拟机,所以...如果它来自这一行,您可以尝试查看它失败的原因,但我会删除该fanctl
行,然后也许整个文件事实。我猜其他行是在这里处理要触发的事件fanctl
。
我检查了我的 vagrant VM(虽然主要是 ubuntu 14.04),但我没有fanctl
在任何地方看到任何东西......我不确定尝试控制 VM 内的风扇是否有意义。