Work in progress

This site is currently undergoing an update. If you spot any problems on this page, please let me know.

VirtualBox host to guest networking

Update 2013: This article is out of date. VirtualBox now includes a host-only network type. On my laptop I create 2 networks, one NAT to provide the VM with internet, and one host-only to provide the laptop access to the VM, even if the laptop is not on the internet.

Update: I just repeated this process with Ubuntu 11.04 host, 10.04 guest. It worked as described here. I also automated the setup on the host, and added a note at the bottom of the post explaining how I did that.

I’m creating a new development server on VirtualBox. I was using VMWare until recently, but since upgrading to Ubuntu 9.04 64bit, I’ve decided to try VirtualBox instead. I also recommended VirtualBox to my brother, so by using it myself I’ll be better able to support him if he has any issues.

Installing a new virtual machine was a breeze. After I activated hardware virtualisation in my bios, I installed a 64bit version of Ubuntu server 8.04 LTS. The install failed a couple of times, not sure why, but third time lucky.

My first major stumbling  block was connecting to the virtual machine from the host machine. By default VirtualBox gives the guest (virtual machine) a NAT ethernet connection. So the guest can connect to the network, including the internet, but the host can’t connect to the guest. I’m creating a development server, so that’s precisely what I want to do, connect from the host to the guest. With a little research, it turns out there’s an easy solution (on Linux hosts).

The VirtualBox article on Advanced Networking in Linux was my guide. I’ll document all the steps I took here.

Install bridge-utils, vtun and uml-utilities:

sudo apt-get install bridge-utils vtun uml-utilities

Create the bridge:

sudo brctl addbr br0<br /> sudo ip link set up dev br0<br /> sudo ip addr add dev br0<br />

Create a tap device for the guest to use, put your username in place of USER:

sudo tunctl -t tap0 -u USER<br /> sudo ip link set up dev tap0<br /> sudo brctl addif br0 tap0

If you need multiple guests connected, repeat this step replacing tap0 with tap1, tap2 and so on. Always use br0.

Now modify the virtual machine settings and map one of the network adapters (probably the second one) to the device tap0. Choose Attached To Host Interface and select the device tap0. I left the first network adapter as a NAT adapter so the virtual machine has internet access. In this configuration, I can disconnect the guest from the internet and / or the host separately.

When the virtual machine has started, setup the network. Assuming the guest is an Ubuntu machine, run these commands on the guest. If you linked the first network adapter to tap0 then use eth0 on the guest, if you chose the second network adapter use eth1, 3 to eth2, 4 to eth3 and  so on.

sudo ip link set up dev eth1<br /> sudo ip addr add dev eth1

Now test it all works. On the host machine try ping -c4 and on the guest try ping -c4 Assuming both machines are set to respond to pings (default in Ubuntu), you should see 4 successful pings.

If this works, you can set the address permanently by editing /etc/network/interfaces and adding this text.

# Host only network<br /> auto eth1<br /> iface eth1 inet static<br /> address<br /> netmask<br /> network<br /> broadcast

I’ve used the 10.9.*.* addresses as an example. You can use any private network address (10.*.*.*, 192.168.*.* or 172.16.*.*-172.31.*.*). The most commonly used addresses are 192.168.*.* and 10.0.*.* or 10.1.*.* so I recommend staying away from them. You want to choose addresses that won’t clash with anything else on your network.

Edit: Finally, I added a script to automate the setup on the host machine. I created a script called /etc/init.d/virtualbox-bridgenetwork with the following contents:


Create the br0 interface

brctl addbr br0
ip link set up dev br0
ip addr add dev br0

Create tap0 for the vm to connect to

