Wednesday 29 August 2018

How to emulate No Internet connection on Guest Windows OS in VirtualBox

Emulating OS being disconnected from Internet is a frequent scenario in testing various software features.

Let's assume we are running Windows as a Guest OS in VirtualBox and want to emulate it being disconnected from Internet.



Before taking any action it is always good to check that you are running the latest version of VirtualBox.

Disconnecting the Guest from Internet can be achieved in several ways:
  • From within Guest Windows OS:
    • If host is using WiFi:
      • Turn off WiFi
      • Disconnect Wireless NIC from WiFi network
      • Disable Wireless NIC
    • If host is using LAN:
      • Disable Ethernet NIC
  • From VirtualBox settings:
    • Devices >> Network >> Network Settings >> Attached to and select Not attached.


      Tooltip text above the combo box says: Selects how this virtual adapter is attached to the real network of the Host OS.

      Virtual Box Manual says: "In this mode, VirtualBox reports to the guest that a network card is present, but that there is no connection -- as if no Ethernet cable was plugged into the card. This way it is possible to "pull" the virtual Ethernet cable and disrupt the connection, which can be useful to inform a guest operating system that no network connection is available and enforce a reconfiguration."

      NOTE: My current VB installation (version 5.2.18 r124319) seems to have a problem with this option: setting "Not attached" makes guest freezing so I need to power off the machine (sending Shutdown signal does not help) but then booting the machine gets frozen as well.
    • Go to Devices >> Network >> Network Settings... and un-check Cable Connected. 


      I tried to find out more what this "Cable connected" actually means. This option is not mentioned in the VirtualBox Manual but there are some explanations on the forum:

      Cable-connected means that you enable/disable the "physical" connection, be it wired or wireless. Like connecting/disconnecting a physical cable on a NIC card, or pulling the plug on your wireless router. It hoes nothing to do with a "cable", rather than "Is there anyone at the end of my connection?" kind of thing...

      What the box does is control whether the emulated NIC is reporting that a link is established or not. You have to imagine that there's a cable between the emulated NIC that a guest OS sees and a NAT "router", a bridged adapter, or any other connection. The imaginary cable can always be plugged or unplugged independent of what's on the other end. This is very similar to having an Ethernet bridge which is "invisible" (has no IP address of its own) but is still connected with a cable that can be plugged in or not. Unplugging and re-plugging the virtual cable is most commonly used to force a guest OS to rediscover the network environment (typically re-request a DHCP lease). Whether the host is wired, wireless, or has no networking capabilities at all is not relevant.

      The "Cable Connected" box controls whether the virtual CAT5/5e/6 network cable (or equivalent ability to communicate, in the case of wireless) is plugged or unplugged. (Sometimes, it's useful to virtualize a system which has a network adapter installed but nothing to talk to.)[source]

      "Cable connected" does not do anything if virtual NIC is Not attached: connecting and disconnecting the cable would do nothing much. It would be like connecting and disconnected a physical cable to your physical Ethernet NIC while your router/server is switched off. [source]
    • Previous action has a shortcut: Devices >> Network >> Connect Network Adapter