温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

iptables 运行逻辑及-I -A 参数解析

发布时间:2020-05-30 18:52:29 来源:网络 阅读:2446 作者:AIOPS_DBA 栏目:安全技术

 

刚开始接触Iptables 就对-I  和 -A 参数很疑惑,-I 插入一条或多条规则 ,-A 是追加一条或多条规则。

都是加一条规则,究竟这两个有什么不同呢?

实验:

拿了两台机器,一台发PING包,一台被PING。

两台机器使用 iptables -nvL INPUT 查看,iptables 是空的

然后在被PING的机器加入 iptables -A INPUT -p icmp --icmp-type 8 -s 0/0 -j DROP 

再用 iptables -nvL INPUT 查看如下:

Chain INPUT (policy ACCEPT 592 packets, 55783 bytes)

 pkts bytes target     prot opt in     out     source               destination 

    8   672 DROP       icmp --  *      *       0.0.0.0/0            0.0.0.0/0           icmp type 8

此时发PING包的机器显示的PING包停住了。

此时在被PING的机器再加入 iptables -A INPUT -p icmp --icmp-type 8 -s 0/0 -j ACCEPT

再用 iptables -nvL INPUT 查看如下:

Chain INPUT (policy ACCEPT 678 packets, 62701 bytes)

 pkts bytes target     prot opt in     out     source               destination 

   21  1764 DROP       icmp --  *      *       0.0.0.0/0            0.0.0.0/0           icmp type 8

    0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           icmp type 8

显示iptables 被追加了一条规则,但发PING包的机器显示的PING包仍停住,证明新加入的规则不能放行PING包

在被PING的机器再加入iptables -I INPUT -p icmp --icmp-type 8 -s 0/0 -j ACCEPT

再用 iptables -nvL INPUT 查看如下:

Chain INPUT (policy ACCEPT 770 packets, 70223 bytes)

 pkts bytes target     prot opt in     out     source               destination 

    2   168 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           icmp type 8

   31  2604 DROP       icmp --  *      *       0.0.0.0/0            0.0.0.0/0           icmp type 8

    0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           icmp type 8

显示iptables 新增一条规则,此时发PING包的机器显示的PING包再次跳动,证明新加入的规则能放行PING包

而两个规则放行规则的差异只是 -A 和 -I ,-A 追加规则在DROP 规则后,-I增加规则在DROP 规则前。

iptables 是由上而下的进行规则匹配,放行规则需在禁行规则之前才能生效。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI