Save 10%Pay yearly on any plan. 6% half-yearly, 3% quarterly. Help centreWhatsAppTelegram TeamsOpen a ticket

How to Check Open Ports on Ubuntu

See which ports are listening on Ubuntu and which program owns each, tell local-only ports from reachable ones, and test from outside what the firewall lets through.

2 min readBy Swati

Reviewed by the AmazingRDP technical team

Checking open ports on Ubuntu

A Linux VPS gives you root access and full control of ports and firewall. See Linux VPS from $6.99

"Is the port open?" is really two questions. Is a program on the machine listening on that port? And can the outside world reach it through the firewall? You check the first on the machine itself and the second from another computer.

1. What is listening: ss

sudo ss -tulnp
LetterMeaning
t, uTCP and UDP
lListening sockets only
nNumbers, not names
pThe program that owns each (needs sudo)

Read the Local Address:Port column carefully:

  • 0.0.0.0:80 or [::]:80 means the program listens on every address. It can be reached from outside if the firewall allows.
  • 127.0.0.1:3306 means it listens for the machine itself only. Nobody outside can reach it, whatever the firewall says.

One port only:

sudo ss -tulnp | grep ':443'

2. Which program has the port: lsof

sudo lsof -i :80
sudo lsof -i -P -n | grep LISTEN

The first line answers "what is using port 80" when a web server refuses to start because the port is taken.

3. The old way: netstat

sudo apt install net-tools
sudo netstat -tulnp

netstat shows the same as ss and is no longer installed by default. Use it if you know it; otherwise stay with ss.

4. What the firewall allows

sudo ufw status verbose

If the status is inactive, the firewall filters nothing, and every port from step 1 that listens on 0.0.0.0 is reachable. See how to open or block a port in the Ubuntu firewall.

5. The view from outside: nmap

Run this from another machine, not from the server:

sudo apt install nmap
nmap -Pn SERVER_IP
nmap -Pn -p 22,80,443 SERVER_IP
ResultMeaning
openA program answers; the port is reachable
closedReachable, but nothing listens
filteredA firewall drops the traffic

Scanning localhost on the server itself, as some guides show, skips the firewall and tells you no more than step 1. Scan only machines that are yours or that you have permission to test.

A quick test of one port without nmap:

nc -zv SERVER_IP 443

What to do with the list

  • You do not recognise a program. Look it up by its process ID: ps -p 1234 -o pid,user,cmd.
  • A service you do not need. Stop and disable it: sudo systemctl disable --now NAME.
  • A database or admin tool listening on 0.0.0.0. Change its setting to 127.0.0.1, or allow its port in the firewall for your own address only.

On a Linux VPS everything listening on a public address is reachable by the whole internet unless you close it, so run these checks after every new installation. Related guides: set a static IP on Ubuntu Server, restart the network in Ubuntu and, for Windows, monitor all network traffic in Windows.

Questions

What is the command to check open ports in Ubuntu?

sudo ss -tulnp lists every listening port with the program that owns it.

How do I find which process is using a port?

Run sudo lsof -i :PORT or sudo ss -tulnp | grep ':PORT'.

What is the difference between 0.0.0.0 and 127.0.0.1 in the list?

0.0.0.0 means the program accepts connections from anywhere. 127.0.0.1 means from the same machine only.

How do I check if a port is open from outside?

From another computer, run nmap -Pn -p PORT SERVER_IP or nc -zv SERVER_IP PORT.