How to locate and close an open port in Linux

Finding and blocking unwelcome open ports in Linux ought to be a job each community admin is aware of how to do.

Picture: Getty Illustrations or photos/iStockphoto

So you happen to be a community administrator and you have a variety of Linux devices in your facts centre. You’ve got uncovered some odd targeted visitors bouncing about your network and your curiosity is piqued. Is it feasible that targeted traffic is generating use of an open port on a device? If so, where’s the port and how do you close it?

On those people Linux devices, the process is really fairly straightforward. I want to display you how to track down an open up port and near it. I am going to be demonstrating on Ubuntu Server 18.04, even though the course of action will be comparable on many distributions—the only big difference being how you near the port.

SEE: Windows 10 stability: A information for small business leaders (TechRepublic High quality)

What you are going to need

In get to make this do the job, all you may require is a working occasion of Ubuntu Server and a user account with sudo privileges. 

How to identify a listening port

Fortunately, you will not have to put in any application to make this get the job done. Why? Mainly because we’ll be using the ss command (as netstat has been deprecated) to look at the listening ports on your server. This will be accomplished wholly from the command line, so possibly log into your server or use protected shell for accessibility. At the time you are at the bash prompt, concern the command:

sudo ss -tulwn | grep Hear

The selections are as follows:

  • -t  Display only TCP sockets on Linux
  • -u Screen only UDP sockets on Linux
  • -l Display listening sockets (for instance, TCP port 22 is opened by SSHD server)
  • -p Checklist process identify that opened sockets
  • -n Will not solve support names 

The output (Determine A) will checklist out only the listening ports.

Determine A


As you can see, there are only a handful of listening ports on this device (53, 22, 631, 445, 3306, 11211, 80, 8080). That is a fairly slim listing of ports. 

If you’re not sure of what port maps to what services, you can constantly find out in the /etc/providers file. Examine that file with the command:

significantly less /and so forth/services

You should really see a listing of each port out there to Linux (Figure B).

Determine B


The port listing for Linux.

How to close a port

Say you are internet hosting a web server on the machine but you will not want port 8080 listening. Alternatively, you only want targeted visitors going by means of ports 80 (HTTP) and 443 (HTTPS). To close port 8080, we will use the ufw (Uncomplicated FireWall) command like so:

sudo ufw deny 8080

You should really see the regulations have been current and the port is now blocked. If you obtain blocking this port to bring about issues with a service or application, you can re-open it with the command:

sudo ufw permit 8080

And which is all there is to locating and closing a listening port on Ubuntu Server 18.04. This approach ought to perform on most distributions, the only caveat will be how you block a port as not every single distribution makes use of ufw. If your distribution of option works by using a different command for blocking ports (this sort of as sudo iptables -A Input -p tcp –destination-port 80 -j Fall), make guaranteed you know how to acquire treatment of this endeavor on your servers. 

Also see

Fibo Quantum

Be the first to comment

Leave a Reply

Your email address will not be published.