`

CentOS 7.0关闭默认防火墙启用iptables防火墙

 
阅读更多

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

1、安装iptable iptable-service

#先检查是否安装了iptables
service iptables status
#安装iptables
yum install -y iptables
#升级iptables(安装的最新版本则不需要)
yum update iptables 
#安装iptables-services
yum install iptables-services

2、禁用/停止自带的firewalld服务

#停止firewalld服务
systemctl stop firewalld
#禁用firewalld服务
systemctl mask firewalld

3、设置现有规则

#查看iptables现有规则
iptables -L -n
#先允许所有,不然有可能会杯具
iptables -P INPUT ACCEPT
#清空所有默认规则
iptables -F
#清空所有自定义规则
iptables -X
#所有计数器归0
iptables -Z
#允许来自于lo接口的数据包(本地访问)
iptables -A INPUT -i lo -j ACCEPT
#开放22端口
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
#开放21端口(FTP)
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
#开放80端口(HTTP)
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
#开放443端口(HTTPS)
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
#允许ping
iptables -A INPUT -p icmp --icmp-type 8 -j ACCEPT
#允许接受本机请求之后的返回数据 RELATED,是为FTP设置的
iptables -A INPUT -m state --state  RELATED,ESTABLISHED -j ACCEPT
#其他入站一律丢弃
iptables -P INPUT DROP
#所有出站一律绿灯
iptables -P OUTPUT ACCEPT
#所有转发一律丢弃
iptables -P FORWARD DROP

4、其他规则设定
#如果要添加内网ip信任(接受其所有TCP请求)
iptables -A INPUT -p tcp -s 45.96.174.68 -j ACCEPT
#过滤所有非以上规则的请求
iptables -P INPUT DROP
#要封停一个IP,使用下面这条命令:
iptables -I INPUT -s ***.***.***.*** -j DROP
#要解封一个IP,使用下面这条命令:
iptables -D INPUT -s ***.***.***.*** -j DROP

5、保存规则设定
#保存上述规则
service iptables save

6、开启iptables服务 
#注册iptables服务
#相当于以前的chkconfig iptables on
systemctl enable iptables.service
#开启服务
systemctl start iptables.service
#查看状态
systemctl status iptables.service
7、映射端口(如将mysql默认的3306端口映射成1306对外提供服务)

iptables -t mangle -I PREROUTING -p tcp --dport 1306 -j MARK --set-mark 883306 
iptables -t nat -I PREROUTING -p tcp --dport 1306 -j REDIRECT --to-ports 3306 
iptables -I INPUT -p tcp --dport 3306 -m mark --mark 883306 -j ACCEPT

分享到:
评论

相关推荐

    CentOS 7.0关闭默认防火墙启用iptables防火墙.docx

    CentOS 7.0关闭默认防火墙启用iptables防火墙.docx

    CentOS 7.0关闭默认防火墙启用iptables防火墙的设置方法

    主要介绍了CentOS 7.0关闭默认防火墙启用iptables防火墙的设置方法,需要的朋友可以参考下

    CentOS 7.0启用iptables防火墙.docx

    首先,由于 CentOS 7.0 默认使用 firewallD,所以在启用 iptables 之前,我们需要关闭 firewallD 服务。这可以通过以下两条命令完成: 1. `systemctl stop firewalld.service` - 此命令会立即停止 firewallD 服务。...

    Linux软防火墙ACL匹配的优化点.docx

    此外,我们还可以使用 CentOS 7.0 关闭默认防火墙启用 iptables 防火墙。 在优化 iptables 的性能时,我们需要注意的是,不要根据规章将规章分到一个组,而要以匹配元素为分组基准。这是因为匹配元素的数量是固定的...

    CentOS 7.0编译安装lnmp教程(Nginx1.6.0+MySQL5.6.19+PHP5.5.14)

    CentOS 7.0默认使用firewall,但我们将切换到iptables。执行以下命令关闭并禁用firewall: ```bash systemctl stop firewalld.service systemctl disable firewalld.service ``` 安装iptables服务,并编辑...

    虚拟机部署zabbix详细笔记

    - **关闭默认防火墙并启用iptables:** - 停止并禁用firewall服务。 - 安装iptables服务,并配置规则以允许必要的端口,如HTTP(80)、MySQL(3306)等。 - 关闭SELINUX,以避免安全策略限制导致的问题。 - **软件源...

    CentOS服务器部署指南1

    在本篇"CentOS服务器部署指南1"中,我们将探讨如何在CentOS操作系统上进行基本的服务器配置,包括防火墙设置、软件安装以及关键服务的启用。以下是对这些步骤的详细说明: 首先,我们来讨论防火墙设置。在CentOS中...

    centos主从同步

    CentOS 7使用firewalld,需要关闭firewalld并启用iptables,开放873端口以允许Rsync通信。 **二、Sersync配置(源服务器)** Sersync是一款针对Linux系统的实时增量文件同步工具,可以实现文件的实时监控和同步。...

    dubbo-zookeeper集群搭建

    4. **重启并启用iptables服务**: ```bash systemctl restart iptables.service systemctl enable iptables.service ``` #### 五、安装ZooKeeper集群 1. **解压ZooKeeper**: ```bash tar -zxvf zookeeper-...

Global site tag (gtag.js) - Google Analytics