0

How can I prevent and bring the internet back in my VirtualBox virtual machine when switching between Wifi networks or ethernet networks?

Currently Host OS is W7 and linux is my guest os.

I've tried the following with no success.

sudo ifconfig eth0 down
sudo ifconfig eth0 up

I've also tried disabling and enabling the internet in Network Sharing -> Advanced Settings.

EDIT: So I have tried both the following commands and using a usb wifi card(which doesn't work when you sleep). About bridge adapters

Useful links http://pastebin.com/raw.php?i=YGiu7S6s

William
  • 1,338
  • 6
  • 25
  • 48
  • 1
    I don't use VirtualBox, but in Hyper-V I need to create a virtual switch (or update the current one) when I change from ethernet to WiFi. – Shredderroy Oct 22 '15 at 02:03
  • @Shredderroy do you mind providing a link? Could I use it instead of virtualbox? – William Oct 22 '15 at 02:10
  • Remark: Hyper-V does not apply to Windows 7. In dealing with VMware I have found that sometimes changing in the guest-definition the network from and to NAT, even ending up with the same option as before, fixes the problem. Sometimes one needs also to reboot the host in-between these changes. – harrymc Nov 01 '15 at 09:35
  • @harrymc unfortunately Virtualbox doesn't support hot swapping of Ethernet devices at least natively, so there is no way that I'm aware of to disable and enable inside VirtualBox. Considering it supports usb I might be able to use a usb wifi device but I'm not really sure. – William Nov 01 '15 at 15:14
  • Try restarting the network in the guest: `/etc/init.d/networking restart `. See also [this thread](http://superuser.com/questions/641933/how-to-get-virtualbox-vms-to-use-hosts-dns). Also this [old thread](https://www.virtualbox.org/ticket/3847) might have some useful ideas. – harrymc Nov 01 '15 at 16:58
  • @harrymc I believe the issue was incorrectly closed and therefore there is currently not a solution to the issue as of now. – William Nov 12 '15 at 05:52

2 Answers2

1

So I never found a solution to this bug. I ultimately gave up and used VMWare.

I believe this might be only a Windows 7 bug but I'm not 100% sure.

William
  • 1,338
  • 6
  • 25
  • 48
1

One easy way out of this is to bridge your vbox machine to your pysical network adapters manually. Like this.

enter image description here

Set adapter 1 to whichever you use more (ethernet or wifi) for good measure, and then adapter 2 to the other one. Now your virtual machine will have direct access to your host's network via a bridge. This creates a slight security hole by directly connecting your guest to your host (meaning some strains of malicious software may be able to infect your host through your guest more easily), but if you're not planning on test running viruses on the machine all the time you're good. This time when your host switches network adapters, depending on your configuration, the guest should reconnect as your host does automatically.

You would do well reading this too just to understand the differences.

Cestarian
  • 1,823
  • 6
  • 25
  • 45
  • This doesn't work for me. I you sure you mean `Bridge Adapter`? The internet still goes down when I change Wifi networks. – William Nov 05 '15 at 16:15
  • Just an update it appears I can not get `Bridge Adapter` option to work at all although thank you for the post. – William Nov 05 '15 at 16:53
  • Aw, well if you can't get Bridge Adapter to work I'm out of ideas. Maybe you can use Host-Only Adapter. – Cestarian Nov 11 '15 at 16:47
  • I think this is related but I'm not really certain why I'm having issues https://forums.virtualbox.org/viewtopic.php?f=6&t=37035 – William Nov 11 '15 at 18:45
  • Is this because I'm using a wifi device http://unix.stackexchange.com/questions/16854/why-is-virtualbox-bridged-networking-slow – William Nov 11 '15 at 19:48
  • If you'd read the comments... the bridged networking was not working because the virtualbox host drivers weren't properly installed, i.e. he had to reinstall virtualbox, why don't you try that one and make sure to allow it to install any drivers it wants on your host? As for your second question, apparently there were issues with Wifi speed on virtual machines (NOT the actual bridging process) on bridged wifi cards in virtual machines back in 2011... this could very well have been solved since then. But like I said earlier, host-only fixes it. – Cestarian Nov 12 '15 at 14:13
  • 1
    I'm still not certain why this doesn't work but I'm still convinced this won't necessarily solve my problem. VMWare box works when you switch Wifi networks in NAT mode so I think this is a VirtualBox bug with the following incorrectly closed https://www.virtualbox.org/ticket/3847 issue. – William Nov 12 '15 at 17:18
  • This worked for me where so many other advice had failed, configuring two network adaptors prevented the connection disappearing after a short amount of time – Barry Jan 30 '19 at 10:01