Four ways to query whether the Linux port is occupied


Usually the more familiar methods are netstat and lsof, but what else is there?

1.netstat or ss command

netstat -anlp | grep 80

2.lsof command

This command is to view which files the process occupies

lsof -i:80

3.fuser command

The fuser command is the opposite of lsof, which is to check which process a certain file is occupied. In Linux, everything is a file, so you can view ordinary files, socket files, and file systems. The socket file contains the port number. For example, view port 22.

fuser 22/tcp -v

USER PID ACCESS COMMAND

22/tcp: root 1329 F.... sshd

root 1606 f.... sshd

4.nmap tool

By default, nmap always scans ports. It is very convenient to scan the local port.

nmap localhost

Starting Nmap 5.51 ( http://nmap.org ) at 2018-03-03 18:00 CST

Nmap scan report for localhost (127.0.0.1)

Host is up (0.0000020s 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

Guess you like

Origin blog.csdn.net/hety119/article/details/88420923