Four Methods for querying whether a port is occupied in Linux
One interview question uses three different methods to check which process occupies 8080. The familiar methods are netstat and lsof, but what else can be done.
1. netstat or ss Command
Netstat-anlp | grep 80
2. lsof command
This command is used to view the files occupied by the process.
Lsof-I: 80
3. fuser command
The fuser command is the opposite of the lsof command to check which process occupies a file. In Linux, everything is a file, so you can view common files, socket files, and file systems. The socket file contains the port number. For example, check port 22.
Fuser 22/tcp-v
USER PID ACCESS COMMAND
22/tcp: root 1329 F... sshd
Root 1606 f... sshd
4. nmap Tool
Nmap always scans ports by default. It is very convenient to scan local ports.
Nmap localhost
Starting Nmap 5.51 (http://nmap.org) at CST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.0000020 s latency ).
Other addresses for localhost (not scanned): 127.0.0.1
Not shown: 998 closed ports
PORT STATE SERVICE
22/tcp open ssh
25/tcp open smtp
Nmap done: 1 IP address (1 host up) scanned in 0.06 seconds
Use the Netstat command to view the number of concurrent requests on the Web Server
Detailed status of the netstat command
This article permanently updates link: https://www.bkjia.com/Linux/2018-03/151170.htm