当前位置: > CentOS > CentOS教程 >

CentOS 7 防火墙设置

时间:2019-01-14 17:22来源:linux.it.net.cn 作者:IT
我在CentOS 7系统下配置防火墙时跳了一些坑,想着写篇博客记录下来,让自己以后可以看看曾经踩过的坑(跳过一次就不要再跳了)。
服务器内没有默认安装iptables服务怎么办?
只能自己去配置了,下面记录详细的配置过程。
首先需要做的时把原先默认的firewalld服务干掉,输入以下指令:

step1:停止并屏蔽firewalld服务
systemctl stop firewalld
systemctl mask firewalld

step2:安装iptables-services软件包
yum install iptables-services

step3:在引导时启用iptables服务
systemctl enable iptables

step4:启动iptables服务
systemctl start iptables

step5:保存防火墙规则
service iptables save或/usr/libexec/iptables/iptables.init save

step6:管理iptables服务
systemctl [stop|start|restart] iptables

经过以上步骤,iptables服务总算安装好了,下面就是在其配置文件内开放需要外部访问的服务端口。

打开iptables配置文件,可以看到如下内容:

# Generated by iptables-save v1.4.7 on Wed Oct 18 22:10:14 2017
*filter
:INPUT ACCEPT [31:2692]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [35:4359]
-A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 8081 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 8082 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 21 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 3690 -j ACCEPT
COMMIT
# Completed on Wed Oct 18 22:10:14 2017

-A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT的含义就是开放3306端口给外部访问,也就是外部可以访问本机的mysqld服务了。

-A INPUT -p tcp -m tcp --dport xxxx -j ACCEPT其中xxxx就是外部可以访问的本机的服务端口号。




(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容