導航:首頁 > 程序命令 > linux打開防火牆埠命令

linux打開防火牆埠命令

發布時間:2025-06-17 04:09:29

linux系統中查看防火牆以及開放埠號命令

在Linux系統中,查看防火牆以及開放埠號的命令如下:

查看防火牆狀態: 使用**systemctl status firewalld**命令可以查看防火牆的狀態。

管理防火牆服務: 啟動防火牆:**systemctl start firewalld** 關閉防火牆:**systemctl stop firewalld** 如果防火牆服務被屏蔽,需要先解除屏蔽:**systemctl unmask firewalld.service**,然後再啟動服務。

查看已開放的埠: 使用**firewallcmd zone=public listports**命令可以查詢當前防火牆區域已開放的埠列表。 使用**netstat apn | grep 埠號**命令可以查看指定埠是否正在監聽。 使用**firewallcmd queryport=埠號/協議**可以查詢指定埠是否開啟,返回**yes**表示開啟,返回**no**表示未打開。

這些命令是Linux系統中管理和控制防火牆、埠的重要工具,能夠幫助用戶有效地管理和監控系統的網路安全。

② Linux防火牆操作命令,開放或關閉埠

在外部訪問 CentOS 中部署應用時,需要通過防火牆管理軟體進行埠管理。以下是 CentOS 防火牆(firewalld)的常用命令和操作指南:

啟動防火牆:systemctl start firewalld

查看防火牆狀態:systemctl status firewalld

禁用防火牆,禁止開機啟動:systemctl disable firewalld

停止防火牆運行:systemctl stop firewalld

使用 firewall-cmd 命令配置防火牆:

開放埠:firewall-cmd --zone=public --add-port=80/tcp --permanent

查看已開放的埠:firewall-cmd --zone=public --list-ports

關閉埠:firewall-cmd --zone=public --remove-port=80/tcp --permanent

批量開放埠:firewall-cmd --zone=public --add-port=40000-45000/tcp --permanent

批量關閉埠:firewall-cmd --zone=public --remove-port=40000-45000/tcp --permanent

更新防火牆設置:firewall-cmd --reload

CentOS7 防火牆操作命令:

安裝防火牆:yum install firewalld

配置 firewall-cmd:

查看版本:firewall-cmd --version

查看幫助:firewall-cmd --help

顯示狀態:firewall-cmd --state

更新防火牆規則:firewall-cmd --reload

查看已激活的 Zone 信息:firewall-cmd --get-active-zones

信任級別和 Zone 的值指定:

drop: 丟棄所有進入的包,而不給出任何響應

block: 拒絕所有外部發起的連接,允許內部發起的連接

public: 允許指定的進入連接

external: 允許受限制的進入連接

dmz: 允許受限制的進入連接

work: 允許受信任的計算機被限制的進入連接

home: 允許受信任的計算機被限制的進入連接

internal: 允許受信任的計算機被限制的進入連接

trusted: 信任所有連接

開啟和關閉埠:

添加埠:firewall-cmd --zone=public --add-port=80/tcp --permanent

重新載入:firewall-cmd --reload

查看埠狀態:firewall-cmd --zone=public --query-port=80/tcp

刪除埠:firewall-cmd --zone=public --remove-port=80/tcp --permanent

管理服務:添加到 work zone

添加服務:firewall-cmd --zone=work --add-service=smtp

查看服務:firewall-cmd --zone=work --query-service=smtp

刪除服務:firewall-cmd --zone=work --remove-service=smtp

配置 IP 地址偽裝:

查看偽裝狀態:firewall-cmd --zone=external --query-masquerade

打開偽裝:firewall-cmd --zone=external --add-masquerade

關閉偽裝:firewall-cmd --zone=external --remove-masquerade

埠轉發:

打開埠轉發:firewall-cmd --zone=external --add-masquerade

轉發 tcp 22 埠至 3753:firewall-cmd --zone=external --add-forward-port=22:porto=tcp:toport=3753

轉發埠數據至另一個 IP 的相同埠:firewall-cmd --zone=external --add-forward-port=22:porto=tcp:toaddr=192.168.1.112

