Hit localhost on macOS from VirtualBox Win7 VM

Dec 3, 2018, updated Dec 4, 2018 virtualbox mac windows

At work, everyone on my team has Macs, but the users of one of our apps use Internet Explorer 11 (IE). We obviously need to test in IE, but how? This is where a VirtualBox Win7 VM comes in handy.

Our app has a React front-end, so local development/testing is done on http://localhost:3000. But how do we hit this URL from the Win7 VM? I’ll show you, but first let’s setup the VM.

Import and Configure the Win7 VM

  1. Install VirtualBox. If you get an error when installing VirtualBox, see this fix
  2. Download IE11 on Win7 VM for VirtualBox
  3. Import the VM into VirtualBox:

    unzip IE11.Win7.VirtualBox.zip
    VBoxManage import "IE11 - Win7.ovf"
    
  4. Increase CPUs to 2:

    VBoxManage modifyvm "IE11 - Win7" --cpus 2
    
  5. Increase video memory to 128MB:

    VBoxManage modifyvm "IE11 - Win7" --vram 128
    
  6. Attach an empty optical drive:

    VBoxManage storageattach "IE11 - Win7" \
    --storagectl "IDE Controller" \
    --port 0 \
    --device 1 \
    --type dvddrive \
    --medium emptydrive
    
  7. Install VirtualBox Guest Additions:

    1. Start Win7 VM
    2. If needed, default login password is Passw0rd!
    3. Menu Bar > Devices > Insert Guest Additions CD image…
    4. Open Windows Explorer > Computer > double-click the CD Drive, follow the prompts, then reboot

Hit localhost from the Win7 VM

Okay, now let’s hit http://localhost:3000 from our Win7 VM.

Open Internet Explorer and navigate to http://10.0.2.2:3000. Bam, we can see our app.

But how is this working? In a nutshell, the default gateway of the Win7 VM, 10.0.2.2, is equivalent to localhost on macOS. See this superuser thread for a deeper dive.