Linux, 检查端口开放的七种方法
telnet
# yum -y install telnet # telnet 10.0.0.51 22 Trying 10.0.0.51... Connected to 10.0.0.51. Escape character is '^]'. SSH-2.0-OpenSSH_7.4 按ctrl+alt+]退出
2. nmap
# nmap -p 22 10.0.0.51 Starting Nmap 6.40 ( http://nmap.org ) at 2018-08-27 09:32 CST Nmap scan report for bogon (10.0.0.51) Host is up (0.000043s latency). PORT STATE SERVICE 22/tcp open ssh --> open即开放 Nmap done: 1 IP address (1 host up) scanned in 0.03 seconds
3. nc
# nc -z -v -n 10.0.0.51 22 Ncat: Version 7.50 ( https://nmap.org/ncat ) Ncat: Connected to 10.0.0.51:22. Ncat: 0 bytes sent, 0 bytes received in 0.03 seconds.
参数说明:
-z: 端口扫描模式
-v: 显示详细信息
-n: 以数字的形式显示,即不反向解析
4. tcping
# yum -y install tcping # tcping 10.0.0.51 22 10.0.0.51 port 22 open.
5.
echo >/dev/tcp/localhost/22 && echo "open"
6. netstat|ss
# ss -ltnp|grep -w 22 LISTEN 0 128 *:22 *:* users:(("sshd",pid=1210,fd=3)) LISTEN 0 128 :::22 :::* users:(("sshd",pid=1210,fd=4))
7. lsof
# lsof -i :22 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME sshd 1210 root 3u IPv4 20218 0t0 TCP *:ssh (LISTEN) sshd 1210 root 4u IPv6 20220 0t0 TCP *:ssh (LISTEN) sshd 23635 root 3u IPv4 188315 0t0 TCP bogon:ssh->bogon:acmsoda (ESTABLISHED) sshd 23789 root 3u IPv4 192038 0t0 TCP bogon:ssh->bogon:7238 (ESTABLISHED)