For quite some time now Zabbix has been offering a virtual appliance for those who would like to try it out or have a simple deployment for a small environment. Among other virtualisation solutions, users also run it on VirtualBox. But, when using NAT in VirtualBox, the host of the virtual machine cannot connect to the appliance directly. Let’s explore how this can be solved.
Accessing VirtualBox machine in NAT mode from the host
There are several approaches to how a virtual appliance could access the network with VirtualBox, one being NAT. It allows the virtual machine to use the host network without actually obtaining an external IP address. Note that if you are using the bridged mode, the following instructions are not needed for you – networking should fully work without extra interfaces.
The problem is that in the NAT mode the host machine – the one where the virtual appliance is running – cannot connect to the appliance. This can be quite inconvenient if one would like to run Zabbix appliance locally, allow it to connect to the internet over NAT and still access it from the local system.
The solution is to add another network adapter in host-only mode. But before we can do that, we also have to add a host-only network…
Adding a host-only network
Before we can add host-only adapters, we have to add a host-only network. To do so, open File -> Preferences in VirtualBox and switch to Network in the left hand side menu. Click on the small icon, resembling a network adapter with a green “+” sign on the right hand side. That should add a network named vboxnet0.
Adding a host-only adapter
The NAT adapter will allow the virtual machine to connect to the internet using the host’s network, but the host will not be able to access that interface on the virtual machine. We will add another interface, which will be used for communication with the host only. To do so, open virtual machine properties while it is stopped and switch to Network in the left hand side menu. Make sure that Adapter 1 is enabled and attached to NAT.
Switch over to Adapter 2, enable it and set it to be attached to Host-only adapter.
With that done, click OK and start up the virtual machine. One might think that this should be enough, but that’s not the case…
Getting address for the new host-only interface
Running either ifconfig -a or ip addr we can observe that eth0 interface is started up and has IP address assigned, but eth1 – the interface we just added as host-only – is not. To obtain address for it, run dhcpcd eth1. If you would check the interface status again, it should have an IP address listed. Note that address down and try to connect to it from the host system – that should be successful now.
Making the configuration permanent
While it will work nicely for now, once you would restart the virtual machine, it would not obtain the IP address for the eth1 iterface – you would have to run dhcpcd eth1 every time it is started up. That’s not too convenient, so we should just tell the appliance to retrieve the address automatically. It’s pretty easy to do – just run the following:
# cp /etc/sysconfig/network/ifcfg-eth0 /etc/sysconfig/network/ifcfg-eth1
This will tell the appliance to use the same configuration for eth1 as for eth0 – that is, start it up automatically and obtain IP address from DHCP.
Now we’re done, and the virtual machine should be able to use NAT in VirtualBox, while still being accessible for the host system – albeit on a different address.