Notes from the VirtualBox – Part 3

Connecting to the New VBox Ubuntu 18 Desktop

Now that we have a shiny new installation of Ubuntu 18 desktop running inside a VBox (see Part 1 and Part 2 for installation instructions), it’s time to open up some connections to it. For example, I want to be able to access my VBox Ubuntu from Windows using SSH. I also want to be able to view web pages that are being served by Apache running on my VBox Ubuntu. These are typical of the activities that you would need to be able to perform if you were responsible for maintaining a web site that was hosted by a commercial provider, such as GoDaddy or A2Hosting.

Starting with Ubuntu 17, netplan or NetworkManager became the default method for managing all network adapters. NetworkManager is the default tool (renderer) used with Ubuntu desktop, while networkd became the default renderer for Ubuntu server. This is important because a significant amount of obsolete instructions is still posted on the internet. This blog will only discuss NetworkManager; networkd will be discussed in the upcoming blog about Ubuntu 18 server running in VBox.

Fortunately, NetworkManager is very friendly and just handles it all for you. If you configured your VBox VM to have two network adapters (NAT and Host-only) before installing Ubuntu, those adapters will have addresses assigned to them automatically by NetworkManager.

The easiest way to verify that your network adapters have been assigned addresses is to open a terminal window and then type this command

sudo ip address show

A screen similar to the following will be displayed:

Results of running the ip command

Note that device 2 is named enp0s3. This name is generated by the system based on some special magic formula that superseded the old-style names such as eth0, eth1, etc. enp0s3 is the default connection for the NAT adapter that provides connectivity to the outside world.

Device 3 is named enp0s8 and is also automatically generated for us. It is automatically assigned an IP4 address, typically for Host-Only network adapters. If your system doesn’t have a third device or if the device doesn’t have an ip address, exit your Ubuntu instance and inside VBox manager add a network adapter (typically Host-Only). When you get back into your Ubuntu instance and repeat the ip command it should show device 3 with an ip address.

NetworkManager in the latest versions of Ubuntu desktop is a slick piece of code but I’m not sure how it’s configured. The configuration file in /etc/netplan only specifies the renderer (NetworkManager); apparently all other details are left to NetworkManager unlike Ubuntu 18 server that requires all network adapter details be specified completely. More in the next blog.

Now that we have two adapters, if we try to access either a web page or an SSH connection from Window we will get failures because the default Ubuntu 18 desktop install doesn’t include the tools to respond to http requests or ssh requests.

So back to our terminal window. Type the following command:

sudo ufw status

If the Uncomplicated Firewall (ufw) is not installed, install it as follows:

sudo apt install ufw

If ufw responds that it is inactive, enable it as follows:

sudo ufw enable

You can repeat the ufw status command at this point and it should tell you that it is active and which ports are available (which should be none).  Now find out which applications have been configure to communicate with the outside world as follows:

sudo ufw app list

Typically, there will be no apps listed or just CUPS (Common Unix Printing System).

Install and Activate OpenSSH

Let’s setup OpenSSH to be allowed thru the firewall first.

sudo ufw allow OpenSSH

If it doesn’t know anything about OpenSSH, it hasn’t been installed. Install the OpenSSH server as follows:

sudo apt install openssh-server
sudo systemctl status ssh

The OpenSSH application should now be listed as enabled and active, similar to the following:

We installed OpenSSH but the service is referred to as ssh

Update the firewall as follows:

sudo ufw allow ssh      or/both
sudo ufw allow OpenSSH

If you do both commands there will be two rules for SSH, as shown when the    sudo ufw status  command is executed.

Both ssh and OpenSSH are available on port 22

Now on Windows, open putty and point it at your VBox Ubuntu:

Note the IP address is the same as the enp0s8 IP address

Click the Open button to start connecting to your VBox Ubuntu. It may complain about not recognizing your VBox Ubuntu but since we are forced to be on (inside) this computer, it is safe to continue. Log in with your user name and password and you’ll be able access your VBox Ubuntu from Windows and perform any terminal operations that you could inside VBox Ubuntu terminal window.

Install and Activate Apache Web Server

Apache web server is the most popular web server in the world and has proven to be robust and stable for many years. It is not automatically installed when you installed Ubuntu 18 desktop into VBox. It can be installed as follows:

sudo apt install apache2
sudo service apache2 start

Now, if we run the command   “sudo systemctl” we will find it running:

Apache is running (3rd line from bottom)

Now we need to make sure Apache can get thru the firewall, so:

sudo ufw allow http       OR/BOTH
sudo ufw allow Apache

Check the firewall status as follows:

sudo ufw status

And the displayed info should be similar to the following:

Now if we go to our Windows browser of choice and put in the IP address given for enp0s8 then we should get a screen similar to the following:

Leave a Reply

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