How to Remote CentOS Virtual Server running in a VirtualBox with a NAT Network using SSH

Posted on

Introduction

This article is presenting content about how to access a CentOS Virtual Server. The CentOS Virtual Server itself is running in a VirtualBox application. There is a need in order to be able to access it using SSH. There are specific requirements in order to achieve the purpose. Actually, this article has a specific relation with several other articles. The first article is an article with the title of ‘How to Install CentOS 8 in VirtualBox running in Microsoft Windows 10’ and it exist in the following link. Another one is an article with the title of ‘How to Activate Network Interface in CentOS 8 running in a VirtualBox’ in this link. However, there is a problem on accessing the CentOS virtual server using SSH.

 

Configuring VirtualBox Manager to accept Incoming Connection in Port 22 using SSH

So, the following are steps to enable remote access to the CentOS virtual server running in VirtualBox application using SSH :

1. Make sure that the running firewall is accepting connection in port 22. It is a default port for accessing server remotely using SSH. The following is the command for adding the port so that any connection to the port will be available.

firewall-cmd --add-port 22/tcp --permanent

2. Do not forget to restart or reload the change which has been added in the previous step. Just do it by executing the following command :

firewall-cmd --reload

For further information about the firewall configuration, just read the article the title of ‘How to Add Rule in the Firewall to Allow Incoming SSH Connection in CentOS 8’ in this link.

3. The most important thing is to add port forwarding rule in the NAT setting configuration of the network interface. Just select the Virtual Server with the associated label. Right click and select the General menu. Soon after, select the Network menu as in the following image :

How to Remote CentOS Virtual Server running in a VirtualBox with a NAT Network using SSH
How to Remote CentOS Virtual Server running in a VirtualBox with a NAT Network using SSH

4. Click the Port Forwarding button as in the above image, the following image of the Setting Window Dialog Box will appear :

How to Remote CentOS Virtual Server running in a VirtualBox with a NAT Network using SSH
How to Remote CentOS Virtual Server running in a VirtualBox with a NAT Network using SSH

5. Adding a Port Forwarding is just an utility to be able to access remotely the CentOS virtual server using SSH. Click the Plus Sign, the following image will appear :

How to Remote CentOS Virtual Server running in a VirtualBox with a NAT Network using SSH
How to Remote CentOS Virtual Server running in a VirtualBox with a NAT Network using SSH

6. Configure the entry Port Forwarding in the new added line as in the above image as follows :

How to Remote CentOS Virtual Server running in a VirtualBox with a NAT Network using SSH
How to Remote CentOS Virtual Server running in a VirtualBox with a NAT Network using SSH

The above definition means that every connection that come from port 9922 in the local host where the VirtualBox application run will be redirected to the Virtual Server IP Address of 10.0.2.15 in port 22.

 

Testing to Access CentOS Virtual Server using SSH from Host

The following is a part for testing to access CentOS virtual server remotely using SSH. The access is from the host where the VirtualBox application run. The access is from the localhost port 9922. It will be mapped and redirected to the CentOS virtual server with the IP Address of 10.0.2.15 in port 22 as follows :

How to Remote CentOS Virtual Server running in a VirtualBox with a NAT Network using SSH
How to Remote CentOS Virtual Server running in a VirtualBox with a NAT Network using SSH

As in the above image, the remote connection from the host with localhost address in port 9922 is a success using SSH protocol to access the CentOS virtual server with the IP Address of 10.0.2.15 in port 22.

12 thoughts on “How to Remote CentOS Virtual Server running in a VirtualBox with a NAT Network using SSH

Leave a Reply