CentOS 7 學習——firewalld

系統環境:

Linux localhost.localdomain 3.10.0-862.el7.x86_64 #1 SMP Fri Apr 20 16:44:24 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

已默認安裝了 firewall ,在CentOS7 中用來替換之前版本的 iptables

查看安裝版本: rpm -qa firewalld

firewalld-0.4.4.4-14.el7.noarch

引入了區組概念:

區組: 即分組權限,一個服務或端口,同一時刻只屬於一個分組

firewall-cmd --get-zones

firewall-cmd --get-default-zone

firewall-cmd --get-active-zones

fireall-cmd --list-all-zones : 查看所有區組配置

運行、停止、禁用firewalld

systemctl start firewalld # 啟動

systemctl status firewalld 或者 firewall-cmd --state # 查看狀態

CentOS 7 學習——firewalld

systemctl disable firewalld # 停止

systemctl stop firewalld # 禁用

CentOS 7 學習——firewalld

查看 firewalld 的狀態

常用的查看命令:

firewall-cmd --list-all --> 所有

firewall-cmd --list-ports --> 所有開放的端口

firewall-cmd --zone=public --list-ports --> 指定區組中開放的端口

開啟一個端口或服務

firewall-cmd --permanent --zone=public --add-port=80/tcp

CentOS 7 學習——firewalld

都添加了到指定的 public 區組,注意看ports項

[--permanent永久生效,沒有此參數重啟後失效]

[以下兩條是以服務的形式添加到Firewall,上面一條以端口/協議的形式添加]

firewall-cmd --permanent --zone=public --add-service=http

firewall-cmd --permanent --zone=public --add-service=https

CentOS 7 學習——firewalld

添加到public區組,注意查看 Services 項

如果添加的端口沒有對應的服務,即:自己定義的端口,則可複製 /usr/lib/firewalld/services 下的一個配置文件,修改裡面的對應內容即可

# short為服務名【自己定義】,方便閱讀,最重要的是修改 protocol和port,保存並重啟Firewall後[systemctl restart firewalld],即可添加

f

Transmission-client

Transmission is a lightweight GTK+ BitTorrent client.

對指定ip開放指定端口

[--add-rich-rule] ==> [--remove-rich-rule] 就可刪除規則

Postgresql端口設置:允許192.168.142.166訪問5432端口

firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.142.166" port protocol="tcp" port="5432" accept"

Redis端口設置:允許192.168.142.166訪問6379端口

firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.142.166" port protocol="tcp" port="6379" accept"

beanstalkd端口設置:允許192.168.142.166訪問11300端口

firewall-cmd --permanent --add-rich-rule="rule family='ipv4' source address='192.168.142.166' port protocol='tcp' port='11300' accept"

firewall-cmd --reload ==> 重新加載配置

firewall-cmd --zone=public --query-port=80/tcp ==> 查找指定端口

刪除指定端口或服務

firewall-cmd --zone=public --remove-port=80/tcp --permanent

firewall-cmd --permanent --remove-service=http

查看服務:

【一個服務對應一個端口,每個服務對應/usr/lib/firewalld/services下面一個xml文件】

firewall-cmd --list-services # 已打開

firewall-cmd --get-services # 可打開


分享到:


相關文章: