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

    iptables -t filter -A INPUT -s 192.168.1.1 -j DROP

                  表        链    匹配属性      动作

    表--要执行的相关功能,eg过滤功能用到filter表,修改ip地址用到nat表,高级配置用到mangle表

    链--过滤点,eg处理入向流量用input,出向output..forward、prerouting、postrouting

    匹配属性--哪条数据包符合

    动作--最后跟我们的动作

    常用的参数drop reject有区别

    [root@py ~]# service iptables status
    Table: filter
    Chain INPUT (policy ACCEPT)
    num  target     prot opt source               destination         
    1    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 
    2    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           
    3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
    4    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22 
    5    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 
    
    Chain FORWARD (policy ACCEPT)
    num  target     prot opt source               destination         
    1    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 
    
    Chain OUTPUT (policy ACCEPT)
    num  target     prot opt source               destination         
    
    [root@py ~]# iptables -L
    Chain INPUT (policy ACCEPT)
    target     prot opt source               destination         
    ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED 
    ACCEPT     icmp --  anywhere             anywhere            
    ACCEPT     all  --  anywhere             anywhere            
    ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:ssh 
    REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited 
    
    Chain FORWARD (policy ACCEPT)
    target     prot opt source               destination         
    REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited 
    
    Chain OUTPUT (policy ACCEPT)
    target     prot opt source               destination       
    [root@py ~]# iptables -I INPUT 2 -p tcp --dport 22 -j ACCEPT
    [root@py ~]# iptables -L
    Chain INPUT (policy ACCEPT)
    target     prot opt source               destination         
    ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED 
    ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ssh 
    ACCEPT     icmp --  anywhere             anywhere            
    ACCEPT     all  --  anywhere             anywhere            
    ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:ssh 
    REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited 
    
    Chain FORWARD (policy ACCEPT)
    target     prot opt source               destination         
    REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited 
    
    Chain OUTPUT (policy ACCEPT)
    target     prot opt source               destination      
    [root@py ~]# iptables -D INPUT 2
    [root@py ~]# iptables -L
    Chain INPUT (policy ACCEPT)
    target     prot opt source               destination         
    ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED 
    ACCEPT     icmp --  anywhere             anywhere            
    ACCEPT     all  --  anywhere             anywhere            
    ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:ssh 
    REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited 
    
    Chain FORWARD (policy ACCEPT)
    target     prot opt source               destination         
    REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited 
    
    Chain OUTPUT (policy ACCEPT)
    target     prot opt source               destination     

    -s 源地址 -d目标地址

    -i入口接口-o出口接口

    ‘!’取反,所有不来自192.168.1.0/24

    注意

    如果是远程管理一个linux主机并修改iptables规则,则必须先允许来自客户端主机的ssh流量确保这是第一条iptables规则,否则可能会由于配置失误将自己所在外面!

  • 相关阅读:
    Java实现 LeetCode 61 旋转链表
    Java实现 LeetCode 60 第k个排列
    Java实现 LeetCode 60 第k个排列
    Java实现 LeetCode 60 第k个排列
    Java实现 LeetCode 59 螺旋矩阵 II
    VC 2005 解决方案的目录结构设置和管理
    Visual C++ 设置适合自己的解决方案目录结构
    瑞蓝RL-NDVM-A16网络视频解码器 视频上墙解决方案专家--数字视频解码矩阵
    为什么类的定义中不能包含其自身类型,但是能包含其自身的指针或引用类型
    C++模板使用介绍
  • 原文地址:https://www.cnblogs.com/zq6041/p/6900618.html
Copyright © 2011-2022 走看看