This website is preserved for historical and scholarly reference and is no longer actively maintained.

VirtualBox Networking -




This page provides background on networking concepts applied in a virtual box network environment. We organize this page into two main sections. The first provides a brief background on networking in VBox.  The second describes the network setup that we require for our two VM environment.  The discussion walks you through three steps (referred to a scenarios).  You need to sucessfully  complete all three.  We provide a test after each scenario to ensure you correctly have setup the scenario.

 

1  Networking in VirtualBox

 

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.

 

 VirtualBox supports a number of virtualized networks:

 

 

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:

 

 

2   Network Scenarios

We present three specific VM configuration  steps that are required to support our 2 VM network setup.

  1. The first involves a single VM and is illustrated in Figure 1.
  2. The second extends the first scenario by allowing outside to inside access to VM1. This lets you ssh directly into your VM1 from a campus computer that has access to the campus network.
  3. The third scenario adds a second VM (which we  refer to as VM2).  VM2 can reach the Internet but the instructions will not allow direct outside to inside access to VM2. extends allows outside to inside access to VM1.


Figure 1 illustrates the network diagram that is applicable to steps 1 and 2.   In the discussion, we assume that the Host OS has a campus network connection that has been assigned the IP V4 address  130.127.10.10.
Note that the figure identifies a SoC Linux machine (ada8). When we say VM1 has 'outside to inside access',  we mean that, as an example, from ada8, you can ssh directly into VM1 (The Host OS / VMM is configured to port forward ssh to VM1).
The Net1 and Net2 in Figure 1 represent two networks involved.  Net1 is clemson's network - it could be a WiFi connection or a wired connection depending on what machine you are using for your Host OS, and how it connects to the campus network. 
Net 2 is a Virtual Box virtual network. After completing Step 1,  Net2 simply connects VM1 with  virtual NIC on the Host OS. Assuming we use the default NAT setup for VM1, Figure 1 shows the IP addresses that are involved.


       ada8.computing.clemson.edu---
                                                       |

Clemson Campus Network ----Net1 -|--- Host OS ---- Net2 -----VM1
                                                                     10.0.2.2               10.0.2.15

Figure 1- Network Diagram - single VM.

 

 

Step 1 - one VM, default NAT setup, only inside to outside access. So an external machine (like Koala5.cs.clemson.edu ) can not access the VM1.

By default, the Host OS serves as a NAT router on behalf of VM1. The Host OS's private (virtual) side network interace is asigned an IP address of 10.0.2.2

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.

The following is how virtual box setups up the virtual network.

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.

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 130.127.10.10. When VM1 issues a ping to a machine like koala5.cs.clemson.edu, the koala 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 Host is VM1!!

Hosts on campus can ping the Host OS at 130.127.10.10 (using our example). But the VM's can not be reached from the outside unless the connection is initiated by the VM (or we allow for Scenario 2 described below).

To complete the configuration, start VM1, assuming it it Ubuntu 16.04, select System Settings and Networks. Select the Wired network that has been assigned 10.0.2.15. If you are just doing Scenario1, you should just see 1 wired connection. If it has not been configured, specify options and IPV4. Set the Method to Automotic (DHCP) - the Host OS (and VirtualBox VMM) has a DHCP server running and will provide the required IP address, subnet/netmask and Gateway. You can set the button 'Require IPv4 Adressing for this connection to complete (probably not required....). Selet Routes and you should not see anything....make sure 'Use this Connection only for resources on its network is NOT clicked.

Step 2 - one VM but with outside to inside access

To allow outside to inside access, port forwarding can be used. We will forward packets from two applications: ssh (requriing a -p 5555 param to force it to use 5555), and a UDPEcho application running the server bound to port 5000 at VM1.

Question: Why require port 5555 when accessing VM1? This way, you can still access your Host OS using ssh (without specifying a port uses a default of 22).

Note: this will not allow direct access from the campus network to your VM2 Kali VM!!


There are two methods: port forwarding and bridge mode.

 

IMPORTANT...quick review of VboxManage - this is the command line interface available on your Host OS that allows you to do EVERTHING the GUI Virtual Box configuration allows (and actually much more).

 

Method 1 : Port forwarding (recommended)

The VboxManage modify command to 'poke a hole' (referred to as port forwarding) through the NAT/FW is '--natpf<1-N> [ <rulename>], tcp|udp, [<hostip>], <hostport>, [<guestIP>], <guestport>

