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.
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.
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.
Discover more from Ubuntu-Server.com
Subscribe to get the latest posts sent to your email.