Setting up a NAT network in VirtualBox 5
During the past years i used Parallels Desktop for virtualizing my Oracle development environments. I chose Parallels at that time because it performed better on my old memory constrained Macbook. Recently i had to upgrade to Parallels Desktop 11 and determined that Parallels silently removed quite some functions which were present in the previous versions. One of those functions is the Advanced Networking tool which supports the creation of virtual networks. These functions are still available, but only in the Pro version. So it was time to decide to take a yearly subscription to Parallels Pro or try to setup the same virtual network structure in VirtualBox 5.
The Parallels configuration i used had a virtual network for my guest hosts which had a NAT connection to network interfaces on my host. In this same virtual network my host also could participate. The VirtualBox 5 documentation is quite sketchy on setting up a NAT network, and the resources on this subject are limited. Therefore i took me some time to figure out that in a VirtualBox NAT network with network address 10.0.0.0/8 the gateway was on 10.0.0.2 and the DNS server on 10.0.0.1. In a VirtualBox NAT network the host does not participate, and therefore it cannot reach the guests. To be able to access the guests from my host, as used to with Parallels, i had to create second host-only network. All brought together i came up with the following virtual network configuration.
I chose different private network addresses for the Virtual NAT and the host-only network. I have tried to setup both networks using different subnets on 10.0.0.0 but was not able get this working properly. Guests connected to the NAT network (10.0.0.0/8) do participate in the same network. The guests also can connect to the external network (accessing the internet) through the NAT connection using the hosts physical network adapter. If a guest is connected to the host-only network (172.16.0.0/12) it can connect to the host and vice versa. The host is connected to the host-only address and assigned ip-address 172.16.0.1.
Both networks have a DHCP-server to distribute network configuration parameters.
Not all VirtualBox network configuration settings can be configured from the VirtualBox application. Therefore the following VBoxManage instructions can be used to create the network, interface and DHCP-servers.
# create NatNetwork VBoxManage natnetwork add --netname NatNetwork --network "10.0.0.0/8" --enable --dhcp on # add dhcp server to the NatNetwork VBoxManage dhcpserver add --netname NatNetwork --ip 10.0.0.3 --lowerip 10.10.0.1 --upperip 10.10.0.254 --netmask 255.0.0.0 VBoxManage dhcpserver modify --netname NatNetwork --enable # create hostonly interface VBoxManage hostonlyif create VBoxManage hostonlyif ipconfig vboxnet0 --ip 172.16.0.1 --netmask 255.240.0.0 # add dhcp server to the hostonly interface VBoxManage dhcpserver add --ifname vboxnet0 --ip 172.16.0.3 --lowerip 172.16.10.1 --upperip 172.16.10.254 --netmask 255.240.0.0 VBoxManage dhcpserver modify --ifname vboxnet0 --enable
When the instructions have been completed successfully the configuration can be viewed from the VirtualBox application. Go to Preferences > Network to open the network configuration panels.
To configure guests-hosts to use the NAT Network and Host-only adapter, open the settings panel for the guest-vm and select the Network tab. Attach Adapter 1 to NAT Network NatNetwork.
And attach Adapter 2 to the Host-only Adapter vboxnet0.
Good-bye Parallels, hello VirtualBox !