1、firewall防火墙配置:
yum install firewalld #安装
systemctl start firewalld #启动
systemctl enable firewalld #设置开机启动
systemctl stop firewalld #关闭
systemctl disable firewalld #取消开机启动
2、端口控制策略:
firewall-cmd --zone=public --add-port=6379/tcp --permanent #开放6379端口
firewall-cmd --zone=public --remove-port=6379/tcp --permanet #删除6379端口
firewall-cmd --reload #配置立即生效
firewall-cmd --zone=public --list-ports #查看当前防火墙开放的端口
systemctl stop firewalld.service #关闭防火墙
firewall-cmd --state #查看防火墙状态
netstat -lnpt #查看端口开放状态
firewall-cmd --list-all #查看防火墙规则(只显示/etc/firewalld/zones/public.xml中防火墙策略)
firewall-cmd --list-all-zones #查看所有的防火墙策略(即显示/etc/firewalld/zones/下的所有策略)
firewall-cmd --reload #重新加载配置文件
#禁止IP(123.56.161.140)访问本机所有服务
firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address="123.56.161.140" drop'
#从防火墙中删除策略: 禁止机器IP(123.56.161.140)访问本机所有服务
firewall-cmd --permanent --remove-rich-rule='rule family=ipv4 source address="123.56.161.140" drop'
#禁止一个B类IP段地址访问本机,比如禁止123.56.*.*
firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address="123.56.0.0/16" drop'
#禁止一个C类IP段地址访问本机,比如禁止123.56.161.*
firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address="123.56.161.0/24" drop'
#允许http服务(对应服务策略目录:/usr/lib/firewalld/services/)
firewall-cmd --permanent --add-service=http
#关闭http服务(对应服务策略目录:/usr/lib/firewalld/services/)
firewall-cmd --permanent --remove-service=http
#允许端口:3389
firewall-cmd --permanent --add-port=3389/tcp
#关闭放行中端口:3389
firewall-cmd --permanent --remove-port=3389/tcp
#允许端口:1-3389
firewall-cmd --permanent --add-port=1-3389/tcp
#更改配置后一定要重新加载配置文件:
firewall-cmd --reload