Centos安装iptables防火墙
一、安装说明:
1、因为centos7.0及以上版本就默认安装了firewall防火墙,但有时候根据项目实际所需,服务器上还是需要安装iptables,以下就是具体的安装步骤;
2、因阿里云在服务器外面还有相应的防火墙,所以除了在iptables中开放相应端口,还需要在阿里云后台-安全组规则-也开放相关端口;
二、如何安装:
安装iptable iptable-service
先检查是否安装了iptables
service iptables status
安装iptables
yum install -y iptables
升级iptables
yum update iptables
安装iptables-services
yum install iptables-services
iptables-services 和 iptables 是不一样的
安装了 services才有/etc/sysconfig/iptables
禁用/停止自带的firewalld服务
停止firewalld服务
systemctl stop firewalld
禁用firewalld服务
systemctl mask firewalld
设置现有规则
查看iptables现有规则
iptables -L -n
先允许所有,不然有可能会产生”杯具“,即可能导致服务器的部分服务不可用,例如web、ftp等
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
保存规则设定
保存上述规则
service iptables save
开启iptables服务
注册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”
2.重新设置iptables设置
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安装iptables防火墙的更多相关文章
- CentOS系统配置 iptables防火墙
阿里云CentOS系统配置iptables防火墙 虽说阿里云推出了云盾服务,但是自己再加一层防火墙总归是更安全些,下面是我在阿里云vps上配置防火墙的过程,目前只配置INPUT.OUTPUT和FO ...
- Centos7下安装iptables防火墙
说明:centos7默认使用的firewalld防火墙,由于习惯使用iptables做防火墙,所以在安装好centos7系统后,会将默认的firewall关闭,并另安装iptables进行防火墙规则设 ...
- CentOS启用iptables防火墙
centos 7默认的防火墙使用firewall,系统服务管理方式也变更了,可以通过systemctl命令控制. 可以参考这个链接 但是习惯用iptables,可以按下面的操作改下 1.关闭firew ...
- 利用CentOS系统IPtables防火墙添加网站IP白名单
参考博文: 利用CentOS系统IPtables防火墙添加360网站卫士节点IP白名单 centos6.5添加白名单如下: 在防火墙 配置文件中加入白名单 ip -A INPUT -s 183.13 ...
- centos 7 安装iptables防火墙
firewalle: 开启6379端口和16379端口 [root@localhost ~]# firewall-cmd --zone=public --add-port=6379/tcp --per ...
- CentOS之——CentOS7安装iptables防火墙
转载请注明出处:http://blog.csdn.net/l1028386804/article/details/50779761 CentOS7默认的防火墙不是iptables,而是firewall ...
- CentOS7安装iptables防火墙
CentOS7默认的防火墙不是iptables,而是firewalle. 安装iptable iptable-service #先检查是否安装了iptables service iptables st ...
- entOS7安装iptables防火墙,试验未通过
CentOS7默认的防火墙不是iptables,而是firewalle. 安装iptable iptable-service #先检查是否安装了iptables service iptables st ...
- Linux 安装 iptables防火墙
CentOS7默认的防火墙不是iptables,而是firewalle. 安装iptable iptable-service #先检查是否安装了iptables service iptables st ...
随机推荐
- JS---基础用法2
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- MVC之Control中使用AOP
原文转载自http://www.cnblogs.com/iamlilinfeng/archive/2013/03/02/2940162.html 本文目标 一.能够使用Control中的AOP实现非业 ...
- [poj1986]Distance Queries(LCA)
解题关键:LCA模板题 复杂度:$O(n\log n)$ #pragma comment(linker, "/STACK:1024000000,1024000000") #incl ...
- 极客时间_Vue开发实战_汇总贴
视频地址: https://time.geekbang.org/course/intro/163 https://github.com/tangjinzhou/geektime-vue-1 电脑dem ...
- 交互原型设计软件axure rp学习之路(一)
开始学习之前,请一定要明白:Axure是个极其极其极其简单的软件.因为你所做的就是拖部件,打字,拖部件,打字,最多加个对齐.如果你能把axure当作word或者ppt来用,那你就学会了axure. A ...
- update-alternatives --Install
up vote 1 down vote favorite I typed: sudo update-alternatives --install "/usr/bin/java" & ...
- java中多个线程访问共享数据的方式有哪些
多个线程对共同数据的访问的实现,要根据情况而定 (1)当访问共同的代码的时候:可以使用同一个Runnable对象,这个Runnable对象中有这个共享数据,比如卖票系统就可以这么做.或者这个共享数据封 ...
- POJ - 3268 Silver Cow Party SPFA+SLF优化 单源起点终点最短路
Silver Cow Party One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to ...
- Jsoncpp写“鱘”的json数据,报错。
最近在用Json::FastWriter生成json数据时,发现一个问题.含有“鱘”字的json字段会多出一个斜杠,不知道是不是编码的问题. C++要使用JSON来解析数据,一般采用jsoncpp. ...
- uoj#335. 【清华集训2017】生成树计数(prufer序列+生成函数+多项式)
传送门 好神仙的题目--又一次有了做一题学一堆的美好体验 据说本题有第二类斯特林数+分治\(FFT\)的做法,然而咱实在看不懂写的是啥,题解贴这里,有兴趣的可以自己去瞅瞅,看懂了记得回来跟咱讲讲 前置 ...