Home>Article>Operation and Maintenance> How to check if a port is open in Linux?
In Linux, we can check whether the port is open by using the lsof command and netstat command on the command line.
Method 1: Use the lsof command
We can use the lsof command to check whether a certain port Open, the basic syntax is as follows:
lsof -i:端口号
If there is no output, it means that the port number is not open
The following figure takes port 80 and port 53 as an example to check whether port 80 and port 53 are open
You can also use the lsof -i command to directly output the open ports to check whether certain ports are open.
Method 2: Use the netstat command
The netstat command can provide network-related information about the host.
We can use netstat -atu to check open ports in linux
Netstat flags we use: -a, -t and -u Introduction
-a: All sockets.
-t: TCP connection of the program
-u: UDP connection of the program
You can also add the -p flag to display the related PID of the process or program name.
To display only UDP ports, you can use the following command:
To display only TCP ports, you can use the following Command:
Related video tutorial recommendation: "Linux Tutorial"
The above is the entire content of this article, I hope it will be helpful to everyone's study. For more exciting content, you can pay attention to the relevant tutorial columns of the PHP Chinese website! ! !
The above is the detailed content of How to check if a port is open in Linux?. For more information, please follow other related articles on the PHP Chinese website!