redhat7 防火墙设置
查看防火墙的状态
# firewall-cmd --state
running
# systemctl stop firewalld //关闭防火墙服务
# systemctl start firewalld //开启防火墙服务
# firewall-cmd --list-all
public (default, active)
interfaces: eno16777736
sources:
services: dhcpv6-client ssh
ports:
masquerade: no
forward-ports:
icmp-blocks:
rich rules:
查看某服务是否开启
# firewall-cmd --query-service ftp
yes
# firewall-cmd --query-service ssh
yes
# firewall-cmd --query-service samba
no
# firewall-cmd --query-service http
no
开启关闭服务端口
暂时开放 ftp 服務
# firewall-cmd --add-service=ftp
永久开放 ftp 服務
# firewall-cmd --add-service=ftp --permanent
永久关闭
# firewall-cmd --remove-service=ftp --permanent
success
重启一下
# systemctl restart firewalld
检查设置是否生效
# iptables -L -n | grep 21
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:21 ctstate NEW
设置特殊端口开放
# firewall-cmd --add-port=3128/tcp
# firewall-cmd --list-all
public (default)
interfaces:
sources:
services: dhcpv6-client ftp ssh
ports: 3128/tcp
masquerade: no
forward-ports:
icmp-blocks:
rich rules:
控制IP段访问
#firewall-cmd --list-all 查看 默认是允许所有的访问
#firewall-cmd --permanent --remove-service=ssh 禁掉
#firewall-cmd --permanent --add-rich-rule 'rule service name=ssh family=ipv4 source address=192.168.1.0/24 accept' 允许访问
#firewall-cmd --permanent --add-rich-rule 'rule service name=ssh family=ipv4 source address=192.168.2.0/24 reject' 拒绝访问
#firewall-cmd --reload 重启一下
# firewall-cmd --list-all 在看一下变化。
#firewall-cmd --permanent --remove-rich-rule 'rule service name=ssh family=ipv4 source address=192.168.1.0/24 accept' 删除策略
图形界面配置