zoukankan      html  css  js  c++  java
  • 1.IPtable基础命令总结

    iptables概念

    规则查询
    #查看对应表中的所有规则
    iptables -t 表名 -L
    
    #查看表的指定链中的规则
    iptables -t 表名 -L 链名
    
    #查看对应表中的所有规则, -v显示跟详细的信息
    iptables -t 表名 -v -L
    
    # -n 表示不解析IP地址
    iptables -t 表名 -n -L
    
    #--line-numbers  显示规则的序号
    iptables --line-numbers -t 表名 -L
    
    #-x 显示计数器的精确值
    iptables -t 表名 -v -x -L
    

    规则管理

    • [1]添加规则
    #在指定表指定链的尾部增加一条规则,省略-t时,表示默认操作filter表中的规则
    命令语法:iptables -t 表名 -A 链名 匹配条件 -j 动作
    示例:iptables -t filter -A INPUT -s 192.168.1.146 -j DROP
    
    #在指定表指定链的首部增加一条规则
    命令语法:iptables -t 表名 -I 链名 匹配条件 -j 动作
    示例:iptables -t filter -I INPUT -s 192.168.1.146 -j ACCEPT
    
    #在指定表指定链指定位置增加一条规则
    命令语法:iptables -t 表名 -I 链名 规则序号 匹配条件 -j 动作
    示例:iptables -t filter -I INPUT 5 -s 192.168.1.146 -j REJECT
    
    #设置指定表指定链的默认策略,并非添加规则
    命令语法:iptables -t 表名 -P 链名 动作
    示例:iptables -t filter -P FORWARD ACCEPT
    
    
    • [2] 删除规则
    #按照规则顺序删除,删除指定表指定链的指定规则
    命令语法:iptables -t 表名 -D 链名 规则序号
    示例:iptables -t filter -D INPUT 3
    
    #按照具体的匹配条件与动作删除,删除指定表的指定链的指定规则
    命令语法:iptables -t 表名 -D 链名 匹配条件 -j 动作
    示例:iptables -t filter -D INPUT -s 192.168.1.146 -j DROP
    
    #删除指定表指定链的所有规则
    命令语法:iptables -t 表名 -F 链名
    示例:iptables -t filter -F INPUT
    
    #删除指定表中的所有规则
    命令语法:iptables -t 表名 -F
    示例:iptables -t filter -F
    
    • [3] 修改规则
    #修改表中指定链的指定规则
    命令语法:iptables -t 表名 -R 链名 规则序号 规则原本的匹配条件 -j 动作
    示例:iptables -t filter -R INPUT 3 -s 192.168.1.146 -j ACCEPT
    其他方法:先删除,再在原编号位置添加一条规则
    
    #修改指定表的指定链的默认策略
    命令语法:iptables -t 表名 -P 链名 动作
    示例:iptables -t filter -P FORWARD ACCEPT
    
    • [4] 保存规则
    #保存命令
    service iptables save
    &  iptables-save > /etc/sysconfig/iptables
    
    #从指定的文件重载规则
    iptables-restore < /etc/sysconfig/iptables
    
  • 相关阅读:
    [LINUX-05]Linux的进程线程及调度
    如何感性地理解EM算法?
    [LINUX-04]linux进程、调度、线程、进程上下文等几点理解
    centos定时删除log文件
    关于 Nginx 配置的一些疑惑, Nginx 根据cookie 进行rewrite
    oracle中如何创建表的自增ID(通过序列)
    Windows下PHP7/5.6以上版本 如何连接Oracle 12c,并使用PDO
    Tomcat不能访问ln -s软连接文件夹的前因后果
    rm命令删除文件时排除特定文件
    nginx中的url转发
  • 原文地址:https://www.cnblogs.com/kcxg/p/10350870.html
Copyright © 2011-2022 走看看