Table of Contents
If you have a travelling person who need to work with virtual server in VirtualBox, you’d probably have issues with setting IPs for your virtual machine.
If you set IP for your virtual machines using the bridge network, the IP of your VMs will change every time you switch the network you connect to.
This is a huge issue if you need to ssh to such servers.
If you use the Host Only network option, you may not be able to connect to the internet from the VMs.
If you enable both bridge network and Host only network interfaces, chances are you don’t have IP v4 for the host only interface.
This post will help you setup IP v4 on host only network so you can have a static, permanent IP address for your VMs so you don’t need to look up for that every time you change the network you connect to.
Let’s get started.
First step: Enable bridge and host only network interfaces
To be able to connect to the internet, you need to have the bridge network. To have an independent IP, you need to have another network interfaces enabled. In this case, I choose the host only network interface:
Configure IPv4 for the host only network interface
By default, the host only network interface is down:
As you can see, the interface is down by default. Let’s enable that interface by using this command:
sudo ifconfig enp0s8 up
enp0s8 is the interface of the host only network. How do you know this? well, before you enable the interface, you didn’t see this. Now you see this. That means it’s the host only network interface.
Enable IPv4 for the host only network interface
You are not done yet. Let’s create (if none exists) or edit an yaml file under /etc/netplan:
network: ethernets: enp0s3: dhcp4: true enp0s8: #add this dhcp4: true # and this version: 2
As you may see, there could be some existing config for the default interface (enp0s3). Let’s add two lines as commented for our new interface.
Save the file and exit.
Now let’s apply the settings by using this command;
sudo netplan apply
Now, if you type
ip a, you will see the interface has IPv4:
You can now ssh from the host OS to the VM using the IP from the host only network interface. That IP is not changed when you switch your Wifi/cable network. Better yet, you still can connect to internet from your VM. If you want to set a static IP for that interface, you can follow the instructions here.
In this post, I’ve shown you how to enable host only network with IPv4 so you don’t have to update the IP of your VM when you connect to it from the host OS.