VirtualBox Introduction



To setup your VM, please do the following steps (all described below).

  1. Get familiar with the VirtualBox Documentation
  2. On your laptop, install the VM and then the Linux Distro (Ubuntu 16.04.3 LTS), and then additional software
  3. Setup networking

The last section of this page contains a list of potentially helpful items.

1 VirtualBox Documentation

 

2 Installing a VM on VirtualBox 

Step 1. Install VirtualBox

Please follow the instructions from VirtualBox.

Step 2. Create a VM and install Linux Ubuntu

 

Step 3. Install the "Guest Addtions" - which adds optimized drivers to your Linux installation.

Step 4. Tweak your VM settings to enable these useful features::

 

Step 5. Packages to install after a installing a Ubuntu VM

After a fresh install of Ubuntu, you should do a 'sudo apt-get update'. Then issue 'sudo apt-get install xxx' the following (note that some of these might already be on your system).. To see all installed, 'apt-cache pkgnames', To see if a specific pkg is installed, like iperf, 'apt-cache showpkg iperf', And if you know the program you want to get but it is different from the package name, you can try 'apt-cache showpkg iperf'.

The following are optionally

Step 6. Download the example code

The simplest method is, from your VM, cd to a working directory. Then use git to download a set of bash/cCode/python/matlab code.

3 Setup Networking on the VM

This section provides details on the default virtual environment setup with VirtualBox with ubuntu 16.04 running as a Guest. From a TCP/IP perspective, we refer to the Guest as VM1 and the TCP/IP host that represents VirtualBox's Host and VMM as the Host. Any number of VMs can be created, with 1 or more virtual networks. We then present a section describing several network options for a single VM scenario. An additional subsection talks about networking options for a scenario involving 2 VMs.

First, let's identify several important concepts and Linux commands.

 

Next, let's look at the types of networks that are possible in a VirtualBox VM system.

 

 

These various choices of networks allows VirtualBox to support VMs that are happy being 1)disconnected from any external network; 2)secure outside-to-inside access with NAT; 3)unsolicited outside-to-inside access with Bridge networking; 4)more restrictive unsolicited outside-to-inside access with NAT and port forwarding.

Additional items to keep in mind:

 

We present two specific VM configuration environments. The first involves a single VM. The second involves multiple VMs. In the discussion we use the following network and supporting terms

Network--L1----Host OS --Link2-L2--VM1 ----L3----VM2

Figure 1- Network Diagram

The Host OS is your laptop running VirtualBox. It has WiFi and Ethernet connectivity (L1 for Link 1 in the Figure) to external public networks.

Link2 corresponds to the virtual network that is set up by one of the following Scenarios.

 

 

Scenario 1 - one VM

In this scenario, VM2 and L3 (from Figure 1) do not exist. The objective is to provide VM1 with Internet access. There are two options: the default NAT and bridge mode.

Option 1: NAT

L1 is the link from Host to the outside (campus wifi ) and L2 is the virtual network where the details can vary depending on how we configure the VM. Our starting point is to have L2 be a simple ethernet link as seen by VM1.The simplest approach is to use the default setup of NAT. By default, VirtualBox sets the the default network setup for VM1 will be 'NAT' (Note.....not NATNetwork). See Section 6.2 of the Manual.

Network--L1----Host--Link2-L2--VM1

By default, the Host OS VM facing NIC will be assigned an IP address of 10.0.2.2, although you won't see this IP if you issue ifconfig at the HostOS. The VM (in all VMs ) are assigned 10.0.2.15.

To allow outside to inside access, port forwarding is used.

It is very easy to use port forwarding with NAT.Issue the following from your Host OS. The first allows ssh access to your VM from a machine on the campus network.

Option 2: Bridge Mode

Modify the VM machine configuration to use Bridge Mode for the type of network on the interface that will be used to provide connectivity to the outside world. Modify the VM (actually this would be the default settings in the VM OS) to used DHCP to obtain its IP information. When the VM boots it interacts with a DHCP server that should be in operation in the outside network. For a campus environment, the VM is allocated an IP address in the same way as the Host OS's interface to the campus network. The address will be different than that allocated to the Host OS. The campus wifi network (eduroam) is a bit problematic- you might need to connect your laptop to a campus ethernet. The easiest to get working is usually in your home environment where you have control over the WiFi AP.

 

Scenario 2 - Two VMs

This scenario

Network ----Host -----VM1----VM2

We idenfity the following assumptions for this scenario:

We describe the setup in the following four steps.

Step 1: VM1 to Internet with NAT network

This is the 'one VM' setup described above.

Internet ----host os ------'hard wired link'---- VM1

------------ ....10.0.2.2 .................................10.0.2.15

VirtualBox setups up a 'hard wired link' allowing a VM (any number) to communicate through the Host using NAT. Don't be alarmed when you see all VMs are assigned an IP address of the same.

The VM will show a NAT network (Settings --- Networks ). Click Advanced and it will show the MAC address. VirtualBox uses a somewhat strange network scenario-it assigns all VMs to use NAT with an IP of 10.0.2.15.

To complete step 1, validate the network is as expected by:

Explanation: Host OS is performing NAT on behalf of flows intiated by VM1. Let's say our Host OS has an IP of 172.23.0.1. When VM1 issues a ping to a machine like netlab.cs.clemson.edu, the netlab host will think its interacting with a host with a source IP of the Host OS's IP address to the outside world.....when really the source is VM1!!

Step 2. Setup Host only Network or an internal network between VMs

Next, let's add VM2 and connect VM1-VM2 using a private network

Internet ----host os ------'hard wire'---- VM1 ----- private 192.168.1/24 ---- VM2

Turn off all VMs. In VirtualBox Manager, File --- Preferences---Network create a Host only network. Double click...and we see the default address of 192.168.56.1. I suggest turning DHCP OFF.

Or....instead of Host only, create an internal network.

Go to VM1 settings --- Network --- And should see Adapter 1 and Adapter 2 (NAT and Host Only). Double check in your VM, select Devices --- Network --- Settings : you should see Adapter 1 and 2.

Next, we need to configure Linux to use the second adapter. Got to Linux System Settings and Network. You should see 2 wired adapters: The interface for connecting to the outside world - it likely shows 10.0.2.15 for the IP, subnet of 255.255.255.0 and GW of 10.0.2.2. . Make sure to use DHCP for the Method (addressing). This setting will cause the IP host to include just one default route in the route table (check with 'netstat -rn' or 'ip route show' ).

The other interface, select Manual, Add a new entry to specify an IP of 192.168.2.1, subnet of 255.255.255.0 but Don't specify a GW! Go to routes, and select the button that says 'Use this connection only for resources on its network.' This is necessary to ensure that only 1 default route is set up.

To double check, on a terminal on VM1, issue ifconfig. You should now see both adapters with the IP addresses (10.0.2.15 and 192.168.2.1).

Note that the 'internal network' is even easier- no need to create a Host only network in Preferences....in fact you might need to remove any Host only networks defined that you are not using.

Step 3. Complete VM2 setup.

------------VM1-----------VM2

....................192.168.2.1 ----192.168.2.100

(Note: you can use any network addressing scheme you like....does not HAVE to be 192...Any private addresses will work. )

 

While powered off, go to settings and Network and disable (deselect) the NAT network adapter (in my case it is Adapter 1). But Adapter 2 should still indicate 'enable' and Host Only.

Start VM2. Issue an ifconfig. Repeat the steps above when we configured VM1's Linux Network Manager to use the Host Only adapter, assign a static IP 192.168.2.100. Make the default router be VM1's 192.168. address.

From VM2, you should be able to ping 192.168. but nothing beyond VM1. So a ping google.com will fail.

Step 4. Configure VM1 to serve as a NAT router

This is the magic step...setting up VM1 to allow VM2 to connect with the outside world. If successful, the IP addresses are as shown below. NAT is in affect at two locations:

Outside Network ---HostOS-------------VM1-----------VM2

........................................10.0.2.2 .....10.0.2.15 192.168.2.1 ------ 192.168.2.100

 

 

Our Host OS continues to operate NAT for all traffic initiated by our VMs. Additionally, VM1 operates NAT on behalf of traffic initiated by VM2.

 

 

Additional VirtualBox Items

Pointers to additional Ubuntu documentation that might be helpful

Here are a few items that are helpful

 

10/25/2017