远程登陆mysql的iptables防火墙配置

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

#中止firewalld服务vim

systemctl stop firewalld安全

#禁用firewalld服务tcp

systemctl mask firewalld工具

开启spa

systemctl unmask firewalld.net

关于firewalld的一些命令rest

启动excel

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

中止

 [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

保存

命令:ESC :wq

 

2、命令
2.一、系统命令
systemctl start iptables #启动

systemctl status iptables #查看运行状态

systemctl restart iptables.service #重启

systemctl stop iptables.service #中止

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

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

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、语法
3.一、filter表解析
    filter表是iptables默认使用的表,负责对流入、流出本机的数据包进行过滤,该表中定义了3个链,分别是:INPUT、OUTPUT、FORWARD

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

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

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

3.二、iptables经常使用语法
-A:追加到规则的最后一条

-D:删除记录

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

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

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

4、常见案例
4.一、IP过滤
4.1.一、禁止192.168.1.3 IP地址的全部类型数据接入
iptables -A INPUT ! -s 192.168.1.3 -j DROP

4.二、开放端口
4.2.一、开放端口
iptables -A INPUT -p tcp --dport 80 -j ACCEPT #开放80端口

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

4.2.三、不容许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

相关文章
相关标签/搜索