admin管理员组

文章数量:1642341

一、检查防火墙是否开启的

systemctl start firewalld

systemctl status firewalld

systemctl stop firewalld

systemctl restart firewalld

systemctl disable firewalld.service //禁止开机自启动

systemctl enable firewalld.service //设置开机自启动

在开机时启用一个服务:systemctl enable firewalld.service

在开机时禁用一个服务:systemctl disable firewalld.service

查看服务是否开机启动:systemctl is-enabled firewalld.service

查看已启动的服务列表:systemctl list-unit-files|grep enabled

查看启动失败的服务列表:systemctl --failed

二、查看防火墙配置

firewall-cmd --state

firewall-cmd --list-all

在每次修改端口和服务后/etc/firewalld/zones/public.xml文件就会被修改,所以也可以在文件中之间修改,然后重新加载

使用命令实际也是在修改文件,需要重新加载才能生效。

三、开放某些端口

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

firewall-cmd --permanent --add-port=80-90/tcp

firewall-cmd --reload #重新加载防火墙配置才会起作用

//移出端口限制

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

//查看端口是否开放

firewall-cmd --query-port=6379/tcp

//查看所有开放的端口

firewall-cmd --zone=public --list-ports

四、开放某些IP地址可以访问

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

firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address=192.168.1.169 drop'

firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address=192.168.1.169/24 drop'

firewall-cmd --reload

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

firewall-cmd --reload

五、禁止指定IP访问本机8080端口

firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.1" port protocol="tcp" port="8080" reject'

六、防火墙生效WARNING: AllowZoneDrifting is enabled.

修改防火墙配置文件:

vim /etc/firewalld/firewalld.conf

AllowZoneDrifiting  , 把对应的值 yes  改为 no 

重启防护墙 即可

七、其他命令详解

firewall-cmd --permanent --zone=public --add-rich-rule=‘rule family=“ipv4” source address=“192.168.0.4/24” service name=“http” accept’ //设置某个ip访问某个服务

firewall-cmd --permanent --zone=public --remove-rich-rule=‘rule family=“ipv4” source address=“192.168.0.4/24” service name=“http” accept’ //删除配置

firewall-cmd --permanent --add-rich-rule ‘rule family=ipv4 source address=192.168.0.1/2 port port=80 protocol=tcp accept’ //设置某个ip访问某个端口

firewall-cmd --permanent --remove-rich-rule ‘rule family=ipv4 source address=192.168.0.1/2 port port=80 protocol=tcp accept’ //删除配置

firewall-cmd --query-masquerade # 检查是否允许伪装IP

firewall-cmd --add-masquerade # 允许防火墙伪装IP

firewall-cmd --remove-masquerade # 禁止防火墙伪装IP

firewall-cmd --add-forward-port=port=80:proto=tcp:toport=8080 # 将80端口的流量转发至8080

firewall-cmd --add-forward-port=proto=80:proto=tcp:toaddr=192.168.1.0.1 # 将80端口的流量转发至192.168.0.1

firewall-cmd --add-forward-port=proto=80:proto=tcp:toaddr=192.168.0.1:toport=8080 # 将80端口的流量转发至192.168.0.1的8080端口

本文标签: 防火墙操作firewalld