One of the common tasks for Linux users is to find out which process is using a particular network port. This can help troubleshoot network or application issues, such as web servers not responding or conflicting services. There are several commands that can show the processes and ports in use on a Linux system, such as the ones listed below.
netstat
Netstat is a command-line tool for network statistics. It can display information about open sockets, routing tables, and connection details. It can also show which ports are in use and which processes are using them. Netstat supports different protocols, such as TCP, UDP, and UNIX. Netstat can help troubleshoot network problems and monitor network activities.
Use the following command to find which service is using the port number of choice. For example, in the command below we are looking for port 80 and which services are using it.
netstat -tulpn | grep :80
lsof
The lsof command is a useful tool for Linux system administrators. It stands for “list open files” and it can show information about files that are opened by processes on the system. Files can include regular files, directories, devices, sockets, pipes, and more.
Same as the previous example, in the command below we are looking for services using port 80.
lsof -i :80