DEV Community

Sei_O
Sei_O

Posted on

Network Configuration for Oracle VirtualBox

Introduction

This article intended for my homelab, how to ensure network in Oracle VM VirtualBox. The reason of worte the article, I want to note a step by steps configuration and I hope someone who reads this article to help your learning.

Oracle VirtualBox is a useful virtual machine sandbox for work and testing several purposes. Depending on the work and testing purposes, we need to consider the network between VMs and HostOS. Because if you are using Bridge Adapter to connect to Internet or HostOS it could also be seen on Local Area Network.


Network Settings and Overview

NAT

  • Connect to the outside via the host PC's NIC
  • Separate network for each virtual machine
  • Virtual machines are not visible from the host PC but are accessible via port forwarding

NAT Network

  • Unlike NAT, which operates on a per-virtual-machine network basis, this setup allows multiple virtual machines to belong to the same network and access each other.
  • However, port forwarding is still required for access from the host PC.

Bridged Adapter

  • Joins the LAN to which the host PC belongs via the host PC's NIC.
  • Allows access to the virtual machine not only from the host PC but also from other PCs on the LAN.

Host-Only Adapter

  • Does not connect to the host PC's NIC; external connectivity is not possible.
  • Establishes a network using the virtual machine and a virtual NIC, allowing mutual access between the virtual machine and the host PC via the virtual NIC.

Internal Network

  • Establishes a network exclusively between virtual machines.
  • No DHCP service is available, so settings such as IP addresses must be configured individually.

Cloud Network

  • Can connect to Oracle Cloud Infrastructure (OCI), access its resources, and manage VMs in the cloud.

Why avoid Bridged Adapter

The Bridged Adapter works by secondary network segment directly to your physical network.


Figure 1. Architecture Network Diagram of Bridged Mode

You can use the Bridged Adapter for accessing the internet, but it's still reachable by another PC on internal network (Normally a packet that send by another PC to VM will denied by firewall of the HostOS).

Of course, you can use the Bridged Adapter when exposing the VM to external and that requires you to ensure that the firewall is secured.


The Reason for the Coexistence of NAT and Host-Only Adapter

Best practice of the network configuration is combined NAT/NAT Network and Host-Only Adapter.


Figure 2. Architecture Network Diagram of NAT and Host-Only Adpater

By using NAT, VirtualBox built-in DHCP server does automatically assign an IP address, a Default Gateway and a DNS server to the VM. However, the GuestOS and HostOS still cannot communicate with each other that menas you cannot accessing SSH via WSL2, Visual Studio Code, Teraterm etc. The Host-Only Adapter can solve this problem by assigning a static IP address to the VM.

Additionally, this network configuration might be good practiced to work a mini-cluster homelab Kubeadm (A low-level tool built to bootstrap minimum viable Kubernetes) on VirtualBox.

Installation of NAT and Host-Only Adapter

Firstly, You need to create both NAT and Host-Only Adapter in installation of VirtualBox before modify the network settings in the GuestOS.

Select "Network tab" (1) then click "Create" (2) in Host-only Networks tab to add a new VirtualBox Host-Only Adapter there you will receive a manually assigned IPv4 address 192.168.x.1 and IPv4 Network Mask 255.255.255.0 in the adapter (3), see the figure below


Figure 3. Network Tab in VirtualBox

If you want to use a dynamically assigned IP Address, select the DHCP Server tab next to the Adapter tab then check a box to be enabled that.

Figure 4. DHCP Server Tab in Host-Only Adapter

Secondly, Move to the target VM and select the Network tab, then change a NIC type to NAT (Normally, the NIC is automatically selected by default settings). Next, switch to the Adapter 2, check the box to be enabled NIC. Select the Host-Only Adapter and a specified Ethernet Adapter that you created Host-Only Adapter Ethernet Adapter in first steps.

Figure 5. Network Settings in the VM

Assign IP address for the GuestOS is it can use nmtui, nmcli or other tools for the network configuration.

The following exempeles uses modify the network settings.

For nmcli:

nmcli connection modify {Connection Name} ipv4.method manual ipv.4addresses {IP Address} ipv4.gateway {Gateway}

#Opt. Create Ethernet Connection if the GuestOS is not allocated Ethernet in the network settings.
nmcli connection add type Ethernet con-name enp0s8 ifname "*" 802-3-ethernet.mac-address {MAC Address}
Enter fullscreen mode Exit fullscreen mode

The MAC Address can be found in the VM's Network Settings in Oracle VirtualBox, see the Figure 5

For nmtui:

nmtui
Enter fullscreen mode Exit fullscreen mode

Open the terminal and enter nmtui then select the Edit a connection to configure network. In addition, you can create a new adapter in nmtui. It's more easily to create the adapter than using nmcli.

Figure 6. Edit Connection Screen in nmtui

Assign IP Address, Gateway, then restart nmcli Connection.

nmcli connection down enp0s8
nmcli connection up enp0s8

#View your Network Configuration
ip addr
Enter fullscreen mode Exit fullscreen mode

The below figure shows results for the IP Address and Ethernet after modified the GuestOS's Network Configuration.


Figure 7. Reslut of ip Command in the GuestOS RHEL10

Try remote access via SSH with Teraterm, VScode or other Open-source terminal emulator program, then you can see it works.

Top comments (0)