1.使用nmap检测开放端口,可检测远程服务器
[root@localhost ~]# nmap localhost
Starting Nmap 6.40 ( http://nmap.org ) at 2020-06-09 01:40 CST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000023s 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 smtpNmap done: 1 IP address (1 host up) scanned in 2.01 seconds
2.使用netstat检测本地端口
[root@localhost ~]# netstat -tunlp
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:22 0.0.0.0:* LISTEN 6741/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 7053/master
tcp6 0 0 :::22 :::* LISTEN 6741/sshd
tcp6 0 0 ::1:25 :::* LISTEN 7053/master
udp 0 0 0.0.0.0:68 0.0.0.0:*3.使用lsof检测开放端口
[root@localhost ~]# lsof -i:22
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
sshd 6741 root 3u IPv4 37912 0t0 TCP *:ssh (LISTEN)
sshd 6741 root 4u IPv6 37914 0t0 TCP *:ssh (LISTEN)
sshd 17129 root 3u IPv4 48317 0t0 TCP localhost.localdomain:ssh->192.168.100.1:65379 (ESTABLISHED)4.使用netcat检测端口
[root@localhost ~]# nc -zv localhost 22
Ncat: Version 7.50 ( https://nmap.org/ncat )
Ncat: Connected to ::1:22.
Ncat: 0 bytes sent, 0 bytes received in 0.01 seconds.5.使用Telnet检测端口,只能检测TCP端口。telnet+ip/域名+端口
[root@localhost ~]# telnet localhost 22
Trying ::1...
Connected to localhost.
Escape character is '^]'.
SSH-2.0-OpenSSH_7.46.curl检测端口,curl +ip:端口
[root@localhost ~]# curl localhost:22
SSH-2.0-OpenSSH_7.4
Protocol mismatch.