Networking Tutorial

Everything which doesn't fit into the other sections.

Networking Tutorial

Postby mschwartz » 16. Jun 2011, 15:14

This tutorial will show you how to set up networking for your VirtualBox VM and your host. If you follow these steps, you will be able to access your guest from your host using a WWW browser or ssh client (or whatever), your guest will have Internet access. There's an optional step at the end that will make your VM accessible from all machines on your network as well.

For windows host and linux guest, I typically set up the guest to have 2x network interfaces. In the vbox GUI, the 1st interface is set to NAT, and the 2nd is set to HOST ONLY.

This gives Ubuntu guest eth0 and eth1.

In /etc/network/interfaces, I add:
Code: Select all   Expand viewCollapse view
auto eth1
iface eth1 inet static
address 192.168.56.10
netmask 255.255.255.0


On my windows host, I add to c:\windows\system32\drivers\etc\hosts file:
Code: Select all   Expand viewCollapse view
192.168.56.10 ubuntu


The guest uses NAT interface (eth0) to access the internet. The guest and host communicate over eth1, host only.

This also works great if you have a laptop and take it to starbucks and use their wifi. Your guest ubuntu uses the NAT interface to access the internet over their WiFi. You still use the host only network to communicate guest <-> host at starbucks. That is, no matter where you take your laptop (like the Oracle Cafeteria!), you can communicate host <-> guest, and both host and guest can access the internet.

ADDITIONAL STEP - NOT REQUIRED

Additionally, if you have two machines or more on your home/office lan and you want to access the guest Ubuntu from a different machine altogether, you add a 3rd interface (eth2) which is BRIDGED networking. On my home lan, my wifi router uses network addresses 192.168.1.x, so I configure eth2 in the guest:
Code: Select all   Expand viewCollapse view
auto eth2
iface eth2 inet static
address 192.168.1.10
netmask 255.255.255.0


Now other machines on the LAN can access the guest at 192.168.1.10. I set up hosts file on those computers:
Code: Select all   Expand viewCollapse view
192.168.1.10 ubuntu


NOTES

A bit more about the .10 address. For HOST ONLY, I see my host OS has an interface set up by vbox installer with IP of 192.168.56.1. If you set up host only networking and use iface eth1 inet dhcp, then the guest will set up eth1 via DHCP but talking to the built in DHCP server in vbox! Thus it will get an IP from 192.168.56.100 or greater than .100. Thus any IP 192.168.56.2 through 192.168.56.99 are safe to use as static. Similarly, my router comes default configuration to do DHCP for all the host-type computers on my LAN for 192.168.1.100 or greater than .100. Thus the same .2 through .99 type range is safe to use for static IP. I mean, I chose .10 because it's in this safe range, you can choose any number that you want.

I think it's a good idea to arrange blocks of the available IP addresses for specific purposes. For example:

.10 through .19 for your physical machines (hosts).
.20 through .29 for your VMs
.2 through .9 for any network printers or other devices
etc.

If you set up eth0 and eth1 as I described earlier, you should be able to ping in both directions. From guest, try:
Code: Select all   Expand viewCollapse view
ping 192.168.56.1


From the host (in cmd.exe or cygwin) try:
Code: Select all   Expand viewCollapse view
ping 192.168.56.10


On both the vbox 192.168.56.x network and my wifi 192.168.56.x network, the .x = .1 is reserved/in use. As I mentioned already, 192.168.56.1 is the HOST IP for the host only network. 192.168.1.1 is the IP of my wifi router itself.

BRIDGED NETWORKING

I use bridged networking for my Ubuntu VMs on my office LAN. The VMs only have one network interface, eth0, and in the vbox GUI it is set up as BRIDGED.

In Ubuntu, my /etc/network/interfaces file looks like this:
Code: Select all   Expand viewCollapse view
auto eth0
iface eth0 inet dhcp


When the VM boots, it sends packets through my host (windows 7) physical ethernet adapter but with it's own MAC address. The DHCP server administered by our IT guy assigns a static IP on the office LAN to the VM because it's configured to do so for the VM's MAC address. The IT guy set up DNS so this static IP has a friendly name so anyone on the LAN can hit the WWW server running in the VM, etc.

The same strategies work no matter what host and guest OS you choose.
Last edited by mschwartz on 22. Jul 2011, 15:18, edited 1 time in total.
mschwartz
 
Posts: 92
Joined: 18. Oct 2010, 21:01
Primary OS: MS Windows 7
VBox Version: PUEL
Guest OSses: ubuntu

Return to Generic Advice

Who is online

Users browsing this forum: No registered users and 2 guests