View port number usage in linux

View port number usage in linux

Use netstat command to view port number usage in linux

The command is as follows:

netstat -tunpl | grep 端口号

Example: View the usage of port 9999

$ netstat -tunpl | grep 9999
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 0.0.0.0:9999            0.0.0.0:*               LISTEN      2003/java 

Description:

(Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) means: (Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) Will show, you must be root to see all this.)

If the status is LISTEN, it means that the port number has been occupied and is being monitored

2003/java means it is occupied by the java program whose process number is 2003

After getting the process number, we can use the ps -ef|grep process number to see what program is occupying the port number

Example:

ps -ef|grep 2003

netstat

The Linux netstat command is used to display the network status.

Use the netstat command to let you know the network status of the Linux system.

Netstat parameter description:

-a或--all 显示所有连线中的Socket。
-A<网络类型>或--<网络类型> 列出该网络类型连线中的相关地址。
-c或--continuous 持续列出网络状态。
-C或--cache 显示路由器配置的快取信息。
-e或--extend 显示网络其他相关信息。
-F或--fib 显示FIB。
-g或--groups 显示多重广播功能群组组员名单。
-h或--help 在线帮助。
-i或--interfaces 显示网络界面信息表单。
-l或--listening 显示监控中的服务器的Socket。
-M或--masquerade 显示伪装的网络连线。
-n或--numeric 直接使用IP地址,而不通过域名服务器。
-N或--netlink或--symbolic 显示网络硬件外围设备的符号连接名称。
-o或--timers 显示计时器。
-p或--programs 显示正在使用Socket的程序识别码和程序名称。
-r或--route 显示Routing Table。
-s或--statistics 显示网络工作信息统计表。
-t或--tcp 显示TCP传输协议的连线状况。
-u或--udp 显示UDP传输协议的连线状况。
-v或--verbose 显示指令执行过程。
-V或--version 显示版本信息。
-w或--raw 显示RAW传输协议的连线状况。
-x或--unix 此参数的效果和指定"-A unix"参数相同。
--ip或--inet 此参数的效果和指定"-A inet"参数相同。

Some examples:

Find out which port the program is running on

#找出mysql的运行端口
netstat -ap | grep mysql

Display TCP connection information

netstat -pt

Display the usage of UDP port number

 netstat -apu

View the number of open threads under the process

netstat -anp | grep pid  (可加 |wc -l 统计行数) 

Note: netstat -p can be used with other parameters to display "PID/process name"

Guess you like

Origin blog.csdn.net/qq_36551991/article/details/109753843