The --natpf<1-N> ids the interface. In our simple HostOS---- 10.0.2/24 ----VM1---- internal network ---- VM2, there is only one Interface from VBoxManage perpsective....the 10.0.2.2 interface that is 'virtually created' by the VMM and is the link between the Host OS and VM1. Remember that for VM1, it's default router must be 10.0.2.2.

A modifyvm --natpf1 operation is required for each specific application your want to permit and forward to a VM application. .

Listing all PF rules does not seem to be available through VBoxManage. It is easy with the GUI however. In the VM, select Machine, Setings, network and port forwarding will list the PF rules. If you ever need to remove a rule, you need to do this procedure to get the rule ID number. Then on your Host OS, assuming we want to remove PF rule number "1234":: VboxManage modify "VM1" --natpf1 delete "1234"

 

To test, on your Host OS, oopen a terminal (or command line shell on windows), issue ifconfig (on Linux/MacOS) or ipconfig on Windows to learns the IP address assigned to your computers connection to the campus network. As an example, let's say this is 130.127. 10.10 and your VM1 user name is jjm. Then, ssh to a department Linux machine. From this machine, issue 'ssh -p 5555 jjm@130.127.10.10' and this allows your to login to your VM1.

You can also configure port forwarding using the VMM 's VM config panels.  Select the VM Machine config, and click on 'Port Forwarding'.  If you did a VBoxManage command you should see the entry in this config page.  To add a port forwarding rule,  click + and enter the information - it should be similar to what was discussed above.

Method 2: Bridge Mode

There is another method for allowing outside to inside access.... VirtualBox supports 'Bridge Mode'. This does NOT use NAT and should be used for a very different purpose: only if you want the VM to appear as it it is physically connected to the same external network used by the Host OS. The VM could then be setup to use DHCP and it would interact with the same DHCP server that your Host OS would use to get an IP address, subnetwork mask, first hop router, and DNS NS. One some versions of MAC OS, we've seen natpf NOT work correctly and Bridge mode was required. With recent VirtualBox versions....both modes appear stable on all Host OSs (Windows 10, Linux/Ubuntu, MACOS).

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.

Step 3 - Two VMs, VM1 accessible from the outside (see Scenario 2 above) and VM2 able to reach VM1 AND the Internet. This requires VM1 to act as the first hop router for VM2. This does NOT allow access from the campus network directly to VM2.

 

 

We will setup the private network as shown below. VM1 will have 2 adapters. VM2 will have one adapter. The VM1 and VM2 private network IPs will be 192.168.2.1 and 192.168.2.2 resp.

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

----130.127.x.x  -------------10.0.2.2---.10.0.2.15.............192.168.2.1 ---------------------192.168.2.2

 Figure 2- Network Diagram

We will setup the private network as shown below. VM1 will have 2 adapters. VM2 will have one adapter. The VM1 and VM2 private network IPs will be 192.168.2.1 and 192.168.2.2 resp.  VM1 serves as a Router.VM1 is our Ubuntu 16.04 VM,  VM2 is our Kali

 We assume the following

 

WARNING:

 

 

There are three steps to complete....and this assumes VM1 is setup correctly as in Scenario 2. This does not require any global network preferences changes in the VMM manager area of the VirtualBox VM Manager.


STEP 1: Setup the 192.168.2/24 network  interfaces on  each VM. VM1 requires a second network adapter. VM2 requires the type of network configured by default on adapter 1 is changed from NAT to 'internal network'.

We use the VirtualBox Machine Manager, go into network settings:

 

STEP2: Each Guest OS Linux network configuration needs to be set correctly - we use the network manager to do this.

 

STEP 3: Next, configure VM1 to serve as a NAT router to allow VM2 to reach the Internet.

We use the addresses and network interface names for our discussion.  following addresses for the VM1-VM2 network

............................................enp0s3 ...VM1 ..enp0s8.....eth0---VM2

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

.............................10.0.2.2 ......10.0.2.15    192.168.2.1 ------ 192.168.2.2


 

We have a script that can be used to help .... the script supports a number of configuration commands....but the command parameters 'NAT outboundIFName  privateIP' will do the two steps shown above:


 

 

 

last updated: 4/7/2019