How to Watch TCP and UDP Ports in Real-time

[‘

n

In software terms, especially at the operating system level, a port is a logical construct that identifies a specific process/application or a type of network service and 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.

n

In this short article, we will show you how to list and monitor or watch running TCP and UDP ports in real-time with a socket summary on a Linux system.

n

List All Open Ports in Linux

n

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

n

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.

n

$ sudo netstat -tulpnrnORrn$ sudo ss -tulpnrn

n

List Open Ports in Linux
List Open Ports in Linux

n

From the output of the above command, the State column shows whether a port is in a listening state (LISTEN) or not.

n

In the above command, the flag:

n

    n

  • -t – enables listing of TCP ports.
  • n

  • -u – enables listing of UDP ports.
  • n

  • -l – prints only listening sockets.
  • n

  • -n – shows the port number.
  • n

  • -p – show process/program name.
  • n

n

Watch TCP and UDP Open Ports in Real-Time

n

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

n

$ sudo watch netstat -tulpnrnORrn$ sudo watch ss -tulpnrn

n

Watch Open Ports in Real Time in Linux
Watch Open Ports in Real Time in Linux

n

To exit, press Ctrl+C.

n

You will also find the following articles useful:

n

    n

  1. 3 Ways to Find Out Which Process Listening on a Particular Port
  2. n

  3. How to Check Remote Ports are Reachable Using ‘nc’ Command
  4. n

  5. How to List All Running Services Under Systemd in Linux
  6. n

  7. 29 Practical Examples of Nmap Commands for Linux System/Network Administrators
  8. n

n

That’s all for now! If you have any questions or thoughts to share about this topic, reach us via the comment section below.

n

‘]