Checking method: 1. Use the lsof command to check, the syntax is "sudo lsof -i -P -n | grep LISTEN" or "doas lsof -i -P -n | grep LISTEN"; 2. Use the netstat command To check the listening port and program, the syntax is "netstat -tulpn | grep LISTEN"; 3. Use the nmap command to check, the syntax is "sudo nmap -sT -O localhost".
#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.
How to check the programs and listening ports in Linux
1. Open a terminal, such as a shell command window.
2. Run any of the following commands:
sudo lsof -i -P -n | grep LISTEN sudo netstat -tulpn | grep LISTEN sudo nmap -sTU -O IP地址
Method 1: lsof command
The syntax is as follows:
$ sudo lsof -i -P -n $ sudo lsof -i -P -n | grep LISTEN $ doas lsof -i -P -n | grep LISTEN ### OpenBSD
The output is as follows :
Look carefully at the last line of the above output:
sshd 85379 root 3u IPv4 0xffff80000039e000 0t0 TCP 10.86.128.138:22 (LISTEN)
sshd
is a program The name
10.86.128.138
is the IP address of the sshd program binding (LISTEN)
22
is the TCP port being used (LISTEN)
##85379 is the process ID (PID) of the sshd task
Method 2: netstat command
You can use netstat as shown below to check the listening ports and programs. Netstat syntax in Linux$ netstat -tulpn | grep LISTEN
$ netstat -anp tcp | grep LISTEN $ netstat -anp udp | grep LISTEN
$ netstat -na -f inet | grep LISTEN $ netstat -nat | grep LISTEN
netstat -bano | more netstat -bano | grep LISTENING netstat -bano | findstr /R /C:"[LISTING]"
Method 3: nmap command
The syntax is as follows:$ sudo nmap -sT -O localhost $ sudo nmap -sU -O 192.168.2.13 ### 列出打开的 UDP 端口 $ sudo nmap -sT -O 192.168.2.13 ### 列出打开的 TCP 端口
$ sudo nmap -sTU -O 192.168.2.13
Linux Video Tutorial"
The above is the detailed content of How to check programs and listening ports in Linux. For more information, please follow other related articles on the PHP Chinese website!