如何在 centos 7 上使用 iptables? [英] How can I use iptables on centos 7?
问题描述
我以最少的配置(操作系统 + 开发工具)安装了 CentOS 7.我正在尝试为 httpd
服务打开 80 端口,但是我的 iptables 服务出了点问题……有什么问题吗?我究竟做错了什么?
I installed CentOS 7 with minimal configuration (os + dev tools). I am trying to open 80 port for httpd
service, but something wrong with my iptables service ... what's wrong with it? What am I doing wrong?
# 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.
推荐答案
使用 RHEL 7/CentOS 7,firewalld 被引入来管理 iptables.恕我直言,firewalld 更适合工作站而不是服务器环境.
With RHEL 7 / CentOS 7, firewalld was introduced to manage iptables. IMHO, firewalld is more suited for workstations than for server environments.
可以回到更经典的 iptables 设置.首先,停止并屏蔽firewalld服务:
It is possible to go back to a more classic iptables setup. First, stop and mask the firewalld service:
systemctl stop firewalld
systemctl mask firewalld
然后,安装 iptables-services 包:
Then, install the iptables-services package:
yum install iptables-services
在启动时启用服务:
systemctl enable iptables
管理服务
systemctl [stop|start|restart] iptables
可以按如下方式保存防火墙规则:
Saving your firewall rules can be done as follows:
service iptables save
或
/usr/libexec/iptables/iptables.init save
这篇关于如何在 centos 7 上使用 iptables?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!