背景
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 也能重新看到规则了。
新建了几个实例也还是这样!我之前建的实例却不会出现这个情况。
哪位大神知道这是为什么?
![]() | 1 defunct9 2021-11-15 18:48:55 +08:00 ![]() 开 ssh ,让我上去看看 |
![]() | 2 harde 2021-11-15 18:53:35 +08:00 +1 |
3 betteryjs 2021-11-15 18:53:39 +08:00 加到 rc.local 试试? |
![]() | 4 zhs227 2021-11-15 18:55:15 +08:00 没禁用 firewalld? |
5 hyuhui OP |
![]() | 6 zhangsanfeng2012 2021-11-15 19:34:17 +08:00 systemctl status iptables 是什么状态 |
7 hyuhui OP @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. |
![]() | 8 ik 2021-11-15 20:09:42 +08:00 via iPhone 来两个终端,一个终端配了,另外一个终端能看到吗? |
![]() | 11 adoal 2021-11-15 20:45:00 +08:00 via iPhone 看看是不是 shell 的某个 rc 里 flush 了 |
![]() | 12 nijux 2021-11-15 21:08:37 +08:00 aws lightsail 防火墙是不是要在网页后台设置啊,不用在服务器上设置 |
![]() | 13 onetown 2021-11-15 22:22:55 +08:00 iptables-persistent 服务 另外 aws 上的安全组不是挺好用的吗 |
![]() | 14 skiy 2021-11-15 22:23:16 +08:00 |
![]() | 15 ihipop 2021-11-15 22:29:38 +08:00 via Android centos7 哪来的原装 5.x 内核 |
16 yanqiyu 2021-11-15 23:08:06 +08:00 iptables 不会平白无故消失,所以肯定是什么东西给他 flush 掉了, 加上 #9 说道“另一个终端,iptables -L 看不到” 要不试一试两种情况,一种是先开两个终端,一个设置 iptables ,一个随后 iptables -L 看;另一种是开一个设置 iptables ,然后开第二个 iptables -L 看。后者就说明登陆过程中有什么东西给它 flush 掉了,前者说明更玄学的事情发生了(无意间设置了 namespace 之类的) 既然“新建了几个实例也还是这样”并且这个问题没有被大规模报告。能不能细节的讲一下你在“新建了几个实例”之后进行的所有操作? |
![]() | 17 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 就可以了。 |
![]() | 18 TsukiMori 2021-11-16 02:15:40 +08:00 via Android lightsail 不直接在 web 管理配置防火墙就可以嘛 |
![]() | 19 holinhot 2021-11-16 03:56:03 +08:00 AWS 自带防火墙网页管理。没有 VNC ,难道系统模版强刷了 iptables 防止你被锁在外面。 |
20 hyuhui OP @yanqiyu 一种是先开两个终端,一个设置 iptables ,一个随后 iptables -L 看:这个通过 iptables -L 可以看到! 报告给亚马逊了,还没有回复。 试过 centos7 、centos8 、debian10 ,新建实例后只安装 iptables-services ( centos )或者 iptables-persistent ( debian ),然后也会出现这个情况。 |
21 julyclyde 2021-11-16 11:00:09 +08:00 @Buges redhat 系用 service 没啥毛病。systemd 时代的 service 和 sysvinit 时代的 service 并不是同样内容的脚本;再说 iptables 也不是个正经 systemd service |
22 yanqiyu 2021-11-16 11:37:18 +08:00 ![]() @hyuhui 那就说明登陆过程有啥东西 flush 了 iptables 要不试一试 https://unix.stackexchange.com/questions/206891/audit-on-changes-to-the-running-iptables-configuration 里面的方法设置 audit 规则追踪一下 |
23 snuglove 2021-11-16 11:41:58 +08:00 我都是使用 iptables-save >/etc/sysconfig/iptables 来保存,保存完了在重启 |
24 hyuhui OP 报告各位 今天尝试了一下,昨天建的实例,问题依旧,但是今天新建的实例已经没有问题了,估计是 AWS 自己的问题 |
![]() | 25 Buges 2021-11-16 14:01:38 +08:00 via Android @julyclyde systemd 虽然有 sysvcompat 兼容以前的脚本,但没理由去用它啊,没有 /etc/init.d ,service 的啥行为都不知道。在我这里 iptables.service 是个正经的 oneshot systemd service ,rh 系统上还有啥区别吗? |
![]() | 27 SkyHive 2021-11-17 17:00:35 +08:00 看看 bashrc 或者 /etc/profile 里有没有奇怪的东西 flush 你得 iptables |