CentOS7中执行 service iptables start/stop
会出现iptables 找不到,一直都在Centos 6.x的环境中,发现这个问题挺尴尬的,
在CentOS 7或RHEL 7或Fedora中防火墙由firewalld来管理。
或则使用新的命令进行管理。

假如采用传统请执行一下命令:
systemctl stop firewalld
systemctl mask firewalld
并且安装iptables-services:
yum install iptables-services
systemctl enable iptables

iptables启动、关闭、保存:
systemctl [stop|start|restart] iptables
or
service iptables [stop|start|restart]
service iptables save
or
/usr/libexec/iptables/iptables.init save

如果要添加范围例外端口 如 1000-2000
语法命令如下:启用区域端口和协议组合
firewall-cmd [--zone=<zone>] --add-port=<port>[-<port>]/<protocol> [--timeout=<seconds>]
此举将启用端口和协议的组合。端口可以是一个单独的端口 <port> 或者是一个端口范围 <port>-<port> 。协议可以是 tcp 或 udp。
实际命令如下:
添加
firewall-cmd --zone=public --add-port=80/tcp --permanent (--permanent永久生效,没有此参数重启后失效)
firewall-cmd --zone=public --add-port=1000-2000/tcp --permanent
重新载入
firewall-cmd --reload
查看
firewall-cmd --zone= public --query-port=80/tcp
删除
firewall-cmd --zone= public --remove-port=80/tcp --permanent

标签: none

添加新评论