How to Watch TCP and UDP Ports in Real-time

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.

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.

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
OR
$ sudo ss -tulpn
List Open Ports in Linux
List Open Ports in Linux

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

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
OR
$ sudo watch ss -tulpn
Watch Open Ports in Real Time in Linux
Watch Open Ports in Real Time in Linux

To exit, press Ctrl+C.

You will also find the following articles useful:

  1. 3 Ways to Find Out Which Process Listening on a Particular Port
  2. How to Check Remote Ports are Reachable Using ‘nc’ Command
  3. How to List All Running Services Under Systemd in Linux
  4. 29 Practical Examples of Nmap Commands for Linux System/Network Administrators

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

Two small things before you go

If something didn’t work on your setup, leave a comment and tell me which distro and version you’re on. I read every one, and most of these articles got better because a reader pointed out what was missing.

And if it did work, share it. TecMint has stayed free for 14 years because people pass these articles around, and that traffic is what pays for writing the next one.

Leave a comment
Get two free Linux courses

Learn the Linux basics with two free courses and join 34,000+ readers getting practical TecMint tutorials and selected Pro TecMint articles every week.

Pro TecMint
Get lifetime access for $99

If you want to go beyond the free tutorials, Pro gives you 18 courses, 5 ebooks, and every future course I add. One payment, lifetime access, no renewals.

Aaron Kili
Aaron Kili
Contributor
About the author

Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

14 Comments

Leave a Reply
    • tcpdump this is quite different.

      The author of the guide probably did not notice that he wrote a little ambiguously. However, people more associate the tcpdump command with the tool for viewing transmitted data.

      The “watch” command runs another command periodically from time to time. The name of the command is not important here. Real-time can have two definitions here.

      The first is “speed performance 1 kbit/s”
      Second, “the ability to display the entire data queue per second”.

      For someone, refreshment once every two seconds or once a month can also be real-time.

      This is the magic of human definition.

      More in “man watch” and in first line of output.

      Reply
    • “admin” / Aaron, maybe this tutorial is not big about “watch” command how to use and how to get help, but don’t worry, because I like to read something interesting.

      I mean, it is better than nothing or nonsense and I read with pleasure.

      So forgive me sometimes harsh words.

      Reply
  1. The title of this article is misleading. the watch command is batch based on a timer event triggering you can specify the granularity but it’s clearly not real-time.

    Reply
    • You don’t need to write the same command to check.

      However, if you see the open port, it means that malware/virus is too slow to open and close port below 2s.

      Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.