流浪汉:更好地“重置”我的客人流浪者vm的网络?

时间:2012-04-30 03:37:24

标签: virtualbox vagrant

我对流浪汉相对较新,但到目前为止肯定喜欢它。

我经常面临的一个小问题是,当我的主机网络暂时停机时,它会影响我与流浪客户的连接。

当我的主机网络再次恢复时,我必须 - 在我的主机上 - 运行vagrant halt然后vagrant up以“重置”我的访客流浪者vm的网络,以便它可以再次连接到互联网。

是否有更“优雅”的方式通过我的主机网络获取我的虚拟机互联网连接,以检测互联网连接是否已备份?

4 个答案:

答案 0 :(得分:26)

是的,最简单的解决方案是重新启动VM本身的网络子系统。不应中断SSH连接。在Ubuntu上,执行以下操作:

sudo /etc/init.d/networking restart

答案 1 :(得分:3)

关于Mitchell的回答,对于我的Vagrant版本1.5.2,命令略有不同:

sudo /etc/init.d/network restart

而不是使用"网络"。我知道这不是什么大问题,只是想说出来。

Vagrant Mitchell的出色工作!

答案 2 :(得分:2)

这就是我所做的:

HOST = VM IP地址 PRIVATE_KEY_PATH =私钥路径

ssh vagrant@$HOST -i $PRIVATE_KEY_PATH登录虚拟机

然后,sudo /etc/init.d/networking restart

答案 3 :(得分:0)

其他答案中列出的命令的更新版本(2018年)*:

对于Ubuntu 16.04。* LTS(Xenial Xerus):

sudo systemctl restart networking

# Check the status - there is no better way with systemd for now:
# https://github.com/systemd/systemd/issues/1287
sudo systemctl status networking

对于CentOS 7.5({networknetworking来说是非常不幸的区别,但我们来了):

sudo systemctl restart network

# Check the status - there is no better way with systemd for now:
# https://github.com/systemd/systemd/issues/1287
sudo systemctl status network

*在现代发行版中,答案中列出的脚本只是systemd的{​​{1}}的包装。