Home >Operation and Maintenance >Linux Operation and Maintenance >How to check if a port is enabled in Linux

How to check if a port is enabled in Linux

WBOY
WBOYOriginal
2022-04-12 17:29:5329716browse

Method: 1. Use the lsof command to check whether the port is enabled. This command is used to list all files that have been opened by the system. When the parameter is set to "-i", you can list the processes that meet the conditions. Syntax It is "lsof -i:port number"; 2. Use the "netstat-aptn" command, which can view all open port numbers.

How to check if a port is enabled in Linux

#The operating environment of this article: linux7.3 system, Dell G3 computer.

How to check whether the port is enabled in Linux

The lsof command is used to check the files opened by your process, the process that opened the file, and the ports opened by the process (TCP, UDP). Retrieve/recover deleted files. It is a very convenient system monitoring tool. Because the lsof command needs to access core memory and various files, it needs to be executed by the root user.

In the Linux environment, everything exists in the form of files. Through files, you can not only access regular data, but also network connections and hardware. Therefore, for example, Transmission Control Protocol (TCP) and User Datagram Protocol (UDP) sockets, the system allocates a file descriptor to the application in the background. Regardless of the nature of the file, the file descriptor is used by the application. Provides a common interface for interaction with the underlying operating system. Because the descriptor list of files opened by an application provides a lot of information about the application itself, being able to view this list through the lsof tool can be helpful for system monitoring and troubleshooting.

Syntax:

lsof(选项)

Options:

  • -a List the processes that open the file;

  • -c List the files opened by the specified process;

  • -g List the GID process details;

  • -d List the processes occupying the file number;

  • d List the files opened in the directory;

  • D Recursively lists open files in the directory;

  • -n Lists files using NFS;

  • -i List processes that meet the conditions. (4, 6, protocol, :port, @ip)

The first method:

Use the lsof command

lsof -i:端口号

Examples are as follows:

How to check if a port is enabled in Linux

Second method:

Use the netstat-aptn command.

How to check if a port is enabled in Linux

Related recommendations: "Linux Video Tutorial"

The above is the detailed content of How to check if a port is enabled in Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn