Monday, August 3, 2015

Ubuntu on VirtualBox with Dual Network Interfaces

I needed to be able to reach the internet from a Ubuntu VM, and be able to get into it from my host machine, and I needed its IP address to be fixed.

I could not use the Bridged Adapter setting because the VM was going to be part of my work domain, and I found that if I shut it down for a while, or switched snapshots it would occasionally change its IP address.

A configuration that works for me is to make it have 2 adapters.

In VirtualBox Manager I went to:
File -> Preferences -> Network -> Host-only Networks
Verified there was an entry and set it up to have a DHCP server.

In my VM settings I set up so that network adapter 1 was host only, and 2 was NAT.

I then installed Ubuntu Server.

I told it to use the 2nd adapter for internet.

After it started I did:
vi /etc/network/interfaces
Which only showed:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth1
iface eth1 inet dhcp

So I tacked this onto the end of it:

auto eth0
iface eth0 inet dhcp

And then rebooted.

Now it can ping the host (Windows in my case), and the host can ping it, and I can ssh into it.

No comments:

Post a Comment