Centos7防火墙配置详解( 四 )

 

Centos7防火墙配置详解

文章插图
 
04-5
查看允许协议
firewall-cmd --list-protocols04-6
开启,关闭,查询端口
# 查询端口是否开放 firewall-cmd --query-port=80/tcp 
Centos7防火墙配置详解

文章插图
 
命令规则:
–permanent:表示永久生效,若没有重启失效;
– zone :表示作用域
–add-port=80/tcp 表示添加端口,格式为端口/通讯协议
开启端口的关键字:add
移除的关键字:remove
#永久增加/开启80端口 firewall-cmd --permanent --add-port=80/tcp firewall-cmd --permanent --add-port=443/tcp firewall-cmd --add-port=8080/tcp#重启防火墙服务 systemctl restart firewalld#删除端口 firewall-cmd --remove-port=8080/tcp 
Centos7防火墙配置详解

文章插图
 
05、防火墙IP限制配置:
05-1
允许指定IP访问所有流量
允许ip访问的关键字:accept
阻止ip访问的关键字:drop
#开启192.168.43.88访问 firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.43.100" accept"#重启防火墙服务firewall-cmd --reload#禁止192.168.43.88访问firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.43.100" drop"05-2
允许指定IP访问指定端口
# 允许IPV4 Ip是8.8.8.8 连接端口80 accept表示允许使用 firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="8.8.8.8" port protocol="tcp" port="80" accept"# 允许IPV4 Ip是10.168.186.25 连接端口22 accept表示允许使用firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="10.168.186.25" port protocol="tcp" port="22" accept"firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="10.168.186.25,10.168.186.211" port protocol="tcp" port="3306" accept"firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="10.168.186.0/24" port protocol="tcp" port="22" accept"# 以上运行完后提示success则表示配置成功05-3
允许指定IP访问指定协议
#阻止ICMP包 firewall-cmd--permanent --add-rich-rule="rule protocol value=https://www.isolves.com/it/aq/rj/2023-03-02/"icmp" drop"#允许特定地址通过icmpfirewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="120.12.23.136" protocol value="icmp" accept"05-4
允许指定IP访问指定服务
#允许特定地址可以访问SSH服务 firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="10.168.186.25" service name="ssh" accept"05-5
防火墙移除某个服务
firewall-cmd --remove-rich-rule="rule family="ipv4" source address="10.168.186.25" service name="ssh" drop"#从允许通过防火墙的列表里移除SSH服务 sudo firewall-cmd --remove-service=ssh --permanentfirewall-cmd --remove-rich-rule="rule protocol value=https://www.isolves.com/it/aq/rj/2023-03-02/"icmp" drop" --permanent05-6
xml方式查看所有规则--对应zone的xml文件中查看规则
cat /etc/firewalld/zones/public.xml
Centos7防火墙配置详解

文章插图




推荐阅读