Virtualize Your Ubuntu Server Experience: A Hands-On Installation Guide
Linux systems are among the most widely used and scalable operating systems currently available. If you become skilled in using Linux, many career opportunities will open up. The most common Linux system is Ubuntu. In this article, I will show you how you can spin up your Ubuntu 22.04 server in Virtual Box.
Introduction
There are a few ways you can install your Ubuntu OS, the most common one is installing it on a hard drive. It can be good in terms of performance as Ubuntu will use all the resources available. However, it is highly likely that you may make some mistakes and need to re-install the OS. Plus you have to free up a lot of space to install the OS. If you already have some experience with Linux this may be the suitable way. But if you are a beginner, a more robust way is preferable. For that, you can create a server in the cloud. Services like Digitial Ocean or Linode let you create a Linux server with minimum resources for $5 - $6 per month. However, I will recommend creating your virtual machine. Both Ubuntu Server and VirtualBox are free to download. You will have all the controls over the server. You can connect two or more computers to the same network and create your own Cloud Native Environment.
Download Links
Creating Virtual Machine
By default, a virtual machine will have 2GB Ram, 1 CPU, and a NAT network adapter. If you have >= 12GB of Ram, you can assign 4GB. Setting the VM with 2 CPU processors is important. With more computing power, Ubuntu Server can handle requests faster. You can run a service in one terminal and run your commands in another without any issues. Most importantly, change your network adapter from NAT to Bridge. If you are not sure, you can check it on your machine. Open terminal, in Windows type ipconfig /all
and in Linux run ip addr
to see the network adapter. When you create a new virtual machine, VirtualBox will automatically create a virtual network adapter called "NAT" that allows the virtual machine to access the internet, but not the host machine or other machines on the same network as the host. By creating a bridge adapter, you can connect the virtual machine to the same network as the host machine, allowing it to communicate with other machines on the network as well as the host machine.
Selecting the right adapter is very important. If not done correctly, you cannot access your VM from your host or any other device in the same network.
Steps
Open virtual box manager
Click on new
Give a name to Virtual Machine
Ubuntu Server
Select the Ubuntu Server ISO image
Click
Next
Give username
ubuntu
Set a password
Set hostname
Ubuntu
Click
Next
Set Base Memory,
4096mb
Processors
2 CPU
Click
Next
Disk size
25 GB
Click
Next
Review Summary
Click
Finish
Close Virtual Machine. Need to setup network
Select
ubuntu Server
virtual machineClick on
Network
In Adapter 1, change to
Bridge Adapter
fromNAT
Select your Machine's Driver in
Name
Click
Ok
Start virtual machine
Install Ubuntu Server
Write down the username and password in a text file, so that you don't need to remember them. You can note the IP address in the Network Connections setup screen. OpenSSH (Open Secure Shell) is a free, open-source implementation of the SSH (Secure Shell) protocol. SSH is a network protocol that allows for secure, encrypted connections between computers. Make sure you select the OpenSSH option. Once installed, you can configure the firewall to access Ubuntu Server through SSH from any device in the network. This is a cool feature, you can use apps like JuiceSSH, Termux, or ConnectBot to access the server from your mobile and practice your Linux skills.
Steps
Select install Ubuntu Server
Select your preferred language,
English
If an update is available, select
Update to new installer
Select preferred, then click
Done
Select
Ubuntu Server
, selected by defaultIn
Network connections
screen, selectDone
. As Network Adapter is already selected as Bridge, the virtual machine will automatically select an IP address from the DHCP server. The host machine can connect to the virtual machine using this IP Address.If you have a proxy server in your network, then you need to add the proxy address. Let it remain empty, and click on
Done
.No need to change, Mirror address. Click
Done
Select
Use an entire disk
, selected by default. ClickDone
Review system summary
Click
Done
Click
Continue
Fill out the form. Name Your Name, Server name: ubuntu, username: ubuntu, password: secret.
Click
Done
Select
Install OpenSSH Server
, not selected by default. ClickDone
Click
Done
. No need to select any softwareOnce the installation is finished, click
Reboot Now
Verify Installation
Login using username and password
Run
ping
google.com
. If installed properly, your Ubuntu Server should be able to connect to the internet and receive data from google.comRun in order
sudo apt update
,sudo apt install nginx
,sudo systemctl status nginx
orsudo systemctl is-active nginx
,sudo fuw status
, if the result is inactive thensudo ufw enable
,sudo ufw allow http
,sudo ufw reload
Type
ip addr
to get the IP address. IP addresses always change so check each time a new Virtual Machine is createdOpen the IP address in the browser, Nginx welcome page should be visible
To use SSH, need to know the PORT on which OpenSSH is running
Run
sudo apt install net-tools
Run
sudo netstat -ltnp | grep sshd
to check on which PORT OpenSSH is runningRun
sudo ufw allow 22/tcp
, assuming 22 is the portRun
sudo ufw reload
andsudo ufw app list
to check 22 port is allowedOpen terminal in Host. Run
ssh ubuntu@your.vm.ip.addr
and enter yes if prompted and then password to login to the system.
Subscribe to my newsletter
Read articles from Ritwik Math directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Ritwik Math
Ritwik Math
As a seasoned senior web developer with a wealth of experience in Python, Javascript, web development, MySQL, MongoDB, and React, I am passionate about crafting exceptional digital experiences that delight users and drive business success.