zoukankan      html  css  js  c++  java
  • 阿里云CentOS6上配置iptables

    参考:http://blog.abv.cn/?p=50

    阿里云CentOS6默认没有启动iptables

    1、检查iptables状态

    [root@iZ94jj63a3sZ ~]# service iptables status
    iptables: Firewall is not running.
    [root@iZ94jj63a3sZ ~]# 

      说明iptables没有启动。

      如果没有安装,则使用如下命令安装

    [root@iZ94jj63a3sZ ~]# yum install -y iptables

      启动iptables

    [root@iZ94jj63a3sZ ~]# service iptables start

     查看当前iptables的配置情况

    [root@iZ94jj63a3sZ ~]# iptables -L -n
    Chain INPUT (policy ACCEPT)
    target     prot opt source               destination         
    
    Chain FORWARD (policy ACCEPT)
    target     prot opt source               destination         
    
    Chain OUTPUT (policy ACCEPT)
    target     prot opt source               destination

    2、清楚默认的防火墙规则

    #首先在清除前要将policy INPUT改成ACCEPT,表示接受一切请求。
    #这个一定要先做,不然清空后可能会悲剧
    [root@iZ94jj63a3sZ ~]# iptables -P INPUT ACCEPT
    
    #清空默认所有规则
    [root@iZ94jj63a3sZ ~]# iptables -F
    
    #清空自定义的所有规则
    [root@iZ94jj63a3sZ ~]# iptables -X
    
    #计数器置0
    [root@iZ94jj63a3sZ ~]# iptables -Z

    3、配置规则

    #允许来自于lo接口的数据包
    #如果没有此规则,你将不能通过127.0.0.1访问本地服务,例如ping 127.0.0.1
    [root@iZ94jj63a3sZ ~]# iptables -A INPUT -i lo -j ACCEPT 
    
    
    #ssh端口22
    [root@iZ94jj63a3sZ ~]# iptables -A INPUT -p tcp --dport 22 -j ACCEPT
    
    
    #web服务端口80
    [root@iZ94jj63a3sZ ~]# iptables -A INPUT -p tcp --dport 80 -j ACCEPT
    
    
    #允许icmp包通过,也就是允许ping
    [root@iZ94jj63a3sZ ~]# iptables -A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
    
    
    #允许所有对外请求的返回包
    #本机对外请求相当于OUTPUT,对于返回数据包必须接收啊,这相当于INPUT了
    [root@iZ94jj63a3sZ ~]# iptables -A INPUT -m state --state ESTABLISHED -j ACCEPT
    
    
    #过滤所有非以上规则的请求
    [root@iZ94jj63a3sZ ~]# iptables -P INPUT DROP

    4、保存

      首先使用 iptables -L -n 检查一下配置是否正确

    [root@iZ94jj63a3sZ ~]# iptables -L -n

      确认无误后保存

    [root@iZ94jj63a3sZ ~]# service iptables save

      添加到开机自启动

    [root@iZ94jj63a3sZ ~]# chkconfig iptables on
  • 相关阅读:
    LeetCode 32. 最长有效括号(Longest Valid Parentheses)
    LeetCode 141. 环形链表(Linked List Cycle)
    LeetCode 160. 相交链表(Intersection of Two Linked Lists)
    LeetCode 112. 路径总和(Path Sum)
    LeetCode 124. 二叉树中的最大路径和(Binary Tree Maximum Path Sum)
    LightGBM新特性总结
    sql service 事务与锁
    C#泛型实例详解
    C# 中的委托和事件(详解)
    C# DateTime日期格式化
  • 原文地址:https://www.cnblogs.com/luxh/p/4680825.html
Copyright © 2011-2022 走看看