How to connect to VirtualBox on the network

Sometimes I experiment on virtual machines with Linux Ubuntu Server and in order to be able to connect to them by IP address, open VirtualBox, select the desired machine, open “Configure” – “Network” and see that in the “Adapter 1″ tab there is a standard tick on ” Enable network adapter “and” Connection type: NAT “is selected. It is necessary for the Internet to work on the virtual machine.
You can change to “Network Bridge” and the virtual machine will try to get IP in the same network as the physical computer, for example from a router, and will also be visible on the network.

Either we leave the first adapter as it is and go to the tab “Adapter 2”, tick off “Enable network adapter” and select “Connection type: Virtual host adapter”. Click “OK” and start the virtual machine.

We will enable the second network adapter on the virtual machine, as well as the DHCP client, so that it will automatically receive the network settings (IP address), then we will connect to it later.
On Linux, the second network adapter is configured in the configuration file /etc/network/interfaces, to which we add for example the following:

auto eth1
iface eth1 inet dhcp

And update the IP:

sudo dhclient eth1

Let’s see the received IP:

ifconfig
ip a

Done.

If you need to test some kind of billing, DHCP server, etc., then you can add two network adapters on one virtual machine, the first is “Network Bridge” (for example, you can connect to the virtual machine via SSH for example), and the second adapter is “Internal network”, on the second virtual machine we will configure only one network adapter “Internal network”, as a result we will have an internal network between both machines in which they will only see each other.

See also my article:
Configuring the Network in Linux

Leave a comment

Leave a Reply