vagrant: a better to way to “reset” my guest vagra

2019-03-12 03:57发布

I am relatively new to vagrant but certainly liking it so far.

One of the little problem I often face is that when my host machine's network goes down momentarily, it affects my connection to my vagrant guest vm.

When my host machine's network comes back up again, I have to - on my host machine - run vagrant halt and then vagrant up in order to "reset" my guest vagrant vm's network so that it can connect to the internet once again.

Is there a more "elegant" way of getting my vm's internet connection via my host machine's network to detect that the internet network connection is back up?

4条回答
一纸荒年 Trace。
2楼-- · 2019-03-12 04:25

Here's what i did:

HOST=VM IP Address PRIVATE_KEY_PATH= Private key path

ssh vagrant@$HOST -i $PRIVATE_KEY_PATH to login to the VM

Then, sudo /etc/init.d/networking restart

查看更多
爷、活的狠高调
3楼-- · 2019-03-12 04:25

Updated version (year 2018) of the command listed in other answers*:

For 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

For CentOS 7.5 (network vs networking is quite unfortunate difference, but here we are):

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

*In modern distributions scripts listed in the answers are just wrappers around systemd's systemctl.

查看更多
趁早两清
4楼-- · 2019-03-12 04:36

Regarding what Mitchell answers, for my Vagrant version 1.5.2 the command is little different:

sudo /etc/init.d/network restart

Instead of using "networking". I know is not a big deal, but just wanted to say it.

Great work with Vagrant Mitchell!

查看更多
萌系小妹纸
5楼-- · 2019-03-12 04:41

Yes, the easiest solution is to restart the networking subsystem within the VM itself. SSH connections shouldn't be interrupted. On Ubuntu, do the following:

sudo /etc/init.d/networking restart
查看更多
登录 后发表回答