Home > Common Problem > How to query the port in linux

How to query the port in linux

百草
Release: 2023-08-10 13:31:09
Original
14636 people have browsed it

How to query the port on Linux: 1. Use the netstat command, the command is "netstat -tuln"; 2. Use the lsof command, the command is "lsof -i"; 3. Use the ss command, the command is "ss -tuln"; 4. Use the nmap command, the command is "nmap -p"; 5. Use the /proc file system by accessing /proc/net/tcp and /proc/net/ udp file.

How to query the port in linux

## The operating environment of this article: linux6.4.3 system, Dell G3 computer.

Linux system provides a variety of methods to query ports. The following are commonly used methods:

Use the netstat command:

The netstat command can Used to display network connections, routing tables, network interfaces and other related information, including port information. All port information can be queried through the following command:

netstat -tuln
Copy after login

This command will list all currently listening TCP and UDP ports, as well as the corresponding process ID and process name.

Use the lsof command:

The lsof command can list the files currently opened in the system and can also be used to query port information. You can query all ports in use through the following command:

lsof -i
Copy after login

This command will list the information of all network connections currently in use, including port, protocol, process ID and process name.

Use the ss command:

The ss command is an alternative tool to netstat and can be used to query information such as network connections, sockets, and routing tables. All port information can be queried through the following command:

ss -tuln
Copy after login

This command will list all currently listening TCP and UDP ports, as well as the corresponding process ID and process name.

Use the nmap command:

nmap is a network detection and security scanning tool that can also be used to query port information. You can query the port information of the specified IP address through the following command:

nmap -p <port> <ip>
Copy after login

where is the port number to be queried and is the IP address to be queried. This command will list the status information of the specified port on the specified IP address.

Using the /proc file system:

The /proc file system of the Linux system provides an interface for accessing kernel and process information, and can also be used to query port information. By accessing the /proc/net/tcp and /proc/net/udp files, you can query the detailed information of the currently listening TCP and UDP ports.

Summary:

The above are several common methods. You can choose the appropriate method to query port information according to actual needs. In actual use, netstat and lsof are the most commonly used commands, and they provide more comprehensive and intuitive port information. The ss and nmap commands provide more powerful and flexible functions and are suitable for more complex network environments and requirements. At the same time, some port information can also be obtained by accessing the /proc file system, but the file content needs to be parsed and processed.

The above is the detailed content of How to query the port in linux. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template