linux查看開放埠的方法:1、使用rpm安裝nmap工具,執行「nmap 127.0.0.1」指令即可查看本機開放的連接埠;2、執行「netstat -anp」指令進行檢視開放的連接埠。
本教學操作環境:linux5.9.8系統、Dell G3電腦。
##1:nmap工具偵測開放埠
nmap是一款網路掃描和主機偵測的工具。 nmap的安裝非常簡單,如下所示rpm安裝所示。[root@DB-Server Server]# rpm -ivh nmap-4.11-1.1.x86_64.rpm warning: nmap-4.11-1.1.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 37017186 Preparing... ########################################### [100%] 1:nmap ########################################### [100%] [root@DB-Server Server]# rpm -ivh nmap-frontend-4.11-1.1.x86_64.rpm warning: nmap-frontend-4.11-1.1.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 37017186 Preparing... ########################################### [100%] 1:nmap-frontend ########################################### [100%] [root@DB-Server Server]#
[root@DB-Server Server]# nmap 127.0.0.1 Starting Nmap 4.11 ( http://www.insecure.org/nmap/ ) at 2016-06-22 15:46 CST Interesting ports on localhost.localdomain (127.0.0.1): Not shown: 1674 closed ports PORT STATE SERVICE 22/tcp open ssh 25/tcp open smtp 111/tcp open rpcbind 631/tcp open ipp 1011/tcp open unknown 3306/tcp open mysql Nmap finished: 1 IP address (1 host up) scanned in 0.089 seconds You have new mail in /var/spool/mail/root [root@DB-Server Server]#
2:netstat 工具偵測開放埠
可以透過" netstat -anp" 來查看哪些連接埠已開啟。
擴充功能:偵測連接埠是否開放
##lsof 工具偵測開放埠[root@DB-Server Server]# service mysql start
Starting MySQL......[ OK ]
[root@DB-Server Server]# lsof -i:3306
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
mysqld 7860 mysql 15u IPv6 44714 TCP *:mysql (LISTEN)
[root@DB-Server Server]# service mysql stop
Shutting down MySQL..[ OK ]
[root@DB-Server Server]# lsof -i:3306
[root@DB-Server Server]#
[root@DB-Server Server]# lsof -i TCP| fgrep LISTEN cupsd 3153 root 4u IPv4 9115 TCP localhost.localdomain:ipp (LISTEN) portmap 3761 rpc 4u IPv4 10284 TCP *:sunrpc (LISTEN) rpc.statd 3797 rpcuser 7u IPv4 10489 TCP *:1011 (LISTEN) sshd 4020 root 3u IPv6 12791 TCP *:ssh (LISTEN) sendmail 4042 root 4u IPv4 12876 TCP localhost.localdomain:smtp (LISTEN)
伺服器連接埠即使處於監聽狀態,但是防火牆iptables屏蔽了該端口,是無法透過該方法檢測端口是否開放的。
[root@DB-Server ~]# nc -vv 192.168.42.128 1521
Connection to 192.168.42.128 1521 port [tcp/ncube-lm] succeeded!
[root@DB-Server ~]# nc -z 192.168.42.128 1521; echo $?
Connection to 192.168.42.128 1521 port [tcp/ncube-lm] succeeded!
0
[root@DB-Server ~]# nc -vv 192.168.42.128 1433
nc: connect to 192.168.42.128 port 1433 (tcp) failed: No route to host
以上是linux怎麼查看開放了哪些端口的詳細內容。更多資訊請關注PHP中文網其他相關文章!