刚开始接触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 是由上而下的进行规则匹配,放行规则需在禁行规则之前才能生效。iptables 运行逻辑及-I -A 参数解析iptables 运行逻辑及-I -A 参数解析相关资讯 IpTables iptables参数
- CentOS Samba 服务器 Iptables 和 (今 07:14)
- iptables超全详解 (09月01日)
- Iptables防火墙 基础知识 (08月19日)
| - Iptables工作原理使用详解 (09月06日)
- iptables中NAT表 (08月25日)
- Linux 为FTP 服务器添加iptables规 (08月11日)
|
本文评论 查看全部评论 (0)
评论声明- 尊重网上道德,遵守中华人民共和国的各项有关法律法规
- 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
|