一、防火墻 開啟、關閉、查看狀態
1、開啟防火墻
[root@localhost ~]# systemctl start firewalld
2、關閉防火墻
[root@localhost ~]# systemctl stop firewalld
3、重啟防火墻
[root@localhost ~]# systemctl start firewalld
4、查看防火墻當下的狀態
[root@localhost ~]# systemctl status firewalld

5、開機自動啟用防火墻
[root@localhost ~]# systemctl enable firewalld

6、開機默認禁用防火墻
[root@localhost ~]# systemctl disable firewalld

7、查看防火墻開機 啟用/禁用 狀態
[root@localhost ~]# systemctl is-enabled firewalld

8、查看系統當前啟動服務的列表
[root@localhost ~]# systemctl list-unit-files|grep enabled

9、查看啟動失敗的服務列表
[root@localhost ~]# systemctl --failed

二、防火墻相關命令
1、查看防火墻版本
[root@localhost ~]# firewall-cmd --version

2、查看幫助
[root@localhost ~]# firewall-cmd --help

其余還有很多
3、查看示當前防火墻狀態
[root@localhost ~]# firewall-cmd --state

4、查看當前防火墻打開的所有端口
[root@localhost ~]# firewall-cmd --zone=public --list-ports
5、更新防火墻規則
[root@localhost ~]# firewall-cmd --reload

6、查看防火墻區域信息
[root@localhost ~]# firewall-cmd --get-active-zones

7、查看指定接口所屬區域
[root@localhost ~]# firewall-cmd --get-zone-of-interface=eth0

8、拒絕所有包 (慎用)
[root@localhost ~]# firewall-cmd --panic-on
9、取消 包拒絕狀態
[root@localhost ~]# firewall-cmd --panic-off

10、查看包的拒絕狀態
[root@localhost ~]# firewall-cmd --query-panic

三、firewall防火墻及端口設置
1、防火墻添加端口
[root@localhost ~]# firewall-cmd --zone=public(作用域) --add-port=80/tcp(端口和訪問類型) --permanent(永久生效)
2、添加80端口
[root@localhost ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent

(--permanent永久生效,沒有此參數重啟后失效)
3、重新載入防火墻配置
[root@localhost ~]# firewall-cmd --reload
4、查看指定端口狀態
[root@localhost ~]# firewall-cmd --zone= public --query-port=80/tcp

5、防火墻移除指定端口
[root@localhost ~]# firewall-cmd --zone=public --remove-port=80/tcp --permanent

6、檢查是否允許偽裝IP
[root@localhost ~]# firewall-cmd --query-masquerade

7、允許防火墻偽裝IP
[root@localhost ~]# firewall-cmd --add-masquerade

8、禁止防火墻偽裝IP
[root@localhost ~]# firewall-cmd --remove-masquerade

9、開放MySQL端口
[root@localhost ~]# firewall-cmd --add-service=mysql

10、阻止mysql端口
[root@localhost ~]# firewall-cmd --remove-service=mysql

11、查看開放的服務
[root@localhost ~]# firewall-cmd --list-services

12、開放通過tcp訪問3306
[root@localhost ~]# firewall-cmd --add-port=3306/tcp

13、阻止通過tcp訪問3306
[root@localhost ~]# firewall-cmd --remove-port=3306/tcp
14、開放通過udp訪問233

15、開放通過udp訪問233
[root@localhost ~]# firewall-cmd --add-port=233/udp

16、查看開放的端口
[root@localhost ~]# firewall-cmd --list-ports

17、端口轉發
(1)80端口轉發到8080(Tomcat的默認端口為8080),443轉發到8443(https配置的端口為8443)
[root@localhost ~]# firewall-cmd --add-forward-port=port=80:proto=tcp:toport=8080
[root@localhost ~]# firewall-cmd --add-forward-port=port=443:proto=tcp:toport=8443

(2)將80端口的流量轉發至192.168.11.11
[root@localhost ~]# firewall-cmd --add-forward-port=port=80:proto=tcp:toaddr=192.168.11.11

(3)將80端口的流量轉發至192.168.11.11的8080端口
[root@localhost ~]# firewall-cmd --add-forward-port=port=80:proto=tcp:toaddr=192.168.11.11:toport=8080

未完 —— 待續 !
本文摘自博客