iptables中

编程入门 行业动态 更新时间:2024-10-06 06:44:50

<a href=https://www.elefans.com/category/jswz/34/1764711.html style=iptables中"/>

iptables中

在使用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 */

结果已经很清楚了

更多推荐

iptables中

本文发布于:2024-02-14 12:59:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1763560.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:iptables

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!