How do I check if a port is in use on Linux?

There are several ways to check if a port is in use on Linux.

  1. netstat command: The netstat 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
  1. lsof command: The lsof 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
  1. ss command: The ss command is a more recent and efficient alternative to netstat. 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.

Leave a Comment