Configuring VirtualBox guests to access the internet and be accessible from the host

2012-02-28  |   |  tool  

I recently had to create a VirtualBox virtual machine hosting Fedora 16. It took me a little while to achieve both

  • access the internet from the Fedora 16 guest
  • reach the Fedora 16 guest from the host (say via SSH).

It's relatively straightforward if you know the details.

To get access to the internet from the guest, you need to enable the NAT network adaptor.

  • On your (shutdown) VM, open up settings->Network
  • In adapter 1, enable network adapter and use attached to NAT

To get access to the guest VM, we need to give it a static IP and be accessible to the host.

  • On VirtualBox, open up (general) preferences -> network
  • Add a host-only network (if none exist)
  • Configure the host-only network with an IP address (eg
  • Optionally enable the DHCP server and make sure to leave room for static addresses (eg by setting lower address bound to
  • On the guest VM settings -> Network, active a second adapter and use attached to Host-only Adapter with the name of the network you have defined globally (usually vboxnet0)
  • Make sure to note down the MAC address (visible in the advanced section)
  • Boot your guest VM and add the network interface

In Fedora 16, to add a network interface, create a file ifcfg-eth1 in /etc/sysconfig/network-scripts (or an alternative ethn name).

Fill it up with








Make sure to change DEVICE if you use a different ethn name. Make sure to replace HWADDR with the MAC address that you copied from adapter 2. Finally, make sure the static address is not within the range of DHCP addresses. I my example would do fine. Reboot for good measure, you should be able to access the guest from the host at You can even edit your host's /etc/hosts and add the following line my-guest

In my case, I can then SSH into the guest using ssh emmanuel@my-guest

That's pretty much basic stuff but a working example always helps :)

Name: Emmanuel Bernard
Bio tags: French, Open Source actor, Hibernate, (No)SQL, JCP, JBoss, Snowboard, Economy
Employer: JBoss by Red Hat
Resume: LinkedIn
Team blog:
Personal blog: No relation to
Microblog: Twitter, Google+
Geoloc: Paris, France