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
  • 相关阅读:
    hdu 3555 Bomb 【数位DP】
    ibatis动态的传入表名、字段名
    ibatis把表名作为一个参数报错问题的解决方案
    事务——原子性、一致性、隔离性和持久性的理解
    struts2 集成webservice 的方法
    MySQL FEDERATED引擎使用示例, 类似Oracle DBLINK
    Javascript禁止网页复制粘贴效果,或者复制时自动添加来源信息
    asp.net关于Cookie跨域(域名)的问题
    Java cookie的使用
    关于Cookie跨域操作的一些总结
  • 原文地址:https://www.cnblogs.com/luxh/p/4680825.html
Copyright © 2011-2022 走看看