一、防火牆 開啓、關閉、查看狀態
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
未完 —— 待續 !