Introduction
In this article, we will discuss how to set up a firewall and configure networking on Ubuntu 20.04 using VirtualBox. This guide assumes you have some experience with firewalls and networking, and you want to create a small virtual network with two Ubuntu machines: PC1 (running Ubuntu as a host operating system) and PC2 (running as a virtual machine). The goal is to provide PC2 with internet access from PC1.
Installing VirtualBox
First, you need to install VirtualBox on your Ubuntu host (PC1). You can download the VirtualBox Debian package from the official Oracle website:
sudo add-apt-repository ppa:virtualbox/virtualbox-6.1
sudo apt update
sudo apt install virtualbox-6.1
Configuring PC1 (Ubuntu Host)
Step 1: Installing and Configuring Ubuntu
Install Ubuntu on PC1 and ensure it is configured with a static IP address, for example, 192.168.1.1.
Step 2: Installing and Configuring Firewall (UFW)
Ubuntu comes with a default firewall named Uncomplicated Firewall (UFW). Install and configure it:
sudo apt install ufw
sudo ufw default deny incoming,outgoing
sudo ufw default allow ssh
sudo ufw enable
Creating a Virtual Machine (PC2)
Create a new virtual machine in VirtualBox with the following settings:
- Type: Linux
- Version: Ubuntu (64-bit)
- Memory size: 512 MB
- Hard disk: Create a new virtual hard disk (VDI)
Configuring PC2 (Virtual Machine)
Step 1: Installing Ubuntu
Install Ubuntu on PC2 and ensure it is configured with a static IP address, for example, 192.168.1.2.
Step 2: Installing and Configuring Firewall (UFW)
Install and configure UFW on PC2:
sudo apt install ufw
sudo ufw default deny incoming,outgoing
sudo ufw allow ssh from 192.168.1.1
sudo ufw enable
Configuring Networking
Configure the network adapter on PC1 to act as a NAT (Network Address Translation) gateway:
sudo nano /etc/network/interfaces
# Add the following lines at the end of the file:
auto eth0
iface eth0 inet static
address 192.168.1.1
eth0:forwarding=yes
eth0:nat=1
eth0:portmap 80 192.168.1.2 80
eth0:portmap 443 192.168.1.2 443
Testing the Setup
Check if PC2 can access the internet through PC1:
sudo ufw status
# Ensure the following rules are present:
# IN: 80, 443 ALLOW IN 192.168.1.1
# OUT: 80, 443 ALLOW OUT 192.168.1.1
Summary
In this article, we learned how to set up a firewall and configure networking on Ubuntu 20.04 using VirtualBox. We created a small virtual network with two Ubuntu machines, PC1 and PC2, and provided PC2 with internet access from PC1.