How to open port on Linux VPS?

To open a port on a Linux VPS server, we must first check with the netstat command whether the desired port is open or closed, then we decide to open or close each one through the Linux firewall.

Also, control of Linux server ports is very important for people who own their own businesses or use VPS servers because there is a possibility of exploitation and intrusion to the server, so we need to take this seriously. If you are one of those who need to change or close some public ports to keep your server secure, then this article could be useful for you.

The steps we need to take to open a port on Linux VPS are:

  • check open ports by netstat command.
  • select a fleeting port.
  • open the port.
  • confirm changes.
  • test the connection

Now let’s check and open some common Linux VPS ports in practice.

How to check all open ports in Linux VPS?

To open a port on Ubuntu Linux vps, first use the open ports list to select a temporary port that is not on the list, so the “netstat” and “ss” commands can be used.

netstat -lntu

commend nestat -lntu

Note: The meaning of the words TCP” corresponds for “Transfer Control Protocol” and “UDP” is abbreviation of “User Datagram Protocol”.

Why is netstat command not working?

If you don’t get a response from the netstat command and you get the message “Netstat Command Not Found”, you can install the system request that is based on the install net-tools” and then run the netstat command after the installation again.

Command 'netstat' not found

ss command

Also, if you don’t get a response from the netstat command, you can use the following command, the output of both is the same:

ss -lntu

commend ss -lntu

Note: The environment of above figure, has been taken after enter to the Linux Server by the corresponding username and password, if you don’t know how to enter this environment, so you can study the Connect to Linux VPS Server article.

How do I open a port on Linux VPS Using UFW firewall?

Step 1- check Port using “$ netstat -na”

Now you have to select the port number you want to open (for example, in this tutorial, port number 2000 is selected) and use the command “$ netstat -na | grep :2000” to make sure the port is closed and it is not being used by another service (figure below)

netstat -na | grep :2000

netstat -na | grep :2000

If something isn’t written in the command output, it means that the port is empty and ready to use.

Step 2- Install UFW Firwall

Now is the time to insert the desired port number (in this case port number 2000) into the firewall table, so the UFW program must be installed on the Linux server first with the following command:

sudo apt install ufw

sudo apt install ufw

Step 3- Add port with UFW command

After installing the firewall, use the following command to add the desired port to the firewall table:

sudo ufw allow 2000

sudo ufw allow 2000

Step 4- Enable the UFW firewall

Now, it is important to activate the firewall with the following command:

sudo ufw enable

sudo ufw enable

Step 5- Initialization for the port

To initialize the server to connect through the desired port while waiting for a connection request from the client, use the following command to initialize it:

ls | nc -l -p 2000

ls | nc -l -p 2000

In this case, the server waits to receive the request for communication from the client. The blinking mark shows this.

Step 6- nmap localhost -p command to check if the port is open

After establishing a connection between the Linux server and the client server, use the “nmap” command to check if port 2000 is open as follows:

nmap localhost -p 2000

'nmap' not found

If you encounter this image after executing this command, install the requested steps as requested by the system and proceed:

nmap localhost -p 2000


In this article, we explained how to open ports on Linux VPS.
According to this article, you can simply open a port on the Linux server via a few commands. If you are familiar with the Linux commands line, you can open a port in just a few minutes.
Good luck.

author image

The Author Robert Smite

Hello! I'm Robert, specializing in virtual servers and cloud technology. With expertise in managing and optimizing virtual servers, my focus is on delivering understandable and practical content in this field. My goal is to enhance knowledge and assist individuals in selecting the best virtual services for their needs.

More from Robert Smite

Post Your Comment

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