轉發埠數據至另一個 IP 的 3753 埠:firewall-cmd --zone=external --add-forward-port=22:porto=tcp:toport=3753:toaddr=192.168.1.112

使用 systemctl 管理服務:

啟動服務:systemctl start firewalld.service

關閉服務:systemctl stop firewalld.service

重啟服務:systemctl restart firewalld.service

顯示服務狀態:systemctl status firewalld.service

在開機時啟用服務:systemctl enable firewalld.service

在開機時禁用服務:systemctl disable firewalld.service

查看服務是否開機啟動:systemctl is-enabled firewalld.service

查看已啟動的服務列表:systemctl list-unit-files|grep enabled

查看啟動失敗的服務列表:systemctl --failed

③ linux查看防火牆埠

在Linux系統中,查看防火牆埠的方法如下:

  1. 打開終端

    • 在Linux桌面的空白處右擊,選擇「打開終端」。
  2. 查看防火牆埠狀態

    • 輸入命令 **sudo /etc/init.d/iptables status**,然後回車運行。
    • 此命令將顯示當前防火牆的規則,包括開放的埠和相關的配置信息。

注意: 使用sudo是為了確保有足夠的許可權來查看防火牆狀態。 不同的Linux發行版可能使用不同的防火牆管理工具,因此具體的查看命令可能有所不同。 如果使用的是ufw,則可以使用sudo ufw status verbose來查看詳細的防火牆狀態和開放的埠。

④ linux防火牆開放埠命令給指定ipCentOSLinux防火牆添加埠開放

首先可以查看有哪些埠是開放狀態:
netstat -ntplCentos 7.0 之前的版本,防火牆用的是 iptables,7.0 之後使用 firewalld 代替了 iptables,那麼我們來分別看看這兩種防火牆的命令操作:
iptables
1. 查看防火牆狀態
systemctl status firewalld
service iptables status
2. 暫時關閉防火牆
systemctl stop firewalld
service iptables stop
3. 永久關閉防火牆
systemctl disable firewalld
chkconfig iptables off
4. 重啟防火牆
systemctl enable firewalld
service iptables restart
5. 開放指定埠
編輯文件: vi /etc/sysconfig/iptables
添加開放埠:iptables -I INPUT -p tcp --dport 埠號 -j ACCEPT
保存配置:service iptables save
重啟防火牆:service iptables restart
firewalld
1. 查看防火牆狀態
systemctl status firewalld
firewall-cmd --state
2. 啟動防火牆
systemctl start firewalld
3.禁用防火牆
systemctl stop firewalld
4.設置開機啟動
systemctl enable firewalld
5.停止並禁用開機啟動
sytemctl disable firewalld
6.重啟防火牆
systemctl restart firewalld.service
firewall-cmd --reload
7. 開放指定埠
添加埠: firewall-cmd --zone=public --add-port=埠號/tcp --permanent
重啟防火牆:systemctl restart firewalld.service

閱讀全文

與linux打開防火牆埠命令相關的資料

熱點內容
粉筆常識考點一本通pdf 瀏覽:65
sdk如何防止反編譯 瀏覽:437
行跡app是哪裡的 瀏覽:479
visualc編譯無錯誤但運行停止 瀏覽:101
捕魚作弊源碼系統 瀏覽:274
在哪裡查住房公積金app 瀏覽:433
建立雲伺服器怎麼購買 瀏覽:498
免費文字識別app哪個好 瀏覽:447
重慶建行解壓多久拿到證 瀏覽:880
python數據收集項目 瀏覽:888
四川金稅盤安全接入伺服器地址 瀏覽:752
ERP如何換伺服器 瀏覽:739
騰訊底層程序員的條件 瀏覽:887
閃送app沒有商城是怎麼回事 瀏覽:363
編譯局成立周年 瀏覽:289
郵件怎麼壓縮成文件夾 瀏覽:727
哪個城市的程序員多 瀏覽:428
linuxphp配置路徑 瀏覽:999
伺服器arm什麼意思 瀏覽:561
3分土地是怎樣演算法 瀏覽:590