Ubuntu – virtual machine loses internet connection if anything happens to host internet connection

virtualbox-networking

I am using Virtual Box and if i lose internet connection or anything happens with my network adapter on host machine i will lose the internet connection on my Virtual Machine.

Even if i connect again, the host is fine but my Virtual Machine can't connect, i need to restart it in order to get internet.

Is there a way to restart networking on the Virtual Machine somehow without rebooting the whole Virtual Machine?

update:

i have tried this command:

sudo /etc/init.d/networking restart

but it just hangs and nothing happens.

Best Answer

This problem is very familiar as it seems and I have experimented a little and it turns out that you can change the network adapter while the VM is running here:

enter image description here

and then change only the Attached to: option to NAT or Bridged Adapter (mine was on Bridged adapter so i changed it to NAT).

enter image description here enter image description here

and click OK. And then change it again to which it was before and again click on OK to accept it.

Now go back to your VM terminal and run this command

sudo /etc/init.d/networking restart

Update:

for Ubuntu 18|20 run

sudo apply netplan

to restart Networking

And the internet connection will work without reseting the VM.

Related Question