tunctl -t tap0 -u USER
ip link set up dev tap0
brctl addif br0 tap0`

You need to change USER to your own username and modify the IP to whatever you were using. Then to make this script run automatically at boot time, run:

sudo update-rc.d virtualbox-bridgenetwork defaults

Now the br0 and tap0 interfaces should be automatically created at boot time.


Callum at 2012-02-13 10:35:36

I think the newer versions of VirtualBox have host to guest support in-built. I'm using VirtualBox's own network adapters since upgrading to Ubuntu Precise / VirtualBox 4.1.8_Ubuntu.

Harry Slaughter at 2010-08-09 22:07:16

You can also simply use the "Bridged Adapter" instead of or in addition to the default NAT adapter. The guest should then be able to fetch an IP from the hosts network and you can talk to the guest using that IP. Worked easey peasey for me (Winblows host, Ubuntu10 guest)

pintu at 2011-05-28 10:49:40

Thanks for a good article Now i am able to configure my host to guest networking..&amp; able to access guest os from host .

Pepe at 2009-10-28 17:34:57

Hello Sensei... I'm not sure when, but I will try Ubuntu soon. I found OSCAR which is an opensource hospital information solution and runs on Ubuntu. See you soon in my Linux and opensource adventures

Tomas Jancik at 2010-04-14 11:02:51

exactly what I'm looking for... I'll try it later... thx very much

Tomas Jancik at 2010-05-18 17:09:22

I recently updated to Ubutnu 10.04 becausae of it's LTS, but since that time VBox does not start when I setup the bridge network. I have to disable eth1 to boot virtual system... I took a screenshot of the error message I tried to modprobe the modules, but still it didnt work... can you help?

Kevin at 2010-06-07 12:48:53

I have not gotten it working already. I am still using the exact steps from your guide, but I put them into scripts that I execute prior to launching the VirtualBox software. It works perfectly, but I'll try what you posted here, when I get home, and let you know how I fare with it. Thanks for the follow-up

Callum at 2010-08-09 22:24:48

That approach only works if you have a live network connection on the host. I have a development server on my laptop so I like to be able to work whether or not I have a wifi or ethernet connection. Also, as I switch connections, I'd have to change the bridged settings depending on which network card I'm using. It is a simpler option when the host has a continuous network connection.

Samuel at 2010-08-05 16:45:05

Callum Thanks for your contribution. I have a slight problem which is also replicated on the virtualbox documentation; on which machine do I type the above commands- ie the guest or the host? Please help.

Week in Review &#8211; 2010-15 at 2010-11-07 02:11:22

[...] the guest &#8211; not too useful if your guest is a server. Here are some useful references: a) b) [...]

Callum at 2009-10-28 19:39:27

Wonderful news sensei. If you need any Ubuntu or linux related help, my lines are always open for you my friend. :-)

Adam at 2012-02-13 04:24:46

Just what I was looking for, work perfectly. I now have a fast connection between my virtual windows and my debian host Thanks Adam

Callum at 2010-08-05 18:46:52

I'm not sure which commands you're asking about. The first part is on the host, the second the on the guest. The last two code blocks are on the guest, everything else is on the host.

New Linux User at 2010-04-27 16:28:34

Amazingly easy instructions, thx a bunch!!!!

adrian at 2011-02-01 06:00:06

How do you do this with Ubuntu host and WinXP guest?

abidibo at 2010-02-08 07:46:39

Good Job, thanks

Callum at 2010-06-04 23:37:55

I finally got virtualbox up and running again, but I'm still running 8.04 as the guest. The changes are persistent and last across sessions. Here's what I have in /etc/network/interfaces: <code># Host only network auto eth1 iface eth1 inet static address netmask network broadcast</code> Do have the auto eth1 part? I realise I missed that from my howto. Or did you find a solution already?

Callum at 2010-04-27 19:12:51

It's been a while since I set this up myself. I honestly can't remember if or how I automated the brctl and tunctl stuff. I probably stuck it in a script somewhere, I'm not sure. You could look into running scripts automatically on startup and then put it in a script, I think that'll work, but I'm not sure. Best of luck with it. Feel free to post back here if you find a way to get it working.

Kevin at 2010-04-27 16:51:05

Thanks Callum! Your guide was concise and worked perfectly. You described how to make the changes persistent by defining the interface in the guest's interfaces file in /etc/network. I did that and when I rebooted my guest OS, eth1 was not present when I did an ifconfig. I then did ifconfig eth1 up, but it did not have an ip address defined. I am running ubuntu server 9.10 as the guest and ubuntu desktop 9.10 as the host. I verified that my /etc/network/interfaces addition was the same as what you posted, but the changes still do not persist between GUEST restarts. (I attached eth1 to tap0 like you suggested) I can create a script to do... <q cite="sudo ip link set up dev eth1 sudo ip addr add dev eth1"> ... easily enough, but it would be nice to persist it. Also, is there a need to change any config on the host to make the creation of the bridge and the tap persistent? Thanks again for the great guide. Kevin

Callum at 2012-07-02 13:27:24

Nope, I stopped using this and instead use VirtualBox's inbuilt functionality.

Callum at 2010-07-31 12:30:29

Apologies for the delayed reply, your message slipped into oblivion in my inbox. I recently set up Virtualbox on 10.04 and it works ok for me. As I read your error message, it seems like your tap0 interface doesn't exist. Check the virtual machine settings, maybe you have network adapters mapped to the machine which no longer exist?

Ramakant at 2012-02-27 05:25:02

Hello Callum, I have installed Windows 7 ultimate in my PC and in that I installed Virtual Box . In the virtual box i installed Oracle Enterprise Linux 5.5. I have done the bridge networking. Now I cant ping the host or guest from either side. Could you please help me how to configure the network so that I can ping both the OS from either end. Looking forward for your reply at the earliest. Best Regards, Raxun

Callum at 2013-04-25 10:14:58

Recent version of VirtualBox include a "host only" type of network adapter, so this whole configuration is now obsolete.

Callum at 2011-03-03 12:13:02

I've never figured out how to automate the br0 and tap0 interface setup on the host. I think a simple bash script run as root on bootup would do it, but I haven't looked into it. I'm not sure what virbr0 is, don't think I've ever seen it on my setup.

Tom Bradford at 2011-03-02 01:52:05

Hmmm. Only part sorted, I'm afraid. The next time I booted the host all the interfaces created on the host in accordance with your instructions had vanished and I had to set them up manually again, at which the guest booted up and the hostonly network established itself. How do I make the br0 and tap0 interfaces persistent on a Ubuntu Server 10.04 host? And, as an aside, what is the virbr0 interface Ubuntu creates by default for, if not for this?

Callum at 2011-02-01 14:54:50

No idea, you might find a new network adapter pops up in Windows XP and you can simply set the network address for it. Don't know.

Callum at 2011-03-01 00:00:37

Glad the article was helpful and you got your problem sorted. :-)

Tom Bradford at 2011-02-28 22:55:29

Glad Google led me to this when I'd been beating my head against the wall after several days of trying to set up a hostonly network between a Ubuntu 10.04 server host and a Linux-based routerOS base. A major part of the problem for me was that the VirtualBox manual clearly says: "when host-only networking is used, VirtualBox creates a new software interface on the host which then appears next to your existing network interfaces." Equally clearly VirtualBox doesn't create the interface on the host - the user has to do it, as per the above. Having mistakenly assumed that VB had created the virbr0 interface that appears in Ubuntu's ifconfig I spent hours trying to connect to it! Another little wrinkle that tripped me up - when creating the hostonlyadapter it has to carry the same number as the nic it is being associated with, ie nic3 hostonlyadapter3 even if it is the first or only hostonlyadapter.

Thiago Vieira at 2012-03-02 20:01:33

Thanks a lot for this solution, it works perfectly at Ubuntu 11.10 kernel Linux 3.0.0-16-generic x86_64 and VirtualBox 4.1.2

Callum at 2012-02-27 10:21:20

I know nothing about a Windows host. My setup is all linux. I no longer use the method described here because VirtualBox now includes this functionality as standard (at least on a Linux host).

Sumit Kumar at 2013-04-25 14:40:14

actually what i want to do is, i want to install two vm on a ubunut host. specially i am intrested in bridging because i want to communication between both vm in such a way so that packet going from one VM to another VM can be sniffed using host machine. Is it possible using host only adapter if possiblre please guide me to right way?

Alan Porter at 2011-07-20 02:16:50

I still don't understand why I did not need the tap interface on the Ubuntu boxes, but I do need it on the Mint one. But I am very happy that your solution worked for me. I was able to automate the creation of the interfaces. This is my /etc/network/interfaces file: <code> # interfaces(5) file used by ifup(8) and ifdown(8) auto lo iface lo inet loopback # eth0 is controlled by NetworkManager #auto eth0 #iface eth0 inet dhcp # VirtualBox TAP device bridge auto tap0 iface tap0 inet manual up ifconfig $IFACE up down ifconfig $IFACE down tunctl_user alan # VirtualBox NAT bridge auto vnet0 iface vnet0 inet static address netmask #bridge_ports none bridge_ports tap0 bridge_maxwait 0 bridge_fd 1 bridge_stp off 1 up ip link set vnet0 qlen 1000 up iptables -t nat -I POSTROUTING -s -j MASQUERADE down iptables -t nat -D POSTROUTING -s -j MASQUERADE </code> I hope this helps others. Alan

Alan Porter at 2011-07-20 00:28:32

I have set up two machines using Ubuntu 10.10 like this, except I left out the tap interface entirely. Instead, I told the host to bring up a bridged network called 'vnet0' (instead of br0), and I told virtualbox to bridge directly to vnet0. This works nicely whether my host's "real" network connections (eth0 or wlan0) are up or not. I usually NAT the vnet0 traffic out through eth0 or wlan0 (using 1 line in a shorewall 'masq' file). I am curious why you needed a tap interface on your bridge. What purpose does it serve? The plot thickens. I am now trying to duplicate this setup on a Linux Mint Debian Edition box, and something is blocking some of my packets. For example, my winxp guest sends a DHCPDISCOVER to the vnet0 interface to ask for an IP address. My DHCP (running on the host) server sends a DHCPOFFER back onto vnet0, but the winxp guest never sees it. I am still debugging this. If you have ideas, I'd love to hear them. Thanks for sharing your experience... I will experiment with the tun setup that you describe, and see if it helps. Alan Porter

Alan Porter at 2011-07-20 15:50:31

Shorewall allows me to NAT through whichever connection is active. My /etc/shorewall/masq file looks like this: <code> eth0,wlan0 </code> If I were doing the same thing using an iptables rule, I would simply do this: <code> iptables -t nat -I POSTROUTING -s -j MASQUERADE </code> You do not have to specify which interface you're masquerading (NAT-ing) to. It'll figure that out based on the destination and the routing tables. Alan

Callum at 2011-07-20 14:48:34

Thanks for sharing. So you're able to use the VirtualBox NAT connection to talk from the host to the guest, is that correct? It's a long time since I set all this up, but as I recall, I set it up because when my external networks were down (eth0 wlan0) I was unable to reach my guest machine. I was using the guest machine as a dev web server, so working without internet became impractical. Maybe VirtualBox has changed slightly and now I can use a NAT connection instead, or maybe I missed something originally.

Alan Porter at 2011-07-20 15:06:51

Actually, no. I am using a single bridged connection from virtualbox to my 'vnet0'. I do not use virtualbox's NAT at all. Then I use dnsmasq to do DHCP and DNS and I use shorewall to do NAT to my hosts eth0 or wlan0 (whichever one happens to be in use at the time). My primary motivations were: (1) I could start my VM's whether my host's eth0 or wlan0 were up or down. And I could move my laptop, unplug eth0, start using wlan0, and the VM's would be unaffected. I would never need to change their bridge connection just because the host had changed the way it connected to the world. (2) I could use dnsmasq to keep track of what winxp was doing, and I could also insert my own fake DNS entries, like " =", etc. (3) Networking is cool. A note about my example interfaces file above... the qlen line is not needed... that was an experiment. And you may have to get rid of the commented-out "bridge_ports none" line. Alan

Callum at 2011-07-20 15:32:42

Ok, now I understand. Thanks. I suppose that you need to manually change the NAT configuration of vnet0 according to which interface is up, is that correct? Or does the NAT routing automatically switch to whichever is the "live" outgoing network? If it does, I suppose that's a simpler solution. My setup does allow me to disconnect my guest machine from the internet while still keeping it available from my host. But that's not something I ever remember doing...

syahreza at 2012-07-02 06:24:44

hello... great tutorial, but i had some problem... i can't connect to my host from guest os.. any idea ?

Callum at 2013-04-15 13:09:29

I'm not very familiar with all this stuff. I posted what worked for me at the time, but since then I've moved to using 1 NAT adapter and 1 host-only adpater. That "just works" for me. If my laptop is offline, the NAT adapter doesn't work, but the host-only does. I did all of this without TAP / TUN or otherwise. Best of luck finding a solution.

Sumit Kumar at 2013-04-25 06:49:29

Hello Callum Very good article but there is a problem for me. I am using virtual box 4.2.8 with ubuntu 12.04 host and ubuntu 11.10 guest. I am unable to setup bridge networking beetween host and guest. here i am pasting configuration of interfaces. Configuration on Ubunutu12.04 host auto lo iface lo inet loopback # Configure the bridge auto br0 iface br0 inet static address netmask broadcast gateway # Ports you want to add to your bridge bridge_ports eth0 # Time to wait before loading the bridge bridge_maxwait 0 auto eth0 iface eth0 inet manual And for ubuntu 11.10 guest, i am selected bridged adapter and under name i selected eth0 interface. And configuration of guest ethernet interface is auto eth2 iface eth0 inet static address netmask broadcast gateway But it is not working when i ping it just says destination host unreachable. Please help

Rava at 2012-11-19 11:42:09

Hi ! thanks for the info. To sum up, i installed an ubuntu 12.04, and virtual box. I need a VM, with 2 eth. The frist eth (eth0 on vm) is my wifi (wlan0 on host ), the second is usually the rj45 (eth1 on vm, eth0 on the host). The trick is that, sometimes, no wifi is allowed at customer, this means no more eth0 on vm o(((( So, i created a tap0, linked to virbr0, for my interface. thanks, thanks, thanks o))) /Rava

Priya at 2013-04-14 22:09:09

I ‘ve been really stuck up trying to established a connection between the Host OS &amp; VirtualBox, Really Appreciate the help!! I ‘ve tried the solution that you suggested here but to no avail. I ‘ve installed Virtualbox 4.2.10 on RHEL 6 and installed guest OS RHEL 6 on it. I ‘ve configured NAT &amp; Host-only adapter in order to established the connection with the Virtualbox from the Host OS. and The Host server is connected to Internet through a modem not to any Office network as this is a Personal server. The Host OS IP is &amp; its DNS is which i ‘ve assigned through the system-config-network utility on RHEL 6. and followed the instructions for the Guest VM IP given here. i.e guest configured NAT &amp; Host-only adapter for the Virtualbox given here. and also checked with the ifconfig command that the IPs assigned correctly. The Guest Virtualbox IP: &amp; DNS which i ‘ve assigned through the system-config-network utility on RHEL 6. But still I can not ping the Host OS from the Guest OS i,e from the VirtualBox when i ping the host OS it says that the Network unreachable. The entries in the /etc/hosts &amp; /etc/resolv.conf for the Host IPs and the DNS which is same as that of HOST OS is there. But it failed to establised connectivity from the Guest OS to Host OS. although i can ping the guest OS from the Host OS. Could you please suggest what i need to do inorder to establish connectivity from Guest OS to Host OS. Thanks Priya

Sumit Kumar at 2013-04-26 06:11:15

Thanks for help

Callum at 2013-04-25 19:16:13

No idea, I'm not affiliated with VirtualBox in any way, I just posted what worked for me. Best of luck.

Priya at 2013-04-13 22:48:40

Could you please suggest on the following Issue that I am facing with the VirtualBox connectivity with the Host Server.. Thanks in Advance, I ‘ve installed Virtualbox 4.2.10 on RHEL 6 and installed guest OS RHEL 6 on it. I ‘ve configured NAT &amp; Host-only adapter in order to established the connection with the Virtualbox from the Host OS. The issue is that the Host machine is able to connect to Virtualbox i.e on which the virtualbox is installed But not vice versa i.e Failed to ping the server from Virtual machine. even though Virtual machine can connect to Internet but not able to ping the server. there is no ISsue in sharing a folder from the Host OS to virtaulbox . able to mount share directory from the Guest OS i.e from VirtualBox. i ‘ve disabled the SELINUX in both the machine as well. when i ping the Host machine from the virtualBox . ping or ping IP it says Destination host unreachable. But can ping the Virtual machine from the Host. Please see the following configuration of /etc/hosts &amp; /etc/resolv.conf of both the machine. Host OS which is &amp; Guest OS i.e VirtualBox which is And the IPs of both are : And &amp; the DNS which i ‘ve configure is [root@ebs Desktop]# vi /etc/hosts [root@ebs Desktop]# cat /etc/hosts The same configurtion in VirtualBox /etc/hosts file as well localhost.localdomain localhost ebs ebs1 [root@ebs Desktop]# cat /etc/resolv.conf The same configurtion in VirtualBox /etc/resolv.conf file as well # Generated by NetworkManager search nameserver nameserver Could you please suggest why the Guest OS i.e Virtual machine is not able to ping the HOST OS despite getting the shared folder or no issue in mounting the shared directory from the Virtualbox. what i am trying to achieve is to esatablish a connection between the Linux OS Host And VirtualBox for that i ‘ve assigned an IP of to linux OS Host and assgined a DNS which is same as IP of the Host OS through netconfig utility. Please see the following. [root@ebs Desktop]# ifconfig eth0 Link encap:Ethernet HWaddr 00:1E:67:22:2D:6E inet addr: Bcast: Mask: UP BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) Memory:d0100000-d0120000 eth1 Link encap:Ethernet HWaddr 00:1E:67:22:2D:6F inet addr: Bcast: Mask: inet6 addr: fe80::21e:67ff:fe22:2d6f/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:79359 errors:0 dropped:0 overruns:0 frame:0 TX packets:64585 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:100 RX bytes:65810295 (62.7 MiB) TX bytes:12737639 (12.1 MiB) Memory:d0000000-d0020000 lo Link encap:Local Loopback inet addr: Mask: inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:9325 errors:0 dropped:0 overruns:0 frame:0 TX packets:9325 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:18942730 (18.0 MiB) TX bytes:18942730 (18.0 MiB) vboxnet0 Link encap:Ethernet HWaddr 0A:00:27:00:00:00 inet addr: Bcast: Mask: inet6 addr: fe80::800:27ff:fe00:0/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:1014 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 b) TX bytes:87654 (85.5 KiB) virbr0 Link encap:Ethernet HWaddr E2:A1:32:D0:FB:8E inet addr: Bcast: Mask: UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:1750 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 b) TX bytes:85491 (83.4 KiB) As the machine having 2 Ethernet cards so it Automatically assigned the eth1 IP to . And virbr0 inet addr is ISP assigned address as the server is connected to internet through a modem. And vboxnet0 is VirtulaBox &amp; whose IP is : Could you Please suggest How could both the Host &amp; guest OS which virtualbox can communicate i.e act like two Server which is connected as I wanna Install IDM database on the Virtualbox machine which is going to be Integrated with EBS R12 database which is installed on the Host OS. Is it the Issue with the DNS which same as IP add of the Host OS ? Could you please suggest what i need to do in order to make the connection between Host OS &amp; VirtualBox, Thanks &amp; Regards Priya

Emre at 2013-09-16 21:30:02

Thanks for your useful instructions instead of VirtualBox's useless host-only.

Jeroen Flamman at 2014-03-29 23:57:50

Thank you Callum for sharing this. 4.5 years later and still very helpful!

Virtualbox host-guest network setup [closed] | ASK AND ANSWER at 2015-12-15 21:04:18

[&#8230;] You can do this on a Linux host. I&#8217;ve documented the steps I took in Ubuntu 9.04 here. [&#8230;]