Introduction: In a Linux server, it is often necessary to see whether certain ports on the system are open properly, or to know which processes occupy a particular port service, so this command is very common, and this article describes the common methods of these commands.
1. See if a particular port is turned on or occupied
List all the TCP connections in the Listening state:
Command parsing:
-l list all listening ports
-N Displays the address and port number in digital form, without parsing the domain name and speeding up the display of the information.
-P shows the process that occupies the port number
-T lists connections for the TCP protocol
-A lists all connections for all sockets under all current connections, TCP, UDP, and UNIX protocols
-U lists UDP connections
For an example of whether to use domain name resolution for-N:
As you can see from the content,-n controls whether the domain name is displayed.
List all the TCP ports in the listening state
Netstat-alt
To find a process for a specific port:
To view the name or user ID of the owner:
Netstat-altep
Lists the user IDs that TCP belongs to in the current process
Netstat-altne
Here, if you will
- NAnd
- eoption, the properties of the user column are the ID numbers of the users, not the user names. Use
-epOption to view both the process name and the user name
-S lists the statistics of the Network information:
-R Lists Routing information
-I print out the network interface information, E and its collocation, can output more friendly information.
Output Network interface information:
Netstat-ie
2. lsof command
Command format: Lsof-i:p ort_number to find a process or command for a specific port
Lsof-i: 8010
3. How to find help information
In Linux, a powerful command man is provided to help us find the most comprehensive introductory information.
Mans netstat
4. Summary
Netstat is a very powerful command, it can provide most of the information needed, lsof is also a very useful tool, but under certain circumstances, lsof may not be able to find out, but Netstat can be queried.
Priority recommendation Nestat to query ports.
How to view the developed ports under the Linux system