How to check if a port is running in Linux

To check if ports are running in the Linux system, you can use the following command:

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

For example, to check if port 80 is running, you can run the following command:

netstat -tuln | grep 80

If port 80 is already in use, it will display similar content.

tcp  0  0  0.0.0.0:80  0.0.0.0:*  LISTEN
  1. Use the ss command:
ss -tuln | grep <端口号>

For example, to check if port 80 is activated, you can run the following command:

ss -tuln | grep 80

If port 80 is already running, the following content will be displayed:

LISTEN  0  128  *:80  *:*

These commands will list all the ports that are currently active, along with their corresponding listening address and process information. If a port is not active, there will be no output.

bannerAds