service iptables save失败(CentOS7的新防火墙firewalld)
1 2 |
#service iptables save The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl. |
上面是在CentOS7中运行iptables规则保存的命令的时候产生的错误。
原因就是在RHEL7/CentOS7中,使用了新的 firewalld 来管理原来的iptables。7里面现在有有几种防火墙共存:firewalld、iptables、ebtables,默认使用firewalld来管理netfilter子系统,不过底层调用的命令仍然是iptables等。
先解决上面的问题,设置回经典的iptables:(这里我没有尝试,搬运自StackOverflow)
1 2 |
systemctl stop firewalld systemctl mask firewalld |
安装原来的iptables-services:
1 |
yum install iptables-services |
开机启动其服务:
1 |
systemctl enable iptables |
使用以下命令管理此服务:(其实这里systemctl也是新的管理工具,大概是service和chkcofig两个命令的集成)
1 |
systemctl [stop|start|restart] iptables |
然后就可以使用之前的保存命令
1 2 3 |
service iptables save #或者 /usr/libexec/iptables/iptables.init save |
但是!
有更好的选择为什么还要用回旧的呢?作为CentOS7的一大特性,拥有动态更新、zone功能,还有图形界面(真相如下),用新的用新的~
还是先解决之前的问题,在firewalld中,开放一个新端口:
1 |
firewall-cmd --zone=public --add-port=6379/tcp |
上面那条依旧是临时的,要使之永久生效还需要加上–permanent 选项
1 2 |
firewall-cmd --zone=public --add-port=6379/tcp --permanent firewall-cmd --reload #更新防火墙规则 |
再试试连接redis就可以连接上了。上面是用了firewalld的命令行设置,当然也可以在图形界面中设置,这里就不演示了。
扩展阅读:
—EOF—