How to build a virtual machine network

  • by

A good way to test a computer system before you physically install it on a machine, is to turn to virtualization or: running a virtual instance of a system on an existing system.  A well known tool to do this is Oracle VM VirtualBox. We can also use VirtualBox to install several instances of a virtual machine and connect them in a virtual machine network to test a complete network before deploying it.

I show this using CentOS 8 and VirtualBox 6.

In this post I explain how to create a base virtual machine and prepare it for later network connectivity.

Part One: install VirtualBox

Firstly, download and verify the CentOS and VirtualBox packages (tip: read my blog post on how to verify software integrity).

I assume you are comfortable with installing software on your existing system.

Fig 1:

Part Two: create a base virtual machine

Secondly, open VirtualBox, create a new virtual machine (VM) and prepare your VM for network connectivity.

Create a new virtual machine

To do this, choose “Machine” and “New…” in the VirtualBox menu.

Give your VM a name (I used “CentOS_baseVM”), choose “Linux” as “Type” and “Red Hat (64-bit)” as “Version”.  VirtualBox will automatically add a folder called “VirtualBox VMs” to your home folder. You can change the name and location of this folder if you like but I suggest keeping the default location.

Fig 2:

Also keep the default settings under “Memory size” and “Hard disk”.  After you click “Create”, VirtualBox will create a VM with 1024 MB RAM and a virtual hard disk.

In the next window, you can change the hard disk size.  The recommended disk space for CentOS 8 is 20 GB.  Keep the remaining settings to their default and click “Create”.  VirtualBox will create a virtual hard disk (with a filename ending in .vdi) in the previously chosen location.

Fig 3:

Adjust network settings

In the VirtualBox main window and with your VM “CentOS_baseVM” selected, click on “Settings” to make some additional modifications before you start your VM.

In “System”, click the “Processor” tab and change the number of processors from 1 to 2 to speed up your VM.

Fig 4:

Next, in “Network”, select the “Adapter 1” tab.

Set the “Attached to:” network adapter setting to “NAT” to use your existing internet connection on your VM. Still in the same window, open the “Advanced” section and make sure to select the “Cable Connected” option.

Fig 5:

Next, select the “Adapter 2” to “Adapter 4” tabs.

In each tab, select the option “Enable Network Adapter”. In the “Attached to:” dropdown menu, select “Internal Network”. Give each adapter a name (I used “intnet02” for “Adapter 2”, “intnet03” for “Adapter 3” and “intnet04” for “Adapter 4”).  Also, make sure that in each “Advanced” section, the option “Cable Connected” is selected and that every adapter has a different MAC Address.

Fig 6:

Click “Ok”.

You are now ready to install CentOS on your base VM.

Part Three: install CentOS on the base VM

In the VirtualBox main window, select “CentOS_baseVM” and click “Start”.

Your new VM will start but doesn’t yet have an operating system installed.  So VirtualBox will ask you for an installation disk.  Choose the CentOS disk image (.iso) you previously downloaded (unless you changed your download preferences, the .iso probably sits in your “Downloads” folder).

Click “Choose”, then “Start”.

Now, you’ll probably end with a tiny, tiny window that you can barely read.  Go to the VirtualBox “View” menu and select the “Virtual Screen” option.  Choose “Scale to 200% (autoscaled output)”.  This size will do nicely for testing purposes.

Select your language

You’re now in the “CentOS Linux 8 Installation” window.  You can easily navigate through the menus using the arrow keys on your keyboard.

Fig 7:

In the first window, you have to select your language.  The language you choose here has an impact on your keyboard layout.  Since you’re installing a system in a virtual machine on a physical machine with a pre-existing keyboard layout, chances are that the CentOS keyboard layout will not match entirely with your machine.  This can be frustrating, especially on machines that have an AZERTY-keyboard layout, and will probably require some trial and error before you find a match.

Configure the installation destination

In the second window you’ll presented with several configuration options.

Fig 8:

Firstly, navigate to the “Installation Destination” option and click “Enter”.  Select the 20 GB hard drive you created in Part Two.  Select “Automatic” as your prefered “Storage Configuration” and then click “Done”.

Fig 9:

Secondly, navigate to the “Network & Host M(anager?)” option and click “Enter”.  A window shows the ethernet ports (“enp”) that are available on your VM.  Throw the Ethernet switch of the second port in the list (“enp0s3”) to “ON” (in fact “enp0s3” should the first one in the list, but the installer sorts port number 10 before port number 3, which can create confusion).  This will connect your VM to the internet.  You’ll notice that NAT (the built-in NAT-server of VirtualBox, that is) automatically provides your VM with a private IP address in the 10.0.2.0/24 range. The DNS-server IP addresses are the ones configured in your router’s DNS settings (usually your internet provider’s DNS servers, unless you changed them).  Click “Done”.

Fig 10:

Configure the installation source

Thirdly, and back in the main window, you’ll notice that the “Installation Source” option is now no longer marked with an orange/red sign.  Instead, the “Closest mirror” is automatically chosen as the installation source.  This again indicates that your VM is now connected to the internet.

Fig 11:

Lastly, the “Software Selection” option still has an orange/red sign underneath it, saying “Nothing selected”.   Navigate to this option and click “Enter”.  Select “Minimal Install”.  For testing purposes, a CentOS VM with basic functionality will do just fine.  You won’t have a GUI but instead lots of fun using the command line.  Click “Done”.

Fig 12:

Back in the main window, click “Begin Installation”.

Fig 13:

The installer will show a window with a progress bar.

Meanwhile, you have the option to create a root password.  No need to create a user, we’ll test network connectivity as “root” user.

Fig 14:

Fig 15:

Don’t click the “Reboot” button since the CentOS .iso is still in the virtual disk drive and you can’t remove it while the VM is running. So close the VM window and choose the “Power off the machine” option. Then remove de CentOS .iso from the virtual disk drive and reboot your VM.

Fig 16:

You now have a VM with CentOS installed.

Leave a Reply

Your email address will not be published. Required fields are marked *