zoukankan      html  css  js  c++  java
  • iptables 配置

    一、概述

      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  3 12:10:36 2017
    *filter
    :INPUT ACCEPT [0:0]
    :FORWARD DROP [0:0]
    :OUTPUT ACCEPT [0:0]
    -A INPUT -i lo -j ACCEPT
    
    #允许本机ping其他host
    -I INPUT -p icmp -j ACCEPT
    -A INPUT -p tcp -m tcp --dport 2222 -j ACCEPT
    -A INPUT -p tcp -m tcp --dport 80 -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 53 -j ACCEPT
    -A INPUT -p udp --sport 53 -j ACCEPT
    
    -A INPUT -p udp --dport 53 -j ACCEPT
    -A OUTPUT -p udp --sport 53 -j ACCEPT
    
    
    #允许本机被ping
    -A OUTPUT -p icmp --icmp-type echo-reply -j ACCEPT
    -A OUTPUT -p tcp -m tcp --sport 80 -j ACCEPT
    -A OUTPUT -p tcp -m tcp --sport 2222 -j ACCEPT
    
    
    -A INPUT -j DROP
    -A FORWARD -j DROP 
    -A OUTPUT -j ACCEPT
    COMMIT
    # Completed on Fri Mar  3 12:10:36 2017
  • 相关阅读:
    网上购物记录(2011淘宝大甩卖)
    心理学上最诡异的23张图!!
    三字念什么
    哥德尔不完备定理
    又要新的开始了(续)
    第一次接触计算机语言的经历
    哥德尔不完备性定理——从数学危机到哲学危机
    google (精简版)
    贴吧回复
    在轻松的环境中工作
  • 原文地址:https://www.cnblogs.com/chris-cp/p/5643634.html
Copyright © 2011-2022 走看看