CentOS之——CentOS7安装iptables防火墙
转载请注明出处:http://blog.csdn.net/l1028386804/article/details/50779761
CentOS7默认的防火墙不是iptables,而是firewalle.
安装iptable iptable-service
- #先检查是否安装了iptables
- service iptables status
- #安装iptables
- yum install -y iptables
- #升级iptables
- yum update iptables
- #安装iptables-services
- yum install iptables-services
#先检查是否安装了iptables
service iptables status
#安装iptables
yum install -y iptables
#升级iptables
yum update iptables
#安装iptables-services
yum install iptables-services
禁用/停止自带的firewalld服务
- #停止firewalld服务
- systemctl stop firewalld
- #禁用firewalld服务
- systemctl mask firewalld
#停止firewalld服务
systemctl stop firewalld
#禁用firewalld服务
systemctl mask firewalld
设置现有规则
- #查看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
#查看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
其他规则设定
- #如果要添加内网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
#如果要添加内网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
保存规则设定
- #保存上述规则
- service iptables save
#保存上述规则
service iptables save
开启iptables服务
- #注册iptables服务
- #相当于以前的chkconfig iptables on
- systemctl enable iptables.service
- #开启服务
- systemctl start iptables.service
- #查看状态
- systemctl status iptables.service
#注册iptables服务
#相当于以前的chkconfig iptables on
systemctl enable iptables.service
#开启服务
systemctl start iptables.service
#查看状态
systemctl status iptables.service
解决vsftpd在iptables开启后,无法使用被动模式的问题
1.首先在/etc/sysconfig/iptables-config中修改或者添加以下内容
- #添加以下内容,注意顺序不能调换
- IPTABLES_MODULES="ip_conntrack_ftp"
- IPTABLES_MODULES="ip_nat_ftp"
#添加以下内容,注意顺序不能调换
IPTABLES_MODULES="ip_conntrack_ftp"
IPTABLES_MODULES="ip_nat_ftp"
2.重新设置iptables设置
- iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
以下为完整设置脚本
- #!/bin/sh
- iptables -P INPUT ACCEPT
- iptables -F
- iptables -X
- iptables -Z
- iptables -A INPUT -i lo -j ACCEPT
- iptables -A INPUT -p tcp --dport 22 -j ACCEPT
- iptables -A INPUT -p tcp --dport 21 -j ACCEPT
- iptables -A INPUT -p tcp --dport 80 -j ACCEPT
- iptables -A INPUT -p tcp --dport 443 -j ACCEPT
- iptables -A INPUT -p icmp --icmp-type 8 -j ACCEPT
- iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
- iptables -P INPUT DROP
- iptables -P OUTPUT ACCEPT
- iptables -P FORWARD DROP
- service iptables save
- systemctl restart iptables.service
CentOS之——CentOS7安装iptables防火墙的更多相关文章
- CentOS7安装iptables防火墙
CentOS7默认的防火墙不是iptables,而是firewalle. 安装iptable iptable-service #先检查是否安装了iptables service iptables st ...
- Centos7下安装iptables防火墙
说明:centos7默认使用的firewalld防火墙,由于习惯使用iptables做防火墙,所以在安装好centos7系统后,会将默认的firewall关闭,并另安装iptables进行防火墙规则设 ...
- CentOS 7.0启用iptables防火墙
CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1.关闭firewall: systemctl stop firewalld.service #停止fir ...
- CentOs7 使用iptables防火墙开启关闭端口
CentOs7 使用iptables防火墙开启关闭端口 # 0x01介绍 iptables命令是Linux上常用的防火墙软件,是netfilter项目的一部分iptables文件设置路径:命令:v ...
- centos 7 安装iptables防火墙
firewalle: 开启6379端口和16379端口 [root@localhost ~]# firewall-cmd --zone=public --add-port=6379/tcp --per ...
- Centos安装iptables防火墙
一.安装说明: 1.因为centos7.0及以上版本就默认安装了firewall防火墙,但有时候根据项目实际所需,服务器上还是需要安装iptables,以下就是具体的安装步骤: 2.因阿里云在服务器外 ...
- CentOS7使用iptables防火墙开放端口
背景:在CentOS上面安装了mysql.svn.tomcat等软件,发现访问不了,用telnet命令查看端口,发现都不通: telnet IP 端口 CentOS7 默认使用firewalld防火墙 ...
- entOS7安装iptables防火墙,试验未通过
CentOS7默认的防火墙不是iptables,而是firewalle. 安装iptable iptable-service #先检查是否安装了iptables service iptables st ...
- CentOS7配置iptables防火墙
CentOS 7中默认是firewalld防火墙,如果使用iptables需要先关闭firewalld防火墙(1.关闭防火墙,2.取消开机启动). #关闭firewalld systemctl sto ...
随机推荐
- 进程池pool
如果有多个进程,同一时间只能有限个给cpu运行 from multiprocessing import Process,Pool import time,os def bar(arg): print( ...
- oracle--合并行数据(拼接字符串),获取查询数据的前3条数据...
--标准函数Lpad 可以实现左补零,但是如果多于需要长度,则会截断字符串 SELECT LPAD ('1' , 3 , '0') FROM DUAL -- return 001 情况一:需要补零. ...
- php 测试 程序执行时间,内存使用情况
memory_get_usage 可以分析内存占用空间. microtime 函数就可以分析程序执行时间. 上栗子: echo '开始内存:'.memory_get_usage(), ''; $tmp ...
- workerman vmstat服务器状态监控服务
转载出自 :http://www.workerman.net/workerman-vmstat workerman vmstat服务器状态监控服务 vmstat 命令可以展现服务器的CPU使用率,内存 ...
- 用Matlab进行部分分式展开
[r p k]=residue[num,den] 例如H(s)=(2s3+5s2+3s+6)/(s3+6s2+11s+6) num=[2 5 3 6]; den=[1 6 11 6]; [r p k] ...
- Python中的self和init
From: https://www.crifan.com/summary_the_meaning_of_self_and___init___in_python_and_why_need_them/ 背 ...
- SpringSecurity的Filter执行顺序在源码中的体现
在网上看各种SpringSecurity教程时,都讲到了SpringSecurity的Filter顺序.但是一直不知道这个顺序在源码中是如何体现的.今天一步一步的查找,最终找到顺序是在FilterCo ...
- Qt学习——QListWidget控件的使用
转载:GDUTLYP Qt提供QListWidget类列表框控件用来加载并显示多个列表项.QListWidgetItem类就是列表项类. 一般列表框控件中的列表项有两种加载方式: 一种是由用户手动添加 ...
- Python error: Microsoft Visual C++ 9.0 is required 解决方案
换了新电脑,在使用python2.7 pip 安装ipython时,报错了 error: Microsoft Visual C++ 9.0 is required. Get it from http: ...
- ubuntu安装最新的mercurial
Mercurial 是一种轻量级分布式版本控制系统,采用 Python 语言实现,易于学习和使用,扩展性强 之前安装的mercurial版本(2.8.2)太老了,想安装最新版本的. 网上搜到方法 su ...