Check if the port is available in Linux.

On Linux, you can use the following command to check if a port is available:

  1. Using the netstat command:
netstat -tuln | grep <端口号>

This command will list all the ports that are currently being listened to, and search for the specified port number. If the port number is listed, it means the port is being used; otherwise, it is available.

  1. Use the lsof command:
lsof -i :<端口号>

This command will display all processes using the specified port. If the output is empty, it means the port is available.

  1. Use the nc command:
nc -zv <IP地址> <端口号>

This command tries to connect to the specified IP address and port number. If the connection is successful, it means the port is available. If the connection fails or is refused, it means the port is not available.

  1. Use the telnet command:
telnet <IP地址> <端口号>

This command will attempt to connect to the specified IP address and port number. If the connection is successful, it means the port is available. If the connection fails or is refused, it means the port is not available.

Please note that the in the above command should be replaced with the port number you want to check, and the can be replaced with a specific IP address or hostname.

bannerAds