一、概述

  1、redhat7/centos7系列默认防火墙使用firewalld,关闭之
    systemctl stop firewalld.service
  2、安装iptables
    yum install -y iptables-services
  3、systemctl start iptables.service
    systemctl enable iptables.service

   /etc/sysconfig/iptables #编辑防火墙配置文件

  4、查看规则:
    iptables -nL //注意,该输出的顺序很重要
    对filter表(iptables默认表)的INPUT链配置:
    //所有input都丢弃;然后开放22端口
      iptables -A INPUT -j DROP ; iptables -A INPUT -p tcp --dport 22 -j ACCEPT

    对filter表(iptables默认表)的FORWARD链配置:
      iptables -A FORWARD -j DROP
    对filter表(iptables默认表)的OUTPUT链配置:
      iptables -A OUTPUT -j ACCEPT

    放开lo:
      iptables -A INPUT -p all -j ACCEPT

    iptables -F #清空规则

    iptables -X #清空自定义规则

  5、note:

    使用以上命令设置规则之后,systemctl restart iptables.service之后,规则完全丢失;

    方法一: iptables-save >  /etc/sysconfig/iptables

    方法二: service iptables save  

    执行之后,重启之后依然可以生效;

  #打开本地回环
    iptables -A INPUT -i lo -j ACCEPT
    iptables -A OUTPUT -o lo -j ACCEPT

  #打开ping
    iptabels -A INPUT -p icmp  --icmp-type 8 -j ACCEPT
    iptables -A OUTPUT -p icmp --icmp-type 0 -j ACCEPT

# Generated by iptables-save v1.4.21 on Fri Mar   ::
*filter
:INPUT ACCEPT [:]
:FORWARD DROP [:]
:OUTPUT ACCEPT [:]
-A INPUT -i lo -j ACCEPT #允许本机ping其他host
-I INPUT -p icmp -j ACCEPT
-A INPUT -p tcp -m tcp --dport -j ACCEPT
-A INPUT -p tcp -m tcp --dport -j ACCEPT #允许本机被ping
-A INPUT -p icmp --icmp-type echo-request -j ACCEPT #允许dns
#-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A OUTPUT -p udp --dport -j ACCEPT
-A INPUT -p udp --sport -j ACCEPT -A INPUT -p udp --dport -j ACCEPT
-A OUTPUT -p udp --sport -j ACCEPT #允许本机被ping
-A OUTPUT -p icmp --icmp-type echo-reply -j ACCEPT
-A OUTPUT -p tcp -m tcp --sport -j ACCEPT
-A OUTPUT -p tcp -m tcp --sport -j ACCEPT -A INPUT -j DROP
-A FORWARD -j DROP
-A OUTPUT -j ACCEPT
COMMIT
# Completed on Fri Mar ::

iptables 配置的更多相关文章

  1. tony_iptables_01_linux下IPTABLES配置详解(转)

    如果你的IPTABLES基础知识还不了解,建议先去看看. 开始配置 我们来配置一个filter表的防火墙. (1)查看本机关于IPTABLES的设置情况 [root@tp ~]# iptables - ...

  2. linux下IPTABLES配置详解(转)

    如果你的IPTABLES基础知识还不了解,建议先去看看. 开始配置 我们来配置一个filter表的防火墙. (1)查看本机关于IPTABLES的设置情况 [root@tp ~]# iptables - ...

  3. linux下IPTABLES配置详解(转)

    如果你的IPTABLES基础知识还不了解,建议先去看看.开始配置我们来配置一个filter表的防火墙.(1)查看本机关于IPTABLES的设置情况[ ~]# iptables -L -nChain I ...

  4. linux下IPTABLES配置

    如果你的IPTABLES基础知识还不了解,建议先去看看. 开始配置 我们来配置一个filter表的防火墙. (1)查看本机关于IPTABLES的设置情况 [root@tp ~]# iptables - ...

  5. [转载] iptables配置实践

    原文: http://wsgzao.github.io/post/iptables/ iptables配置实践 By wsgzao 发表于 2015-07-24 文章目录 1. 前言 2. 更新历史 ...

  6. linux下IPTABLES配置详解

    如果你的IPTABLES基础知识还不了解,建议先去看看. 开始配置 我们来配置一个filter表的防火墙. (1)查看本机关于IPTABLES的设置情况 [root@tp ~]# iptables - ...

  7. (转载)Linux下IPTABLES配置详解

    (转载)http://www.cnblogs.com/JemBai/archive/2009/03/19/1416364.html 如果你的IPTABLES基础知识还不了解,建议先去看看. 开始配置 ...

  8. Android Linux自带iptables配置IP访问规则

    利用Linux自带iptables配置IP访问规则,即可做到防火墙效果

  9. 9. iptables 配置

    iptables 配置文件存放位置:  [root@Demon yum.repos.d]# vim /etc/rc.d/init.d/iptables   一.只给 Centos 6.5 打开 22 ...

  10. [转]linux下IPTABLES配置详解

    如果你的IPTABLES基础知识还不了解,建议先去看看.开始配置我们来配置一个filter表的防火墙.(1)查看本机关于IPTABLES的设置情况[root@tp ~]# iptables -L -n ...

随机推荐

  1. Mono For Android中AlarmManager的使用

    最近做了一个应用,要求如下: 程序运行之后的一段时间,分别触发3个不同的事件.当然很快就想到了Android中的AlarmManager和BroadcastReceiver.但是毕竟Mono环境和Ja ...

  2. win8 VS2010 配制OpenGL

    glut下载地址: http://www.opengl.org/resources/libraries/glut/glutdlls37beta.zip glut.h  ---> C:\Progr ...

  3. 论山寨手机与Android联姻 【1】MTK亮相的历史背景

    [1]MTK亮相的历史背景如果说1960年代是大型机(Mainframe)的时代,1970年代是小型机(Microcomputer)的时代,那么1980年代无疑是个人电脑(PC)的时代,而1990年代 ...

  4. List<int>是值类型还是引用类型

    class Program { static void Main(string[] args) { List<int> lst = new List<int>(); lst.A ...

  5. grep 基于关键字搜索

    grep 'linux' /etc/passwd 搜索passwd文件下的包含linux的行 find / -user linux|grep Video 在用户为linux的根目录下搜房Video内容 ...

  6. CC++初学者编程教程(14) Redhat linux安装Oracle12c

    1选择虚拟机的设置 2 设置共享文件夹 3 使用共享文件夹向导 4 选择主机路径 5 启用文件共享 6 设置好文件共享以后,关闭虚拟机的设置 7 开启虚拟机 8 登陆 9输入密码 10 安装vmwar ...

  7. 使用 Node.js 做 Function Test

    Info 上周 meeting 上同事说他们现在在用 java 写 function test,产生了很多冗余的代码,整个项目也变得比较臃肿.现在迫切需要个简单的模板项目能快速搭建function t ...

  8. 线性表A-B

    1.顺序存储 #include<stdio.h> /* 设有两个顺序表A和B,且都递增有序,试写一算法,从A中删除与B中相同的那些元素,即求A-B */ #define getArrayL ...

  9. Centos6.5 telnet wireshark

    yum -y install telnet-server telnet vim /etc/xinted.d/telnet disable = no vim /etc/pam.d/remote #aut ...

  10. CSS 根据数据显示样式

    在低版本IE时代,我们想让数据根据其值显示不同的样式可能需要直接从服务器端输出时为不同的数据添加相应的class.但现在,通过属性选择器+伪元素+属性选择符,这三个东西混合使用就可以让数据根据其值以不 ...