阿里雲centos7防火牆

2021-09-19 11:31:48 字數 2874 閱讀 3170

從centos7開始,防火牆由iptables修改為firewall

使用方法:

centos 7 開始防火牆就採用firewall 而不再是 iptables

開啟某個埠

[root@localhost conf]# firewall-cmd --permanent --zone=public --add-port=埠號/tcp

關閉防火牆

[root@localhost conf]# systemctl stop firewalld

開啟防火牆

[root@localhost conf]# systemctl start firewalld

開機啟動

[root@localhost conf]# systemctl enable firewalld  

取消開機啟動

[root@localhost conf]# systemctl disable firewalld

$ firewall-cmd --help

1. 檢視規則

檢視執行狀態

$ firewall-cmd --state

檢視已被啟用的 zone 資訊

$ firewall-cmd --get-active-zones

public

inte***ces: eth0 eth1

檢視指定介面的 zone 資訊

$ firewall-cmd --get-zone-of-inte***ce=eth0

public

檢視指定級別的介面

$ firewall-cmd --zone=public --list-inte***ces

eth0

檢視指定級別的所有資訊,譬如 public

檢視所有級別被允許的資訊

$ firewall-cmd --get-service

檢視重啟後所有 zones 級別中被允許的服務,即永久放行的服務

$ firewall-cmd --get-service --permanent

# firewall-cmd --panic-on # 丟棄

# firewall-cmd --panic-off # 取消丟棄

$ firewall-cmd --query-panic # 檢視丟棄狀態

# firewall-cmd --reload # 更新規則,不重啟服務

# firewall-cmd --complete-reload # 更新規則,重啟服務

新增某介面至某信任等級,譬如新增 eth0 至 public,再永久生效

# firewall-cmd --zone=public --add-inte***ce=eth0 --permanent

設定 public 為預設的信任級別

# firewall-cmd --set-default-zone=public

a. 管理埠

列出 dmz 級別的被允許的進入埠

# firewall-cmd --zome=dmz --list-ports

允許 tcp 埠 8080 至 dmz 級別

# firewall-cmd --zone=dmz --add-port=8080/tcp

允許某範圍的 udp 埠至 public 級別,並永久生效

# firewall-cmd --zome=public --add-port=5060-5059/udp --permanent

b. 管理服務

新增 smtp 服務至 work zone

# firewall-cmd --zone=work --add-service=smtp

移除 work zone 中的 smtp 服務

# firewall-cmd --zone=work --remove-service=smtp

c. 配置 ip 位址偽裝

檢視# firewall-cmd --zone=external --query-masquerade

開啟偽裝

# firewall-cmd --zone=external --add-masquerade

關閉偽裝

# firewall-cmd --zone=external --remove-masquerade

d. 埠**

要開啟埠**,則需要先

# firewall-cmd --zone=external --add-masquerade

然後** tcp 22 埠至 3753

# firewall-cmd --zone=external --add-forward-port=port=22:proto=tcp:toport=3753

** 22 埠資料至另乙個 ip 的相同埠上

# firewall-cmd --zone=external --add-forward-port=port=22:proto=tcp:toaddr=192.168.1.100

** 22 埠資料至另一 ip 的 2055 埠上

# firewall-cmd --zone=external --add-forward-port=port=22:proto=tcp:toport=2055:toaddr=192.168.1.100

以上都是一些常用方法,更多高階方法,請參考:

centos7防火牆配置

centos7防火牆配置 centos7使用的是linux kernel 3.10.0的核心版本,新版的kernel核心已經有了防火牆netfilter,並且firewalld的使用效能更高,穩定性更好。centos7配置防火牆的兩種方法 一 使用xml配置檔案的方式配置 方法一cp usr lib...

Centos7 關閉防火牆

centos7 關閉防火牆 centos 7.0預設使用的是firewall作為防火牆,使用iptables必須重新設定一下 1 直接關閉防火牆 systemctl stop firewalld.service 停止firewall systemctl disable firewalld.servi...

Centos7 關閉防火牆

1 直接關閉防火牆 systemctl stop firewalld.service 停止firewall systemctl disable firewalld.service 禁止firewall開機啟動 2 設定 iptables service yum y install iptables ...