遇到一个神奇的 iptables 问题,求解!

2021-11-15 18:35:13 +08:00
 hyuhui

背景

1 、服务器为亚马逊的 aws lightsail ,今天新建的 2 、系统是 CentOS Linux release 7.9.2009 (Core) 3 、内核是 5.12.19-1.el7 4 、已安装 iptables-services ,iptables 的状态为运行中

问题

添加规则,service iptables save 保存,iptables -L 能看到规则,测试规则生效。

但是,只要断开 ssh ,或者 reboot 服务器,重新 ssh 进去,iptables -L 看到规则清零了,测试规则失效了。vi /etc/sysconfig/iptables 看到规则是在里面的,service iptables restart 后规则重新生效,iptables -L 也能重新看到规则了。

新建了几个实例也还是这样!我之前建的实例却不会出现这个情况。

哪位大神知道这是为什么?

3465 次点击
所在节点    Linux
27 条回复
defunct9
2021-11-15 18:48:55 +08:00
开 ssh ,让我上去看看
harde
2021-11-15 18:53:35 +08:00
+1
betteryjs
2021-11-15 18:53:39 +08:00
加到 rc.local 试试?
zhs227
2021-11-15 18:55:15 +08:00
没禁用 firewalld?
hyuhui
2021-11-15 18:58:21 +08:00
@zhs227 firewalld 已禁用

systemctl stop firewalld.service

systemctl disable firewalld.service
zhangsanfeng2012
2021-11-15 19:34:17 +08:00
systemctl status iptables 是什么状态
hyuhui
2021-11-15 19:56:04 +08:00
@zhangsanfeng2012

● iptables.service - IPv4 firewall with iptables
Loaded: loaded (/usr/lib/systemd/system/iptables.service; enabled; vendor preset: disabled)
Active: active (exited) since Mon 2021-11-15 19:09:08 CST; 44min ago
Process: 15421 ExecStop=/usr/libexec/iptables/iptables.init stop (code=exited, status=0/SUCCESS)
Process: 15450 ExecStart=/usr/libexec/iptables/iptables.init start (code=exited, status=0/SUCCESS)
Main PID: 15450 (code=exited, status=0/SUCCESS)

Nov 15 19:09:08 ip.ap-northeast-1.compute.internal systemd[1]: Stopped IPv4 firewall...
Nov 15 19:09:08 ip.ap-northeast-1.compute.internal systemd[1]: Starting IPv4 firewal...
Nov 15 19:09:08 ip.ap-northeast-1.compute.internal iptables.init[15450]: iptables: A...
Nov 15 19:09:08 ip.ap-northeast-1.compute.internal systemd[1]: Started IPv4 firewall...
Hint: Some lines were ellipsized, use -l to show in full.
ik
2021-11-15 20:09:42 +08:00
来两个终端,一个终端配了,另外一个终端能看到吗?
hyuhui
2021-11-15 20:19:48 +08:00
@ik 另一个终端,iptables -L 看不到,vi /etc/sysconfig/iptables 可以看到
ik
2021-11-15 20:33:39 +08:00
@hyuhui 神奇我也没遇到过😢
adoal
2021-11-15 20:45:00 +08:00
看看是不是 shell 的某个 rc 里 flush 了
nijux
2021-11-15 21:08:37 +08:00
aws lightsail 防火墙是不是要在网页后台设置啊,不用在服务器上设置
onetown
2021-11-15 22:22:55 +08:00
iptables-persistent 服务
另外 aws 上的安全组不是挺好用的吗
skiy
2021-11-15 22:23:16 +08:00
ihipop
2021-11-15 22:29:38 +08:00
centos7 哪来的原装 5.x 内核
yanqiyu
2021-11-15 23:08:06 +08:00
iptables 不会平白无故消失,所以肯定是什么东西给他 flush 掉了,

加上 #9 说道“另一个终端,iptables -L 看不到”
要不试一试两种情况,一种是先开两个终端,一个设置 iptables ,一个随后 iptables -L 看;另一种是开一个设置 iptables ,然后开第二个 iptables -L 看。后者就说明登陆过程中有什么东西给它 flush 掉了,前者说明更玄学的事情发生了(无意间设置了 namespace 之类的)

既然“新建了几个实例也还是这样”并且这个问题没有被大规模报告。能不能细节的讲一下你在“新建了几个实例”之后进行的所有操作?
Buges
2021-11-15 23:39:15 +08:00
你既然是 systemd 的系统,为啥要用 service 呢。

systemctl show iptables.service 输出里面找到 iptables-restore 命令的参数就是保存持久化 iptables 规则的地方。

把你的 iptables 规则写到这个文件里,或者用 iptables-save 的输出保存到这个文件,然后 systemctl enable --now iptables.service;systemctl reload iptables.service 就可以了。
TsukiMori
2021-11-16 02:15:40 +08:00
lightsail 不直接在 web 管理配置防火墙就可以嘛
holinhot
2021-11-16 03:56:03 +08:00
AWS 自带防火墙网页管理。没有 VNC ,难道系统模版强刷了 iptables 防止你被锁在外面。
hyuhui
2021-11-16 09:19:09 +08:00
@yanqiyu 一种是先开两个终端,一个设置 iptables ,一个随后 iptables -L 看:这个通过 iptables -L 可以看到!

报告给亚马逊了,还没有回复。

试过 centos7 、centos8 、debian10 ,新建实例后只安装 iptables-services ( centos )或者 iptables-persistent ( debian ),然后也会出现这个情况。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/815599

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX