There are several ways to check if a port is in use on Linux.
netstat
command: Thenetstat
command can be used to check the status of network connections and open ports. To check if a specific port is in use, you can use the following command:
netstat -tuln | grep :<port_number>
For example, to check if port 80 is in use, you can use the command:
netstat -tuln | grep :80
lsof
command: Thelsof
command can be used to list open files and the processes that have them open. To check if a specific port is in use, you can use the following command:
lsof -i :<port_number>
For example, to check if port 80 is in use, you can use the command:
lsof -i :80
ss
command: Thess
command is a more recent and efficient alternative tonetstat
. To check if a specific port is in use, you can use the following command:
ss -tuln | grep :<port_number>
For example, to check if port 80 is in use, you can use the command:
ss -tuln | grep :80
The above commands will display a list of connections that are using the specified port, including the process ID, protocol, and IP address. If no output is displayed, the port is not in use.