VirtualBox Bridged Networking

If you've been using VirtualBox for a while, you've probably been scratching your head wondering how you can give two virtual machines the ability to communicate. The easiest way to do this is to configure bridged networking. In this tutorial, we are going to configure and test two CentOS 5.5 guests and a Windows 7 host. We also assume you already have guest additions installed.

Make sure your virtual machines are shutdown, then click "Settings." Select "Network" from the list on the left. This will bring up the guest machine's network settings. As you can see, VirtualBox allows a lot of network flexibility, with support for up four adapters and four different networking modes. Click the dropdown box labeled "Attached to" and change it to "Bridged Adapter" like so:

Now we must make sure that we select the proper network adapter that our host is using. On my laptop, I have two adapters, a physical adapter and a wireless one. Since I am connected to my network wirelessly, I need to select my wireless adapter. Click the dropdown box labeled "Name" and select the appropriate adapter that you are connecting with:

After clicking "OK," modify the other virtual machines on the network in the same manner. Start them both.

Bridged networking does a bit of voodoo to retrieve multiple IP addresses from your router with the same adapter card. If you login to your router after your guest OSes are connected, you should notice that there are multiple IP addresses for the same MAC address in your router.

Let's test that everything is working. First, verify that your host can connect to the internet. If that is working properly, and it should be (you are reading this), the next step is to verify internet connectivity on each guest machine. Open up a terminal, and ping google. If everything went okay, you should get something like this:

[matt@localhost ~]$ ping -c 3 google.com
PING google.com (209.85.225.106) 56(84) bytes of data.
64 bytes from iy-in-f106.1e100.net (209.85.225.106): icmp_seq=1 ttl=52 time=83.4 ms
64 bytes from iy-in-f106.1e100.net (209.85.225.106): icmp_seq=2 ttl=52 time=82.3 ms
64 bytes from iy-in-f106.1e100.net (209.85.225.106): icmp_seq=3 ttl=52 time=82.9 ms

--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 82.397/82.942/83.443/0.428 ms

The important thing is at the bottom: all packets that were transmitted were recieved.

Next, let's verify connectivity between the the host and each guest, and in between our two guests. To do this, we need to get the ip addresses for each machine. First, lets get the Windows host's ip address. Open up a command promt by going to "Start" and typing "cmd" into the search box. Now run ipconfig:

C:\Users\Matt>ipconfig

The should produce a fairly decent amount of output. The line we are interested in is near the top, the first IPv4 Address:

IPv4 Address. . . . . . . . . . . : 192.168.1.60

Write this number down.

Now, let's move onto each guest. In linux, the command to get the computer's ip address is ifconfig, and it must be run as root. If you have sudoers configured, and have added /sbin to your path, open up a terminal and type the following:

sudo ifconfig

The line we are looking for is also near the top, listed under our network adapter, which should be eth0. Specifically, we are looking for the second line:

inet addr:192.168.1.114  Bcast:192.168.1.255  Mask:255.255.255.0

The first number in this line is our ip address. Write this down, and do this for each guest. My ip addresses are the following:

Machine IP address
Windows Host 192.168.1.60
CentOS Guest #1 192.168.1.114
CentOS Guest #2 192.168.1.111

To verify that I can connect to each guest from my host, I just ping them from my Windows command prompt. The Windows and linux ping commands are different, yet similar. For Windows, there's no need to specify a number of packets to send. Let's ping both guests now:

As you can see, I can reach both guests from my Windows host just fine.

Next, we'll ping the host and other guest from each guest:


(Click for full size image)

Again, no errors-- everything appears to be working fine. Now we can move onto more interesting things, like using ssh and configuring various servers.

blog comments powered by Disqus  -  Home