1、查看防火墙状态

Bash
systemctl status firewalld

2、开启防火墙

Bash
systemctl start firewalld

3、关闭防火墙

Bash
systemctl stop firewalld

4、设置开机启动

Bash
systemctl enable firewalld

5、禁止开机启动

Bash
systemctl disable firewalld

6、查看防火墙配置

Bash
firewall-cmd --state
firewall-cmd --list-all

7、查询端口是否开放

Bash
firewall-cmd --query-port=8080/tcp

8、允许80端口访问

Bash
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --reload    #重新加载防火墙配置才会起作用

9、移除80端口

Bash
firewall-cmd --permanent --remove-port=80/tcp
firewall-cmd --reload

10、允许某个端口段

Bash
firewall-cmd --permanent --zone=public --add-port=1000-2000/tcp
firewall-cmd --reload

11、允许某个IP访问,默认允许

Bash
firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address=192.168.1.169 accept'
firewall-cmd --reload

12、禁止某个IP访问

Bash
firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address=10.0.0.42 drop'
firewall-cmd --reload

13、允许某个IP访问某个端口

Bash
firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address=192.168.1.169 port protocol=tcp port=6379 accept'
firewall-cmd --reload

14、移除以上规则

Bash
firewall-cmd --permanent --remove-rich-rule='rule family="ipv4" source address="192.168.1.169" port port="6379" protocol="tcp" accept'
firewall-cmd --reload

15、允许某个IP段访问

Bash
firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address=10.0.0.0/24 accept'

16、重启防火墙

Bash
firewall-cmd --reload
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。