Open ports in Linux
Part of the network diagnosis is to check the services with open ports on Linux.
How to Check Open Ports on Linux
To check open ports with netstat, the “-tunl” options can be used:
-t for TCP
-u for UDP
-n to not resolve names
-l for open doors (listen)
In this example, netstat lists the open TCP/UDP ports:
The ss command can also show open ports with the identical option:
ss -tunnel
lsof command on Linux
Since everything in Linux is a file, network connections can also be viewed as an “open file”. The “lsof” command can be used in this context to view files that correspond to Internet addresses.
The lsof “-i” option filters open files from the type of Internet addresses. It is necessary to run lsof as root:
fuser command on Linux
The “fuser” command can also be used to display information about a particular open port. It identifies the processes through the files or sockets, returning the PID of the processes:
To find out which process is using a particular file:
The netstat, ss, lsof, and fuser commands are used to view the local machine’s open ports.
There is a tool called nmap that can also discover the open ports of both the local machine and the remote machines.
Learn much more about Linux in our books.
Did you like it? Share