Categories: 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.

Sponsored

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.

Sponsored

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.

Ubuntu Server Admin

Recent Posts

How to Install Google Cloud AI Python client library to interact with Vertex AI

In this article, we will see how to install google cloud AI Python client library…

2 hours ago

Meet the Canonical Ceph team at Cephalocon 2024

Photo by Jeton Bajrami on Unsplash Date: December 4-5th, 2024 Location: Geneva, Switzerland In just…

22 hours ago

The transition to in-house software development in the automotive industry

Who will win the race to the perfect SDV? The automotive industry is experiencing a…

22 hours ago

Profile-guided optimization: A case study

Software developers spend a huge amount of effort working on optimization – extracting more speed…

22 hours ago

Ubuntu Weekly Newsletter 866

Welcome to the Ubuntu Weekly Newsletter, Issue 866 for the week of November 10 –…

2 days ago

Ubuntu vs Debian: Linux Distributions Compared Deep Dive

Debian and Ubuntu are two popular Linux distributions. In this deep dive we will guide…

2 days ago