iptables中 -A 和 -I 参数的区别

在使用iptables添加规则的过程中,看到-A和-I参数都是添加规则,刚开始容易混淆,然后就专门试了一下,原来差异在这里

我们直接看实验吧

有以下四条规则

iptables -A INPUT -s 1.1.0.0/24 -j ACCEPT
iptables -A INPUT -s 2.2.0.0/24 -j DROP
iptables -A INPUT -s 3.3.0.0/24 -j ACCEPT
iptables -A INPUT -s 4.4.0.0/24 -j DROP

执行完结果

[root@k8s-node2 ~]# iptables -L --line-number
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination         
1    KUBE-FIREWALL  all  --  anywhere             anywhere            
2    KUBE-SERVICES  all  --  anywhere             anywhere             ctstate NEW /* kubernetes service portals */
3    KUBE-EXTERNAL-SERVICES  all  --  anywhere             anywhere             ctstate NEW /* kubernetes externally-visible service portals */
4    ACCEPT     all  --  1.1.0.0/24           anywhere            
5    DROP       all  --  2.2.0.0/24           anywhere            
6    ACCEPT     all  --  3.3.0.0/24           anywhere            
7    DROP       all  --  4.4.0.0/24           anywhere          

删除上述4、5、6、7号规则,然后是-I

iptables -I INPUT -s 1.1.0.0/24 -j ACCEPT
iptables -I INPUT -s 2.2.0.0/24 -j DROP
iptables -I INPUT -s 3.3.0.0/24 -j ACCEPT
iptables -I INPUT -s 4.4.0.0/24 -j DROP

执行完结果

[root@k8s-node2 ~]# iptables -L --line-number
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination         
1    DROP       all  --  4.4.0.0/24           anywhere            
2    ACCEPT     all  --  3.3.0.0/24           anywhere            
3    DROP       all  --  2.2.0.0/24           anywhere            
4    ACCEPT     all  --  1.1.0.0/24           anywhere            
5    KUBE-FIREWALL  all  --  anywhere             anywhere            
6    KUBE-SERVICES  all  --  anywhere             anywhere             ctstate NEW /* kubernetes service portals */
7    KUBE-EXTERNAL-SERVICES  all  --  anywhere             anywhere             ctstate NEW /* kubernetes externally-visible service portals */
          

结果已经很清楚了

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值