防火墙配置

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. when coding in a fresh system

    I have designed a component of a web system with my workmate. In detail, I am just a coder instead o ...

  2. 悟空模式-java-抽象工厂模式

    [一朝,王母娘娘设宴,大开宝阁,瑶池中做蟠桃胜会] 有一天,王母娘娘要在瑶池办party,就需要准备大量的食材.要知道,天上的神仙也分三六九等,九曜星.五方将.二十八宿.四大天王.十二元辰.五方五老. ...

  3. JVM之---Java源码编译机制

    Sun JDK中采用javac将Java源码编译为class文件,这个过程包含三个步骤:     1.分析和输入到符号表(Parse and Enter)    Parse过程所做的工作有词法和语法分 ...

  4. ASP.NET MVC中你必须知道的13个扩展点

         ScottGu在其最新的博文中推荐了Simone Chiaretta的文章13 ASP.NET MVC extensibility points you have to know,该文章为我 ...

  5. 使用swiper 轮播插件ajax 请求加载图片时,无法滑动问题

    因为图片是动态创建的,在插件开始初始化时,文档流中没用图片,故没有创建相应宽度.通过调整js加载顺序,问题还是没有解决. 最后找到swiper插件 api 有属性是可以根据内容变动,自动初始化插件的, ...

  6. BZOJ1396: 识别子串(后缀自动机 线段树)

    题意 题目链接 Sol 后缀自动机+线段树 还是考虑通过每个前缀的后缀更新答案,首先出现次数只有一次,说明只有\(right\)集合大小为\(1\)的状态能对答案产生影响 设其结束位置为\(t\),代 ...

  7. angular2 如何使用websocket

    1.npm下载: npm install angular2-websocket 2.需要在哪个组件使用就在那里引入: import {$WebSocket} from 'angular2-websoc ...

  8. linux 软件包安装方式选择、安装位置、源码包安装

    对外提供服务,比如apache,应使用源码包安装对内提供服务,比如gcc,只是我自己使用,使用rpm包安装 rpm包不需要指定安装位置,源码包的安装需要手动指定安装位置 rpm包默认安装位置/etc/ ...

  9. linux 用户管理命令useradd、passwd、who、whoami、id、w及创建用户默认值文件

    useradd /usr/sbin/useradd执行权限:rootuseradd [选项] 用户名-u UID:手工指定用户的UID号-d 家目录:手工指定用户的家目录-c 用户说明:手工指定用户的 ...

  10. eclipse安装python

    在Eclipse中安装pydev插件 启动Eclipse, 点击Help->Install New Software...   在弹出的对话框中,点Add 按钮.  Name中填:Pydev,  ...