zoukankan      html  css  js  c++  java
  • Linux之防火墙iptables

    一、检查iptables服务状态

    1、首先检查iptables服务的状态

    [root@bogon ~]# service iptables status
    iptables: Firewall is not running.
    说明iptables服务是有安装的,但是没有启动服务。
    如果没有安装的话可以直接yum安装
    yum install -y iptables

    2、启动iptables

    [root@bogon ~]# service iptables start
    iptables: Applying firewall rules:                         [  OK  ]

    3、查看当前iptables的配置情况

    [root@woxplife ~]# iptables -L -n
    二、清除默认的防火墙规则
    #首先在清除前要将policy INPUT改成ACCEPT,表示接受一切请求。
    iptables -P INPUT ACCEPT
    #清空默认所有规则
    iptables -F
    
    #清空自定义的所有规则
    iptables -X
    
    #计数器置0
    iptables -Z
    三、配置规则
    #允许来自于lo接口的数据包
    #如果没有此规则,你将不能通过127.0.0.1访问本地服务,例如ping 127.0.0.1
    iptables -A INPUT -i lo -j ACCEPT
    #ssh端口22
    iptables -A INPUT -p tcp --dport 22 -j ACCEPT
    
    #FTP端口21
    iptables -A INPUT -p tcp --dport 21 -j ACCEPT
    
    #web服务端口80
    iptables -A INPUT -p tcp --dport 80 -j ACCEP
    
    #tomcat
    iptables -A INPUT -p tcp --dport xxxx -j ACCEP
    
    #mysql
    iptables -A INPUT -p tcp --dport xxxx -j ACCEP
    
    #允许icmp包通过,也就是允许ping
    iptables -A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
    
    #允许所有对外请求的返回包
    #本机对外请求相当于OUTPUT,对于返回数据包必须接收啊,这相当于INPUT了
    iptables -A INPUT -m state --state ESTABLISHED -j ACCEPT
    
    #如果要添加内网ip信任(接受其所有TCP请求)
    iptables -A INPUT -p tcp -s 45.96.174.68 -j ACCEPT
    
    #过滤所有非以上规则的请求
    iptables -P INPUT DROP
    四、保存
    #保存
    [root@woxplife ~]# service iptables save
    
    #添加到自启动chkconfig
    [root@woxplife ~]# chkconfig iptables on
  • 相关阅读:
    在阿里云上遇见更好的Oracle(三)
    从传统IT快速走向公共云计算
    在阿里云上遇见更好的Oracle(二)
    Oracle 11g 审计跟踪管理
    在阿里云上遇见更好的Oracle(一)
    Elasticsearch中的DocValues
    初识Django —Python API接口编程入门
    为什么mysqld启动报错
    云计算产品的四件套
    说说云计算中的地域和可用区概念
  • 原文地址:https://www.cnblogs.com/liukaifeng/p/10052654.html
Copyright © 2011-2022 走看看