我用最少的配置安装了CentOS 7(os + dev工具).我正在尝试打开80端口进行httpd
服务,但是我的iptables服务有问题......它出了什么问题?我究竟做错了什么?
# ifconfig/sbin/service iptables save bash: ifconfig/sbin/service: No such file or directory # /sbin/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. # sudo service iptables status Redirecting to /bin/systemctl status iptables.service iptables.service Loaded: not-found (Reason: No such file or directory) Active: inactive (dead) # /sbin/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. # sudo service iptables start Redirecting to /bin/systemctl start iptables.service Failed to issue method call: Unit iptables.service failed to load: No such file or directory.
Sgaduuw.. 328
在RHEL 7/CentOS 7中,引入了firewalld来管理iptables.恕我直言,firewalld更适合工作站而不是服务器环境.
可以回到更经典的iptables设置.首先,停止并掩盖firewalld服务:
systemctl stop firewalld systemctl mask firewalld
然后,安装iptables-services包:
yum install iptables-services
在启动时启用服务:
systemctl enable iptables
管理服务
systemctl [stop|start|restart] iptables
保存防火墙规则可以按如下方式完成:
service iptables save
要么
/usr/libexec/iptables/iptables.init save
@Sgaduuw您能否详细说明为什么您认为fitewalld不适合服务器? (8认同)
它没有保存iptables.重新启动服务器会丢失所有更改. (5认同)
在我的系统上,iptables正确保存.你确定iptables服务是在启动时启动的吗?你可以通过运行'systemctl enable iptables'来做到这一点 (2认同)
Metal3d.. 95
RHEL和CentOS 7使用firewall-cmd而不是iptables.你应该使用那种命令:
# add ssh port as permanent opened port firewall-cmd --zone=public --add-port=22/tcp --permanent
然后,您可以重新加载规则以确保一切正常
firewall-cmd --reload
这比使用iptable-save更好,特别是如果你打算使用lxc或docker容器.启动docker服务将添加iptable-save命令将提示的一些规则.如果保存结果,则会有很多不应保存的规则.因为docker容器可以在下次重启时更改它们的ip地址.
具有永久选项的Firewall-cmd更适合这种情况.
检查"man firewall-cmd"或查看官方firewalld文档以查看选项.有很多选项可以检查区域,配置,它是如何工作的......手册页真的很完整.
我强烈建议不要使用自Centos 7以来的iptables-service