In this article I’ll show you how to set up a Linux running in VirtualBox to be able to access a service running on localhost on the host machine. I’ll use MySQL as an example, because that was the problem I faced with. The Linux OS of my choice is Ubuntu.

Testing the connection

First, let’s see how you can test if your virtual machine can access the service on the host. There is a great program called nmap for it. If it is not installed, you can install it with the following commands:

sudo apt-get update
sudo apt-get install nmap

Let’s suppose we have a web application that is trying to connect to the MySQL server on localhost:3306 by default. We would not like to change this configuration, but allow our virtual linux to connect to the MySQL server running on the host.