Software, Technology

How-to: VirtualBox Networking Part Part Four – Accessing my Virtual Server

Fiberoptics Guides, Library of University of Alberta Canada, International Business school.jpgThis all started when I needed to run a sandboxed instance of WordPress and thought a virtual Ubuntu 11.10 server would the simple answer under VirtualBox.

Deciding how to network my virtual server so that I could practically use it, I’m going to run two network adapters on my virtual server to give me the access I need; a standard NAT adapter and a Host-only adapter.

My host is Ubuntu 11.10 Desktop and my guest is 11.10 Server, which keeps things within the Linux way of life.

Guest Access to the Internet
First, I need my guest machine to be able to access the Internet for installing updates, downloading packages and the like. I need to access it from my host machine, but I don’t want the server to be accessible from anywhere else on the network.

Selecting my guest machine from the VirtualBox Manager window, I then select Settings > Network.

I begin by keeping the default networking NAT adapter. This allows the guest machine to access the Internet through my host’s connection. The guest isn’t visible to anyone else on my network; I cannot access any guest resources from my host machine either, nor can any guest machines access each other.

Configure Host-only Adapter in VirtualBox Manager
VirtualBox vboxnet0 set-upThe easy method is to use the default Host-only adapter provided by VirtualBox, this is the one named vboxnet0, but you can add more if you want several separate Host-only networks. If you go to the VirtualBox Manager main window and select File > Preferences > Network, you can configure vboxnet0 or add new adapters.

Click on the “Edit” button for your Host-only network, that’s the screwdriver icon titled “Edit host only network” and you’ll find the default settings. The IP address is the address at which the guests can access the host. I’ll leave this as-is.

By default, vboxnet0 has a DHCP server set up to dynamically allocate IP addresses on a per session basis. I want to my WordPress virtual server to keep static IP addresses, so on the DCHP tab, I uncheck the “Enable Server” box for DHCP

Add Host-only Adapter to Guest
VirtualBox Add Host-Only Network AdapterI’ll add another network adapter to my guest machine, a Host-Only Adapter, that enables a self-contained, private, virtual network consisting solely of my host and any guests using host-only. Any of the member machines can access each other, but nothing outside it can get in.

So on my Adapter 2 tab for my guest, I set the Attached to option to Host-only, and the name is the default vboxnet0. Promiscuous mode doesn’t matter, but I do need the Cable Connected checkbox enabled.

Configure the Guest
I need my guest’s virtual server to have a static IP address on the host-only network, otherwise the address changes for every session and I have to work out what it is before I can access it from the host. Logging into the guest, I open a terminal and issue the following command:

ifconfig eth1 netmask up

This sets the IP address on my host-only adapter for this guest and brings up the network interface. It uses the 192 network prefix for domestic networks, followed by .168 for the start of the host ID, .56 as the host-only sub-net range, and I could use use any final identifier above .1 (my host) on my host-only network. The NAT adapter is sitting on eth0, so logically the Host-only adapter is bound to eth1. I can now secure shell (SSH) or browse to the guest from the host using this IP address as a test.

Howver, this is just temporary; if I reboot, this configuration will disappear. To make it permanent, I need to add it to the /etc/network/interfaces file (as root) in the form:

# The host-only network interface
auto eth1
iface eth1 inet static

Once I reboot, this interface will be raised automatically. I can check that it’s present using the ifconfig command in a terminal on the guest.

Naming of parts
Since I’m not so good with numbers and IP addresses, I’d rather use the guest machine name over the IP address. To do this I can add an alias to the /etc/hosts file on my Host machine, so that I can browse by name to my running guest.

I edit the file (as root) adding the line: ocelotsvr

If I add more guests to the host-only network, I can do the same so that I can address any of them from any of them by name.

Any Port in a Storm?
The networking experts out there will have spotted an alternate route to accessing my virtual server.

Using my default NAT adapter, I could run some extra configuration there to let me access my virtual server from the host – without using Host-only networking.

VirtualBox NAT set up with  port forwardingI can set up port forwarding in VirtualBox, using the guest’s Network Adapter settings panel. Going to the NAT adapter, the big button at the bottom is for Port forwarding. This opens a further configuration dialog box so I can set the port forwarding rules for this network adapter for this guest only.

I need two rules; one to access the Apache web-server on my guest, the other to handle all the other TCP traffic (http requests, mostly).

Keeping it simple, I’ll name them Apache and TCP; both use the TCP protocol. If I stick to the common port numbers, 8888 on the host forwarding to port 80 on the guest for Apache; then 2222 on the host forwarding to port 22 on the guest; this gives me specific access on the guest for those service requests. Anything else will be rejected by VirtualBox as there’s no viable route.

This also means any other guests I wish to run can’t access this virtual server, as no network route exists under NAT. RC

Image credit: Fiberoptics Guides, Creative Commons from Library of University of Alberta Canada, International Business school

About Robin Catling

Robin Catling gained degrees in both arts and technology which led to a diverse portfolio of employment. A freelance systems analyst, project manager and business change manager for the likes of American Express, British Airways and IBM, he moved on to web design, journalism and technical authoring. He has also worked in film and television, both behind and in front of the camera, including productions by Steven Spielberg, Martin Scorcese, Ron Howard and Ridley Scott. A qualified three-weapon coach, he runs West Devon Swords teaching sports fencing to all age groups, and in recent years qualified with the British Federation of Historical Swordplay to teach medieval and renaissance combat in the Historical Western Martial Arts.


5 thoughts on “How-to: VirtualBox Networking Part Part Four – Accessing my Virtual Server

  1. This web site definitely has all of the info I needed about this subject and didn’t know who to ask.

    Posted by Wallett | Oct 5, 2012, 8:58 am
  2. your post is really informative for me. i liked it very much.

    Posted by C Gabrielli | Oct 7, 2012, 5:38 pm
  3. your work’s fine.

    Posted by Celly Watanabe | Nov 29, 2012, 12:41 pm
  4. I know this is ~6 years after the fact, but in doing a search for virtualbox networking (currently), and trying to find something that explains it clearly – this was awesome! Thank you so much for putting all of the articles together for this. You did a outstanding job and helped me tremendously!

    Posted by | Mar 6, 2018, 1:38 pm


  1. Pingback: How-to: Build a WordPress Server Part One – LAMP « Everything Express - Oct 28, 2012

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Twitter Updates

Follow us on Twitter @EverythingExpre

Find Us on Facebook

Enter your email address to follow this blog and receive notifications of new posts by email.



BBC World News

BBC World News
Opens the BBC World News page.
%d bloggers like this: