Check if the port is open in Linux.
In Linux systems, you can use the netstat command or the lsof command to check if a port is open.
- Use the netstat command:
netstat -tuln | grep <端口号>
The -t option displays only TCP protocol ports, the -u option displays only UDP protocol ports, the -l option shows only listening ports, and the -n option displays port numbers in numerical form.
- Use the lsof command:
lsof -i :<端口号>
The -i option is used to display only network-related information, followed by specifying the port number to be queried.
Both methods can be used to check if a specified port is open and display the corresponding service or process information.