防火牆是保護伺服器、網路安全的重要工具,其可以限制網路訪問,控制協議和埠等等。一個好的防火牆設置可以有效的提高網路安全。在進行防火牆設置的時候,我們需要知道哪些埠是開放的,以便於對相應業務進行管理。接下來,我們將從幾個方面進行詳細介紹查看防火牆開放了哪些埠的方法。
一、防火牆如何開放埠
在進行查看防火牆開放埠之前,我們需要了解如何開放埠。下面是一些 CentOS 7 系統下防火牆命令的相關操作。
# 查看 iptables 狀態 sudo systemctl status iptables.service # 關閉 iptables sudo systemctl stop iptables.service # 禁止 iptables 開機啟動 sudo systemctl disable iptables.service # 開啟 iptables sudo systemctl start iptables.service # 允許埠 80 通過防火牆 sudo iptables -I INPUT -p tcp --dport 80 -j ACCEPT # 保存 iptables 設置 sudo iptables-save # CentOS 7 Firewall-cmd 命令 sudo firewall-cmd --state # 查看firewall-cmd狀態 sudo firewall-cmd --zone=public --add-port=80/tcp --permanent # 永久開放80埠 sudo firewall-cmd --reload #重新載入
二、查看Linux系統中防火牆開放的埠
Linux系統提供了一些命令和工具可以查看現有的防火牆規則,下面我們將一一介紹。
1. iptables 命令
iptables 命令可以列出所有防火牆規則,可以通過輸入以下命令在命令行窗口查看:iptables -L
。
$ sudo iptables -L Chain INPUT (policy ACCEPT) target prot opt source destination Chain FORWARD (policy ACCEPT) target prot opt source destination DOCKER-ISOLATION all -- anywhere anywhere DOCKER all -- anywhere anywhere ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED ACCEPT all -- anywhere anywhere REJECT all -- anywhere anywhere reject-with icmp-port-unreachable
2. netstat 命令
netstat 命令可以查看與本地系統建立連接的埠並列出詳細信息,可以通過輸入以下命令在命令行窗口查看: netstat -anp
。
$ sudo netstat -anp | grep LISTEN tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN - tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN - tcp 0 0 127.0.0.1:8000 0.0.0.0:* LISTEN - tcp6 0 0 :::80 :::* LISTEN -
3. ss 命令
ss 命令是 netstat 命令的替代品,可以顯示更多的詳細信息,可以通過輸入以下命令在命令行窗口查看:ss -lntup
。
$ sudo ss -lntup Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port tcp LISTEN 0 128 127.0.0.11%lo:53 0.0.0.0:* users:(("docker-proxy",pid=13943,fd=4)) tcp LISTEN 0 128 *:22 *:* users:(("sshd",pid=2735,fd=3)) tcp LISTEN 0 128 :::80 :::* users:(("httpd",pid=1070,fd=4),("httpd",pid=1069,fd=4),("httpd",pid=1068,fd=4),("httpd",pid=1067,fd=4),("httpd",pid=1066,fd=4),("httpd",pid=1065,fd=4))
三、查看防火牆開放埠
除了查看系統的防火牆設置埠,還有其他的一些方法可以查看防火牆開放埠。
1. nmap 命令
nmap 是一個網路掃描工具,通過掃描目標 IP 地址和埠,可以獲取防火牆上開放的埠,可以通過下列命令來查看:
$ sudo nmap -p- localhost Starting Nmap 7.60 ( https://nmap.org ) at 2018-04-22 12:15 CST Nmap scan report for localhost (127.0.0.1) Host is up (0.000024s latency). Not shown: 65533 closed ports PORT STATE SERVICE 22/tcp open ssh 25/tcp open smtp 80/tcp open http 8000/tcp open http-alt
2. telnet 命令
telnet 是一個遠程訪問工具,通過連接目標地址,可以獲取防火牆上開放TCP埠的情況。可以使用以下命令: telnet [rayjump.com](http://rayjump.com/)
,其中 [rayjump.com](http://rayjump.com/) 為域名, 為需要查看的埠。
$ telnet rayjump.com 22 Trying 192.168.1.1... Connected to rayjump.com. Escape character is '^]'. SSH-2.0-OpenSSH_7.4
3. 使用瀏覽器訪問埠服務
在訪問有開放埠的伺服器上,我們可以直接使用瀏覽器通過訪問相應的埠進行查看。
通過上述方法,我們就可以查看防火牆開放了哪些埠,並且對相應埠進行管理和配置。維護好企業的網路環境,提高相應的安全性,這就需要我們要有一個好的防火牆設置,提高網路安全性。
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/151550.html