检查 Linux 中的开放端口列表

netstat

~ ☺ # netstat -lnputg
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      11/nginx: master pr 
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      20/sshd             
tcp        0      0 0.0.0.0:8022            0.0.0.0:*               LISTEN      11/nginx: master pr 
tcp        0      0 127.0.0.11:40631        0.0.0.0:*               LISTEN      -                   
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      11/nginx: master pr 
udp        0      0 127.0.0.11:35276        0.0.0.0:*                           -                   
IPv6/IPv4 Group Memberships
Interface       RefCnt Group
--------------- ------ ---------------------
lo              1      224.0.0.1
eth0            1      224.0.0.1
lo              1      ff02::1
lo              1      ff01::1
sit0            1      ff02::1
sit0            1      ff01::1
eth0            1      ff02::1
eth0            1      ff01::1

ss

apt install iproute2

~ ☺ # ss -lnputa
Netid           State                Recv-Q            Send-Q                        Local Address:Port                          Peer Address:Port                                                      
udp             UNCONN               0                 0                                127.0.0.11:35276                              0.0.0.0:*                                                         
tcp             LISTEN               0                 0                                   0.0.0.0:80                                 0.0.0.0:*                users:(("nginx",pid=11,fd=15))           
tcp             LISTEN               0                 0                                   0.0.0.0:22                                 0.0.0.0:*                users:(("sshd",pid=20,fd=3))             
tcp             LISTEN               0                 0                                   0.0.0.0:8022                               0.0.0.0:*                users:(("nginx",pid=11,fd=14))           
tcp             LISTEN               0                 0                                127.0.0.11:40631                              0.0.0.0:*                                                         
tcp             LISTEN               0                 0                                   0.0.0.0:443                                0.0.0.0:*                users:(("nginx",pid=11,fd=16))           
tcp             TIME-WAIT            0                 0                                 127.0.0.1:49554                            127.0.0.1:80                                                        
tcp             ESTAB                0                 0                                 127.0.0.1:40362                            127.0.0.1:22                                                        
tcp             ESTAB                0                 0                                172.25.0.2:45306                       107.182.23.235:26695            users:(("ssh",pid=495,fd=3))             
tcp             ESTAB                0                 0                                172.25.0.2:8022                          192.168.99.1:49911                                                     
tcp             ESTAB                0                 0                                 127.0.0.1:22                               127.0.0.1:40362            users:(("sshd",pid=28711,fd=3)) 

nmap

~ ☺ # nmap -sTU -O localhost

Starting Nmap 7.60 ( https://nmap.org ) at 2019-04-17 10:39 CST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00028s latency).
Other addresses for localhost (not scanned): ::1
Not shown: 1996 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
80/tcp   open  http
443/tcp  open  https
8022/tcp open  oa-system
Device type: general purpose
Running: Linux 3.X
OS CPE: cpe:/o:linux:linux_kernel:3
OS details: Linux 3.7 - 3.10
Network Distance: 0 hops

OS detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 4.61 seconds

lsof

apt install lsof

~ ☺ # lsof -i
COMMAND   PID USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
nginx      11 root   14u  IPv4  726283      0t0  TCP *:8022 (LISTEN)
nginx      11 root   15u  IPv4  726284      0t0  TCP *:http (LISTEN)
nginx      11 root   16u  IPv4  726285      0t0  TCP *:https (LISTEN)
sshd       20 root    3u  IPv4  726409      0t0  TCP *:ssh (LISTEN)
ssh       495 root    3u  IPv4  733033      0t0  TCP dbe2ea4b15c3:45306->107.182.23.235:26695 (ESTABLISHED)
sshd    28711 root    3u  IPv4 2043787      0t0  TCP localhost:ssh->localhost:40362 (ESTABLISHED)

~ ☺ # lsof -i:443
COMMAND PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx    11 root   16u  IPv4 726285      0t0  TCP *:https (LISTEN)