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
![](https://img.haomeiwen.com/i12979420/f2fe3701f5cfbb4d.png)
127.0.0.1 没有加进去
说明 执行 /path/to/zookeeper/bin/zkServer.sh status 会从 127.0.0.0.1 -----> 发起对 zk的连接 。
$ sudo iptables -nvL --line
![](https://img.haomeiwen.com/i12979420/d665d6ee20299e72.png)
$ sudo iptables -I INPUT -s 127.0.0.1 -p tcp -m tcp --dport 2181 -j ACCEPT
![](https://img.haomeiwen.com/i12979420/4d7c6668856e8ef6.png)
![](https://img.haomeiwen.com/i12979420/81aac7ba33db2618.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
网友评论