Ubuntu

Check what ports and processes are running in Ubuntu

You must know what ports are operating and which process is running on that port before connecting to a port or debugging. Sometimes you may also have problems like “port already in use,” and if necessary, you have to know what process is using that port and terminate it if needed. It may be achieved by the knowledge of which ports the different processes use. We shall examine some approaches to complete the work in this post. First, though, let’s grasp some of the technical words used in this article.

What are Ports?

Ports are an abstraction that may communicate applications using various protocols. For transport layer protocols like TCP, UDP, and SMTP, ports are utilized. Different services are allocated a port number, such as port 80 used by HTTP, port 22 used by SSH, etc. The usage of port numbers enables a couple of systems to open many sockets through the same transport protocol.

Multiple ports and dynamic ports 49152-65535 are used in an application. The first 1024 ports (00-1023) are System Ports, which prohibit user programs from meddling with them since many operating systems reserve these ports for privileged functions.
Ports may receive and deliver data and are above the OSI model’s Transport layer.

What are Processes?

In essence, a process is a program’s dynamic instance and is carried out sequentially. An entity representing the core work unit to be implemented in the system is specified as a process. In plain words, we create our computer programs in a text file, and it becomes a process that does all the duties stated in the program when we execute this program.

Let us now see the methods to check the ports and processes running in Ubuntu.

Method 1: Using netstat and grep Command

netstat

The netstat command displays network status and protocol statistics. Depending on the command line parameter used, netstat shows different sorts of network data. TCP and UDP endpoints can be seen in table, routing table, and interface information formats.

grep

The grep filter examines the file and displays every line that contains that pattern for a certain pattern of characters. The pattern looked for in the file is called the regular expression.

Use the following command to check which process is running on a port. You must specify the port in this command.

$ netstat -ltnp | grep -w ':80'

Method 2: Listing All Listening Ports Using netstat

Use the following command to list all TCP or UDP ports that listen, including those that utilize ports and socket status.

sudo netstat -tunlp

Method 3: Using ss Command

The command ss is a utility used to dump the statistical socket and show information similarly to netstat. Also, TCP and state information is displayed than most other tools. It is also slightly faster than netstat.

Conclusion

We have seen various commands to see which ports your system uses and how to run on a particular port. These commands can be particularly helpful while optimizing the performance of the system and in various debugging tasks. For instance, if you want to run a web application on port 8000 but that port is already occupied, you can look for the process running on this port and kill the process if needed. We have discussed three methods to check the ports and processes running in Ubuntu use that best suit your needs.

About the author

Simran Kaur

Simran works as a technical writer. The graduate in MS Computer Science from the well known CS hub, aka Silicon Valley, is also an editor of the website. She enjoys writing about any tech topic, including programming, algorithms, cloud, data science, and AI. Travelling, sketching, and gardening are the hobbies that interest her.