Each network service running on a Linux system uses a particular protocol (the most common being the TCP (Transmission Control Protocol) and UDP (User Datagram Protocol)) and a port number for communicating with other processes or services.

We will show you how to list and monitor or watch running TCP and UDP ports in real-time with a socket.


List All Open Ports in Linux

To list all open ports on a Linux system, you can use the netstat command or ss utility as follows.

It is also crucial to mention that netstat command has been deprecated and instead ss command has taken its place in showing more detailed network statistics.

$ sudo netstat -tulpn
$ sudo ss -tulpn


In the above command, the flag:

-t – enables listing of TCP ports.
-u – enables listing of UDP ports.
-l – prints only listening sockets.
-n – shows the port number.
-p – show process/program name.


Watch TCP and UDP Open Ports in Real-Time

However, to watch TCP and UDP ports in real-time, you can run the netstat or ss tool with the watch utility as shown.

$ sudo watch netstat -tulpn
$ sudo watch ss -tulpn


Was this answer helpful? 0 Users Found This Useful (0 Votes)