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

Welcome to the Ubuntu Weekly Newsletter 883

Welcome to the Ubuntu Weekly Newsletter, Issue 883 for the week of March 9 –…

7 hours ago

How to Install nvidia-smi on Ubuntu or Debian Linux

In this article, we will see how to install nvidia-smi on Ubuntu or Debian Linux.…

19 hours ago

How to Install clang tool on Ubuntu or Debian Linux

In this article, we will see how to install clang tool on Ubuntu or Debian…

2 days ago

How to resolve Ubuntu 20.04 Container Signature Errors on Raspberry Pi ARM Devices

When working with Docker containers on Raspberry Pi devices, you might encounter frustrating signature verification…

2 days ago

How to fix DNS Resolution Issues with OpenVPN on Ubuntu 18.04

You’ve recently upgraded to Ubuntu 18.04 and found that your OpenVPN connection no longer resolves…

2 days ago

How to Fix Ubuntu 18.04 System Monitor Launch Issues

Have you ever tried to open System Monitor on your Ubuntu 18.04 system only to…

3 days ago