Linux checks the service port number, checks the port (netstat, lsof)
netstat - atulnp will display all ports and all corresponding programs, and use the grep pipeline to filter out the desired fields
-a: all, means to list all connections, service monitoring, Socket information
-t: tcp, to list the services of the tcp protocol
-u: udp, to list the services of the udp protocol
-n: port number, to display with the port number
-l: listening, list the current listening services
-p: program, list the PID of the service program
Proto: network transmission protocol, mainly tcp and udpLocal Address: local ip:portForeign Address: remote host's ip:portState: connection status, mainly including monitoring (LISTEN) and establishment (ESTABLISED) PID: service process number Program name :service name
Check the occupancy of a certain port: lsof -i: port number
How to check the port in Linux
Method 1: lsof -i: port number is used to check the occupancy of a certain port, for example, to check the usage of port 9092, lsof -i:9095
can See that port 9095 has been occupied by nginx
Example:
lsof -i:22220
Method 2: netstat -tunlp | grep port number, used to view the process of the specified port number, such as viewing the situation of port 5050, netstat -tunlp | grep 5050
-t (tcp) only displays tcp related options
-u (udp) Only display udp-related options
-n Refuse to display aliases, and convert all numbers that can be displayed into numbers
-l Only list the service status in Listen (monitoring)
-p Display the name of the program that establishes the relevant link
Example:
netstat -tunlp |grep 22220
Query the PID number of the service through the above two methods
Query the corresponding service through the ps command
ps -ef |grep 87254
Count the number of connections on port 80
netstat -nat|grep -i "80"|wc -l
Examples are as follows: