防火墙配置

CentOS 7默认使用的是firewall作为防火墙,这里改为iptables防火墙。

 firewall操作:

# service firewalld status; #查看防火墙状态

(disabled 表明 已经禁止开启启动 enable 表示开机自启,inactive 表示防火墙关闭状态 activated(running)表示为开启状态)

# service firewalld start;  或者 #systemctl start firewalld.service;#开启防火墙

# service firewalld stop;  或者 #systemctl stop firewalld.service;#关闭防火墙

# service firewalld restart;  或者 #systemctl restart firewalld.service;  #重启防火墙

# systemctl disable firewalld.service#禁止防火墙开启自启

# systemctl enable firewalld#设置防火墙开机启动

#yum remove firewalld#卸载firewall

禁用/停止自带的firewalld服务

systemctl stop firewalld  #停止firewalld服务

systemctl mask firewalld  #禁用firewalld服务

安装iptables防火墙及操作:

service iptables status    #先检查是否安装了iptables

yum install -y iptables   #安装iptables

yum update iptables   #升级iptables

yum install iptables-services  #安装iptables-services

设置现有规则

iptables -L -n  #查看iptables现有规则

iptables -P INPUT ACCEPT  #先允许所有,不然有可能会杯具

iptables -F  #清空所有默认规则

iptables -X  #清空所有自定义规则

iptables -Z  #所有计数器归0

iptables -A INPUT -i lo -j ACCEPT  #允许来自于lo接口的数据包(本地访问)

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

iptables -A INPUT -p tcp --dport 21 -j ACCEPT  #开放21端口(FTP)

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

iptables -A INPUT -p tcp --dport 443 -j ACCEPT  #开放443端口(HTTPS)

iptables -A INPUT -p icmp --icmp-type 8 -j ACCEPT  #允许ping

iptables -A INPUT -m state --state  RELATED,ESTABLISHED -j ACCEPT  #允许接受本机请求之后的返回数据 RELATED,是为FTP设置的

iptables -P INPUT DROP  #其他入站一律丢弃

iptables -P OUTPUT ACCEPT  #所有出站一律绿灯

iptables -P FORWARD DROP  #所有转发一律丢弃

其他规则设定

iptables -A INPUT -p tcp -s 45.96.174.68 -j ACCEPT  #如果要添加内网ip信任(接受其所有TCP请求)

iptables -P INPUT DROP  #过滤所有非以上规则的请求

iptables -I INPUT -s ***.***.***.*** -j DROP  #要封停一个IP,使用下面这条命令:

iptables -D INPUT -s ***.***.***.*** -j DROP  #要解封一个IP,使用下面这条命令:

保存规则设定

service iptables save  #保存上述规则

开启iptables服务

systemctl enable iptables.service  #注册iptables服务  相当于以前的chkconfig iptables on

systemctl start iptables.service  #开启服务

systemctl status iptables.service  #查看状态

解决vsftpd在iptables开启后,无法使用被动模式的问题

1.首先在/etc/sysconfig/iptables-config中修改或者添加以下内容

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

  

Linux centos修改防火墙为iptables的更多相关文章

  1. Linux CentOS修改网卡IP/网关设置

    1. 修改对应网卡IP的配置文件 修改以下内容 2. 修改对应网卡的网关的配置文件 vi /etc/sysconfig/network 修改以下内容 3. CentOS 修改DNS 修改以下内容 4. ...

  2. Linux Centos 开启防火墙 FirewallD is not running

    转载自:http://www.z4zr.com/page/1006.html CentOS7用firewall命令“替代”了iptables.在这里我们需要区分“iptables服务”和“iptabl ...

  3. linux中的防火墙netfilter iptables

    目录 一.Linux防火墙基础 1.1 ptables的表.链结构 1.2 数据包控制的匹配流程 二.编写防火墙规则 1.iptables的安装 2.1 基本语法.控制类型 一般在生产环境中设置网络型 ...

  4. Linux CentOS 7 防火墙/端口设置

    CentOS升级到7之后用firewall代替了iptables来设置Linux端口, 下面是具体的设置方法: []:选填 <>:必填 [<zone>]:作用域(block.d ...

  5. Linux CentOS中防火墙的关闭及开启端口

    注:CentOS7之前用来管理防火墙的工具是iptable,7之后使用的是Firewall 样例:在CentOS7上安装tomcat后,在linux本机上可以访问tomcat主页,http://ip: ...

  6. Linux CentOS 7 防火墙与端口设置操作

    CentOS升级到7之后用firewall代替了iptables来设置Linux端口, 下面是具体的设置方法: []:选填 <>:必填 [<zone>]:作用域(block.d ...

  7. Linux CentOS 7 防火墙/端口设置【转发】

    CentOS升级到7之后用firewall代替了iptables来设置Linux端口, 下面是具体的设置方法: []:选填 <>:必填 [<zone>]:作用域(block.d ...

  8. Linux系统修改防火墙配置

    防火墙配置文件位置 /etc/sysconfig/iptables 需要开放端口,请在里面添加一条内容即可: 1 -A RH-Firewall-1-INPUT -m state --state NEW ...

  9. Linux CentOS 修改内核引导顺序

    CentOS 7.0 系统更改内核启动顺序 可以 uname -a查下当前的 由于 CentOS 7 使用 grub2 作为引导程序,所以和 CentOS 6 有所不同,并不是修改 /etc/grub ...

随机推荐

  1. Review——JS的异步与同步

    一.概念 同步(synchronous):指在js的主线程上,所有任务被依次执行: 异步(asynchronous):指任务不进入主线程,进入任务队列(task):当“任务队列”通知主线程,异步任务才 ...

  2. Wannafly挑战赛9 E - 组一组

    链接:https://www.nowcoder.net/acm/contest/71/E来源:牛客网 题目描述 有一个长为 n 的数列 A,其中有 m 个限制条件,条件有两种: 1.对于区间 [l,r ...

  3. Codeforces Global Round1 简要题解

    Codeforces Global Round 1 A 模拟即可 # include <bits/stdc++.h> using namespace std; typedef long l ...

  4. 使用display:none和visibility:hidden隐藏的区别

    今天做毕设时遇到了一个小问题,我做了一个tab导航栏,点击一个tab页其它tab页隐藏,这时候第一想法是使用display:none来控制显示隐藏,写了之后发现使用display会有一个问题,就是第二 ...

  5. React—Native开发之原生模块向JavaScript发送事件

    首先,由RN中文网关于原生模块(Android)的介绍可以看到,RN前端与原生模块之 间通信,主要有三种方法: (1)使用回调函数Callback,它提供了一个函数来把返回值传回给JavaScript ...

  6. 多线程下载英文Google地图

    1. pom.xml文件 <?xml version="1.0" encoding="UTF-8"?> <project xmlns=&quo ...

  7. samba 使用tips

    安装: 推荐使用新立德包管理器安装 SAMBA配置文件: /etc/samba/smb.conf Samba服务器的启动与关闭: sudo /etc/init.d/smbd start ubuntu访 ...

  8. Android布局属性

    LinearLayout布局: 线性版面配置,在这个标签中,所有元件都是按由上到下的排队排成的.在这个界面中,我们应用了一个 LinearLayout的布局,它是垂直向下扩展的 ,所以创建的布局XML ...

  9. Spring Boot -01- 快速入门篇(图文教程)

    Spring Boot -01- 快速入门篇(图文教程) 今天开始不断整理 Spring Boot 2.0 版本学习笔记,大家可以在博客看到我的笔记,然后大家想看视频课程也可以到[慕课网]手机 app ...

  10. ORACLE 参数设置绑定变量

    使用 CURSOR_SHARING 参数 EXACT  默认,不替换 SIMIAR 当替换不会影响到执行计划时,才会将字面量替换成绑定变量 FORCE 只要有可能,字面量会被替换为绑定变量