美文网首页
【iptables】关于iptabels的-A与-I参数的区别

【iptables】关于iptabels的-A与-I参数的区别

作者: Bogon | 来源:发表于2023-11-25 09:52 被阅读0次

iptables -A 与 -I 的重要性:

-A添加规则的参数,是添加规则在现有的后面
-I添加规则的参数,是添加在规则在现有的前面

如果是互不干涉的规则端口使用-A没关系不会受影响。

#!/bin/bash

ips="
xx.xx.xx.xx
xx.xx.xx.xx
"
infra='zookeeper'
port="2181"

for ip  in ${ips[@]}

do
     sudo iptables -A INPUT -s $ip  -p tcp -m tcp --dport $port -j ACCEPT
done
     sudo iptables -A INPUT -p tcp -m tcp --dport $port -j DROP
image.png

127.0.0.1 没有加进去

说明 执行 /path/to/zookeeper/bin/zkServer.sh status 会从 127.0.0.0.1 -----> 发起对 zk的连接 。

$ sudo iptables -nvL --line
image.png
$ sudo iptables -I INPUT -s  127.0.0.1  -p tcp -m tcp --dport 2181 -j ACCEPT
image.png image.png

参考

关于iptabels的-A与-I参数
https://blog.csdn.net/weixin_46152207/article/details/112505965

iptables小册
https://www.zsythink.net/archives/category/%e8%bf%90%e7%bb%b4%e7%9b%b8%e5%85%b3/iptables

相关文章

网友评论

      本文标题:【iptables】关于iptabels的-A与-I参数的区别

      本文链接:https://www.haomeiwen.com/subject/aucuudtx.html