Javatpoint Logo
Javatpoint Logo

What is Listening Port

Communication protocol types like UDP (User datagram protocol), or TCP (transmission control protocol), associated IP address, and the number of port identifies the network port. The network port is just like the Listening port. The listening port listens to applications or processes on the network port. It is acting just like the communication endpoint.

Using the firewall, we can open or closed each listening port. The open port can be defined as a network port used to accept incoming packets from remote locations. The same port cannot listen to two services on the same IP address.

For example, suppose we use ports 80 and 443 to listen and run an apache web server. In this case, HTTP and HTTPS ports are already in use. That's why, if we try to install Nginx, we will not be able to start it.

Check listening Ports with netstat

Netstat is described as a command-line tool. Information about network connection is provided by it. We will use the following command to list all open listening ports like UDP or TCP along with the services using the socket status and the ports:

What is Listening Port

Where

-l is used to indicate all listening sockets

-t is used to indicate all TCP connections

-u is used to indicate all UDP connections

-p is used to indicate the name of the listener's process or PID. If we run the command as sudo user or as root, only then this information will show.

The output of the above command is shown in the following screenshot:

What is Listening Port

In our case, the important columns are:

Proto: It shows the protocol which the socket use.

Local Address: It shows the listening port's port number and IP address.

PID/Program name: It shows the PID and the process name.

Instead of the service name, if we want to print numeric value, we can add -n flag, as shown follows:

What is Listening Port

The output of the above command is as follows:

What is Listening Port

We can use the grep command to filter the result. Using this command, we can find about the application which is listening on a particular port.

What is Listening Port

The output of the above command is as follows:

What is Listening Port

Alternative, we can find what application is listening on the specifying port, as shown follows:

What is Listening Port

The output of the above command is as follows:

What is Listening Port

Nothing will be listening on the port if the output is empty. On the basis of the criteria like state, PID, protocol, we can also filter the list.

Now this time, netstat is outdated. That's why it is replaced with ss and ip, but still, if we want to check the network connection, the netstat command will be one of the most used commands.

Check listening ports with ss

New netstat is described by ss command. Some features of netstat are absent in ss, but it is slightly faster compared to netstat, and can expose more TCP states. It is not difficult to transmit from netstat to ss because the command options of both commands are mostly the same. We will use the following command to get all the listening port's lists.

What is Listening Port

The output of netstat command and the above command is almost the same.

What is Listening Port

Checking listening port with Nmap

Nmap is described as a popular and powerful port scanner and network exploitation tool. We can use our default package manager to install nmap on our computer as shown follows;

What is Listening Port

We will run the following command in our Linux system in order to scan all open or listening ports. The completion of this process will take a long time.

What is Listening Port

Checking listening port with lsof

Isof is described as a powerful command-line utility. It is used to provide information about open files. Everything is a file in the Linux operating system. A socket may be a network file or stream that is used to write to the network.

We will use the -i option to list all the files which are available on the network or internet. The mix of numeric ports and service name is shown by this command.

What is Listening Port

The output of the above command is as follows:

What is Listening Port

We will run isof in the following form to determine the listening application on a particular port, as shown below:

What is Listening Port

The output of the above command is as follows:

What is Listening Port

In the above section, we have explained four ways in Linux operating system to check open ports. We also have learned about the processes which are bound upon particular ports.






Youtube For Videos Join Our Youtube Channel: Join Now

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA