1、telnet命令
格式: telnet ip 端口號
[root@centos7-127 ~]# telnet 192.168.87.128 22
Trying 192.168.87.128...
Connected to 192.168.87.128. # 表示端口已經開放
Escape character is '^]'.
SSH-2.0-OpenSSH_7.4
[root@centos7-127 ~]# telnet 192.168.87.128 8008
Trying 192.168.87.128...
telnet: connect to address 192.168.87.128: Connection refused # 表示端口未開放
2、nmap命令
格式: nmap ip -p 端口號
Starting Nmap 6.40 ( http://nmap.org ) at 2019-09-19 10:34 CST
Nmap scan report for centos7-128.cn (192.168.87.128)
Host is up (0.00028s latency). # 主機可通
PORT STATE SERVICE
80/tcp open http # 端口開放
MAC Address: 00:0C:29:0C:AE:01 (VMware)
Nmap done: 1 IP address (1 host up) scanned in 0.08 seconds
[root@centos7-127 ~]# nmap 192.168.87.128 -p 8080
Starting Nmap 6.40 ( http://nmap.org ) at 2019-09-19 10:34 CST
Nmap scan report for centos7-128.cn (192.168.87.128)
Host is up (0.00035s latency). # 主機可通
PORT STATE SERVICE
8080/tcp closed http-proxy # 端口關閉
MAC Address: 00:0C:29:0C:AE:01 (VMware)
Nmap done: 1 IP address (1 host up) scanned in 0.03 seconds
3、通過nc命令檢查
命令格式:nc -v ip 端口
[root@centos7-127 ~]# nc -v 192.168.87.128 80
Ncat: Version 7.50 ( https://nmap.org/ncat )
Ncat: Connected to 192.168.87.128:80. # 端口開放
^C
[root@centos7-127 ~]# nc -v 192.168.87.128 8080
Ncat: Version 7.50 ( https://nmap.org/ncat ) # 端口關閉
Ncat: Connection refused.
4、使用nc測試端口是否可用
需要測試端口的服務器啟動nc服務監聽端口
格式: nc -lp 端口
[root@centos7-128 ~]# nc -lp 8081
adfadfjla
測試的服務器使用nc命令連接,然后發送信息
格式: nc ip 端口
[root@centos7-128 ~]# nc 192.168.87.128 8081
adfadfjla
能收到信息,表示端口可用