在CentOS7.0中默认使用firewall代替了iptables
service。虽然继续保留了iptables命令,但已经仅是名称相同而已。除非手动删除firewall,再安装iptables,否则不能继续使用以前的iptables配置方法。以下介绍的是firewall配置方法:

#cd /usr/lib/firewalld/services
//该目录中存放的是定义好的网络服务和端口参数,只用于参考,不能修改。这个目录中只定义了一部分通用网络服务。在该目录中没有定义的网络服务,也不必再增加相关xml定义,后续通过管理命令可以直接增加。

#cd /etc/firewalld/services/
//从上面目录中将需要使用的服务的xml文件拷至这个目录中,如果端口有变化则可以修改文件中的数值。

# Check firewall state.firewall-cmd –state# Check active zones.firewall-cmd –get-active-zones# Check current active services.firewall-cmd –get-service# Check services that will be active after next reload.firewall-cmd –get-service –permanent 查看firewall当前的配置信息,最后一个命令是查看写入配置文件的信息。
# # Set permanent and reload the runtime config.# firewall-cmd –permanent –zone=public –add-service=http# firewall-cmd –reload # firewall-cmd –permanent –zone=public –list-services 打开HTTP服务端口并写入配置文件 从配置文件中重载至运行环境中。
# firewall-cmd –permanent –zone=public –remove-service=https# firewall-cmd –reload 从已有配置中删除一个服务端口
# firewall-cmd –permanent –zone=public –add-port=8080-8081/tcp# firewall-cmd –reload# firewall-cmd –zone=public –list-ports8080-8081/tcp# firewall-cmd –permanent –zone=public –list-ports8080-8081/tcp## firewall-cmd –permanent –zone=public –remove-port=8080-8081/tcp# firewall-cmd –reload 打开或关闭一段TCP端口的方法,同理如果使用了其它非通用端口,那么也可以这么操作。
# firewall-cmd –permanent –zone=public –add-rich-rule=”rule family=”ipv4” \ source address=”192.168.0.4/24” service name=”http” accept” # firewall-cmd –permanent –zone=public –remove-rich-rule=”rule family=”ipv4” \ source address=”192.168.0.4/24” service name=”http” accept” The following command allows you to open/close HTTP access to a specific IP address.
最后编辑: kuteng  文档更新时间: 2021-12-02 09:11   作者:kuteng