How to check port is open in Linux Ubuntu? Here is the command to check which process is using a port in Linux. On Linux, learn how to check if port is open.
Using lsof command
lsof command is used to list open files. Note that an open file may be a regular file, a directory, a block special file, a character special file, an executing text reference, a library, a stream or a network file (Internet socket, NFS file or UNIX domain socket.) A specific file or all the files in a file system may be selected by path.
$ sudo lsof -i -P -n
$ sudo lsof -i -P -n | grep LISTEN
Using netstat command
netstat (network statistics) command is used to display information about network. If the command is not installed upon the system, install it using the command $ sudo apt-get install net-tools and once installed use it to check port and process information.
$ sudo netstat -ltnp
The netstat command uses the following command parameters to diplay the related netwrok information:
l: display only listening sockets
t: display tcp connection
n: display addresses in a numerical form
p: display process ID/ Program name
If you want to get information about a specific port, you can use the netstat command using the grep function together.
$ sudo netstat -ltnp | grep -w ':80'
That’s all.