mysql 防火墙配置文件_远程登录mysql的iptables防火墙配置

本文介绍了如何在CentOS7系统中停用firewalld并启用iptables防火墙,详细步骤包括安装iptables,编辑防火墙配置文件以开放3306端口,以及设置iptables为开机启动,确保远程MySQL连接的畅通。
摘要由CSDN通过智能技术生成

CentOS7默认的防火墙不是iptables,而是firewalld

#停止firewalld服务

systemctl stop firewalld

#禁用firewalld服务

systemctl mask firewalld

开启

systemctl unmask firewalld

关于firewalld的一些命令

启动

[root@excelib.com ~]# systemctl start firewalld

停止

[root@excelib.com ~]# systemctl stop firewalld

重启

[root@excelib.com ~]# systemctl restart firewalld

查询状态

[root@excelib.com ~]$ systemctl status firewalld

另外,对于firewalld来说还可以使用自身的firewall-cmd工具来查询运行状态

[root@excelib.com ~]$ firewall-cmd --state

CentOS7 安装iptables防火墙和配置

一)、关闭,禁用系统默认的firewall防火墙

# 停止firewall

systemctl stop firewalld.service

# 禁止firewall开机自启

systemctl disable firewalld.service

二)、安装iptables防火墙

1)、先检查是否安装了iptables

service iptables status

2)、安装iptables

yum install -y iptables

3)、升级iptables

yum update iptables

4)、安装iptables-services

yum install iptables-services

检查是否安装成功

systemctl status iptables

启动防火墙命令:systemctl start iptables.service

5)、编辑防火墙文件

vim /etc/sysconfig/iptables

# 添加80和3306端口,推荐使用vim快捷键yy(复制当前行),p(粘贴)

-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT

-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT

6)、重启防火墙使配置文件生效

systemctl restart iptables.service

7)、设置iptables防火墙为开机自启

systemctl enable iptables.service

关闭SELINUX

命令:vi /etc/selinux/config

bb3e722fc4df5b98aa68b7de9884ee56.png

保存

命令:ESC :wq

二、命令

2.1、系统命令

systemctl start iptables #启动

systemctl status iptables #查看运行状态

systemctl restart iptables.service #重启

systemctl stop iptables.service #停止

systemctl enable iptables.service #设置开机启动

systemctl disable iptables.service #禁止开机启动

2.2、常用命令

iptables -h #查询帮助

iptables -L -n #列出(filter表)所有规则

iptables -L -n --line-number #列出(filter表)所有规则,带编号

iptables -L -n -t nat #列出(nat表)所有规则

iptables -F #清除(filter表)中所有规则

iptables -F -t nat #清除(nat表)中所有规则

service iptables save #保存配置(保存配置后必须重启iptables)

systemctl restart iptables.service #重启

三、语法

3.1、filter表解析

filter表是iptables默认使用的表,负责对流入、流出本机的数据包进行过滤,该表中定义了3个链,分别是:INPUT、OUTPUT、FORWARD

INPUT:过滤进入主机的数据包

OUTPUT:处理从本机出去的数据包

FORWARD:负责转发流经本机但不进入本机的数据包,起到转发作用

3.2、iptables常用语法

-A:追加到规则的最后一条

-D:删除记录

-I:添加到规则的第一条

-p:(proto)规定通信协议,常见的协议有:tcp、udp、icmp、all

-j:(jump)指定要跳转的目标,常见的目标有:ACCEPT(接收数据包)、DROP(丢弃数据包)、REJECT(重定向)三种,但是一般不适用重定向,会带来安全隐患

四、常见案例

4.1、IP过滤

4.1.1、禁止192.168.1.3 IP地址的所有类型数据接入

iptables -A INPUT ! -s 192.168.1.3 -j DROP

4.2、开放端口

4.2.1、开放端口

iptables -A INPUT -p tcp --dport 80 -j ACCEPT #开放80端口

4.2.2、开放端口范围

iptables -I INPUT -p tcp --dport 22:80 -j ACCEPT #开发22-80范围的端口

4.2.3、不允许80端口流出

iptables -I OUTPUT -p tcp --dport 80 -j DROP

————————————————

版权声明:本文为CSDN博主「???^_^12138」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。

原文链接:https://blog.csdn.net/qzc70919700/article/details/79784566

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值