Gray Matter @


How to Access a Web Server in a VirtualBox Machine

RT Cunningham | October 19, 2020 (UTC) | Computers, Web Development

web server VirtualBoxThe instructions available elsewhere when it comes to accessing a web server from a host operating system to a guest operating system, inside a VirtualBox machine, may seem vague or incomplete. I’m trying to rectify that situation by taking you through the process, step-by-step, after you install a guest operating system.

Whether your guest operating system is Windows, Linux or something else, the instructions are the same. You can click on each picture to get a full-sized view of what I’m explaining.

Host Network Manager

You don’t have to do anything with your machine to create a host network, but you have to shut it down or discard the saved state when you change the network settings within it. Let’s do this the right way and make sure it’s shut down and not saved.

Navigate to the Host Network Manager within VirtualBox by clicking on “File” and then “Host Network Manager”. You can use the shortcut of “Ctrl-H” to get to it network manager 1

When you click on “Create” for the very first time, the host will appear with the name “vboxnet0”. The next entry will increment the “0”, should you create network manager 2

Click on “Properties” for “vboxnet0” and make sure “Configure Adapter Manually” is selected. You’ll then see the IPv4 address assigned to the host machine. If you want to change the “/24” block, you can do it network manager 3

Click on “DHCP Server” next to “Adapter” and you can see the details of your “/24” block. Make sure “Enable Server” is selected. When you install a web server on your guest operating system and try to access it from your host operating system, you’ll access an IP address anywhere from the range of “Lower Address Bound” to “Upper Address Bound”. Unless you’re doing something unusual, it’ll probably be the first one available, ending in “.3”.host network manager 4

If you want to make sure you always access the same IP address, set the lower and upper address bounds to the same number. It’s easier than trying to set a static IP address for the guest operating system from within.

Network Settings

The next step is to navigate to your machine’s network settings. Unless you changed it while setting up the machine, “Adapter 1” should be enabled and attached to “NAT”. Leave it that 1

At this point, you need to enable “Adapter 2” and attach it to “Host-only Adapter”. The name of “vboxnet0” should be available in the dropdown box. It’s probably the only one 2

The VirtualBox Machine Web Server

Regardless of what web server software you use, you should now be able to access it from a web browser on the host operating system, using the IP address of the machine provided in the address bar. If you want to use a domain name instead, you’ll need to add the IP address and domain name in your “hosts” file. On Windows, it’s located at “C:\Windows\System32\Drivers\etc\hosts”. You may have to uncheck the read only status of the file properties.

On Linux, it’s located at “/etc/hosts”. I’m not aware of where it is on a BSD or Macintosh system, but it’s probably in the same place since they’re both UNIX-like systems, just like Linux. The format is the IP address from your guest operating system and your chosen domain name, like this:

There are many web development environments and this could be one of them. You could share a folder between the host operating system and the guest operating system to edit web server files. Or, you could do everything from within the VirtualBox machine when you use a lightweight Linux distribution with a desktop.

Since I already use Linux Mint for everything, it’s easier for me to install the web server components without messing around with VirtualBox machines. With Windows, you have to either install a web server stack (WAMP, WEMP or something else) or do it in a virtual environment. Setting up a Linux server in a VirtualBox machine is a much better idea, but that’s only my opinion.

Share: Facebook | Twitter

These Posts May Also Be Interesting:

Gray Matter @
Copyright © 2020, 2021
RT Cunningham

Blogroll and Other Links: