1、启动防火墙[root@share ~]# systemctl start firewalld.service2、指定IP与端口[root@share ~]# firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.100.77" port protocol="tcp" port="5432" accept"指定多个端口(连续)[root@share ~]# firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.100.77" port protocol="tcp" port="13330-13339" accept"指定ip段可以访问[root@share ~]# firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.100.0/24" port protocol="tcp" port="5432" accept"3、重新载入,使配置生效[root@share ~]# firewall-cmd --reload4、查看配置结果[root@share ~]# firewall-cmd --list-all5、删除规则[root@share ~]# firewall-cmd --permanent --remove-rich-rule="rule family="ipv4" source address="192.168.100.77" port protocol="tcp" port="445" accept"CentOS 7.0默认使用的是firewall作为防火墙1、查看firewall服务状态systemctl status firewalld2、查看firewall的状态firewall-cmd --state3、开启、重启、关闭、firewalld.service服务#查看linux哪些程序正在使用互联网firewall-cmd --permanent --list-services ssh dhcpv6-client
开启
service firewalld start
重启
service firewalld restart
关闭
service firewalld stop4、查看防火墙规则firewall-cmd --list-all停止firewallsystemctl stop firewalld.service禁止firewall开机启动systemctl disable firewalld.service5、查询、开放、关闭端口
查询端口是否开放
firewall-cmd —query-port=8080/tcp
开放80端口
firewall-cmd —permanent —add-port=80/tcp
firewall-cmd —permanent —add-port=8080-8085/tcp
移除端口
firewall-cmd —permanent —remove-port=8080/tcp
查看防火墙的开放的端口
firewall-cmd —permanent —list-ports
重启防火墙(修改配置后要重启防火墙)
firewall-cmd —reload
参数解释
1、firwall-cmd:是Linux提供的操作firewall的一个工具;
2、—permanent:表示设置为持久;
3、—add-port:标识添加的端口;
常用命令配置白名单,限制指定ip只能访问服务器指定的端口和去掉开通的端口
#配置规则firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="指定的ip地址" port protocol="tcp" prot="指定的端口" accept"#配置所有端口都可以访问firewall-cmd --permanent --zone=public --add-port=8080/tcp#批量配置规则firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="指定的ip地址段(192.168.1.0/24)" port protocol="tcp" prot="指定的端口" accept"#reload配置生效firewall-cmd --reload#关闭端口firewall-cmd --zone=public --remove-port=80/tcp --permanent#批量添加区间端口firewall-cmd --zone=public --add-port=4400-4600/udp --permanent#查看防火墙排除端口firewall-cmd --permanent --list-port#查看所有开放的端口iptables -L -n
