How To List Open Ports In Linux

Linux, being a very flexible and open-source operating system, allows its users to have full control over its working. One such capability it offers is to check the open ports. Ports are the endpoints that allow network communication to a specific process or service running on a Linux system. For system administrators or networking enthusiasts, knowing how to list open ports in Linux is an essential skill. In this blog post, we will guide you on how to achieve this.

There are various ways to list open ports in Linux, but we will focus on two primary methods: using the netstat command and the ss command.

1. Using netstat command

The netstat (network statistics) command is a command-line tool that provides information about network connections, routing tables, interface statistics, and so on. However, please note that the netstat tool has been deprecated and may not exist in the newer versions of Linux distributions. Instead, the ss tool is used, which we will discuss later in the post.

To list all the open ports in Linux using the netstat command, you can use the following command:

netstat -lntu

This command will display a list of all open ports and the services that are using them. The flags used in this command are:

  • -l : This shows only the listening sockets
  • -n : This shows the numerical addresses rather than trying to determine symbolic host, port, or user names
  • -t : This indicates TCP ports
  • -u : This indicates UDP ports

2. Using ss command

The ‘socket statistics’ or ss command is an improved version of the netstat command. It is used to dump socket statistics and displays information similar to netstat.

To list all the open ports on your Linux system using the ss command, you can use the following command:

ss -lntu

Similar to the netstat command, the flags -l, -n, -t and -u are used in the same manner.

By understanding how to list open ports in Linux, you can gain a better perspective on the networking aspect of your system. It is also one of the fundamental steps in network troubleshooting and system security. Happy learning and exploring the wonders of Linux!