IPTables 没有按照我的要求执行

IPTables 没有按照我的要求执行

这里的社区太棒了!

我有一台华硕 3100 无线路由器和大约 4 个 IP 摄像头。在我的旧路由器上,很容易阻止传出流量,这样我就可以确保摄像头不会“呼叫回家”。我想对这台路由器做同样的事情,所以我决定首先使用端口转发工具,然后开始查找 IPTABLES。 我不知道这是否是 asuswrt-merlin 使用路由器管理工具和 iptables 上的端口转发的问题。我怀疑不是...对吧?

我的目标:

  1. 默认情况下阻止 192.168.1.0/29 的传出和传入流量
  2. 例外:我想打开 120:130,但只对少数几个受信任的 IP(工作或朋友家)开放。假设这些 IP 是 150.150.150.150 和 250.250.250.0/24(我使用浏览器访问这些端口,但这可能并不重要),所以如果我想访问 CAMERA #2,它将是 DDNS.dns.com:121
  3. 例外:摄像机通过 SMTPS(端口 465)发送电子邮件,所以我想打开它以便它可以发送电子邮件。

我不想阻止输入/输出,因为我有一些与其他地方通信的 IoT 设备,所以我不想更改默认策略来阻止它。除非我误解了它的工作原理。

我用最新的 Asuswrt-Merlin 刷新了路由器,并打开了 JFFS 自定义脚本。我在/jffs/scripts/名为下创建了一个名为 的文件firewall-start。我从 shebang 开始编辑了该文件并添加了一些规则(稍后会回到这里)。我使用了service restart_firewall。我遇到的问题是我没有得到适当的结果,而且很可能是我写错了规则和/或顺序。

我尝试过 iptables forward,尝试过 iptables INPUT & OUTPUT,还尝试过“INSERT”/“APPEND”的组合,但出于某种奇怪的原因,它要么会阻止所有内容,要么会完全打开。它从来都不符合我的最终目标。我确信这与 FORWARD、INPUT 或 OUTPUT 的某些顺序或默认规则有关,但我就是搞不清楚。

我也是一次插入一条规则。开始很简单。

iptables -I FORWARD -d 192.168.1.0/29 -p tcp --dport 17111 -j DROP

这样就可以删除它。有时这很棘手,因为如果我尝试 canyouseeme.org 并且它说成功输入代码它仍然说成功。有时它说它失败(意味着它被删除了)所以有时这就是我遇到的但听起来可能是一个不相关的问题。然后我对自己说好的,这有效。现在让我们在这之后添加一个 INSERT 规则,因为显然 INSERT 会转到顶部所以我在上面的代码后面添加了这个:

iptables -I FORWARD -s myworkip -d 192.168.1.0/29 -p tcp --dport 121 -j ACCEPT

因此,将这两个文件放在文件中。我刷新 iptables,然后重新启动防火墙启动服务,使其获取新规则。我使用时,iptables -L我看到它的顺序正确。通过重新加载网页 ddns.dns.com:121 进行测试,但什么也没有。它不会加载。是一些缓存吗?需要时间吗?有时我等了 5 分钟,仍然没有结果。我再次使用 canyouseeme.org,它仍然显示最后一个 DROP 代码失败。

我需要一些专家来帮助我。这是我目前现有的 iptable:

Chain INPUT (policy ACCEPT)
target     prot opt source               destination
DROP       icmp --  anywhere             anywhere             icmp echo-request
ACCEPT     all  --  anywhere             anywhere             state RELATED,ESTABLISHED
DROP       all  --  anywhere             anywhere             state INVALID
PTCSRVWAN  all  --  anywhere             anywhere
PTCSRVLAN  all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere             state NEW
ACCEPT     all  --  anywhere             anywhere             state NEW
OVPN       all  --  anywhere             anywhere             state NEW
ACCEPT     udp  --  anywhere             anywhere             udp spt:bootps dpt:bootpc
INPUT_ICMP  icmp --  anywhere             anywhere
DROP       all  --  anywhere             anywhere

Chain FORWARD (policy DROP)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere             state RELATED,ESTABLISHED
other2wan  all  --  anywhere             anywhere
DROP       all  --  anywhere             anywhere             state INVALID
ACCEPT     all  --  anywhere             anywhere
NSFW       all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere             ctstate DNAT
OVPN       all  --  anywhere             anywhere             state NEW
ACCEPT     all  --  anywhere             anywhere

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Chain ACCESS_RESTRICTION (0 references)
target     prot opt source               destination

Chain FUPNP (0 references)
target     prot opt source               destination

Chain INPUT_ICMP (1 references)
target     prot opt source               destination
RETURN     icmp --  anywhere             anywhere             icmp echo-request
RETURN     icmp --  anywhere             anywhere             icmp timestamp-request
ACCEPT     icmp --  anywhere             anywhere

Chain NSFW (1 references)
target     prot opt source               destination

Chain OVPN (2 references)
target     prot opt source               destination

Chain PControls (0 references)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere

Chain PTCSRVLAN (1 references)
target     prot opt source               destination

Chain PTCSRVWAN (1 references)
target     prot opt source               destination

Chain SECURITY (0 references)
target     prot opt source               destination
RETURN     tcp  --  anywhere             anywhere             tcpflags: FIN,SYN,RST,ACK/SYN limit: avg 1/sec burst 5
DROP       tcp  --  anywhere             anywhere             tcpflags: FIN,SYN,RST,ACK/SYN
RETURN     tcp  --  anywhere             anywhere             tcpflags: FIN,SYN,RST,ACK/RST limit: avg 1/sec burst 5
DROP       tcp  --  anywhere             anywhere             tcpflags: FIN,SYN,RST,ACK/RST
RETURN     icmp --  anywhere             anywhere             icmp echo-request limit: avg 1/sec burst 5
DROP       icmp --  anywhere             anywhere             icmp echo-request
RETURN     all  --  anywhere             anywhere

Chain default_block (0 references)
target     prot opt source               destination

Chain logaccept (0 references)
target     prot opt source               destination
LOG        all  --  anywhere             anywhere             state NEW LOG level warning tcp-sequence tcp-options ip-options prefix "ACCEPT "
ACCEPT     all  --  anywhere             anywhere

Chain logdrop (0 references)
target     prot opt source               destination
LOG        all  --  anywhere             anywhere             state NEW LOG level warning tcp-sequence tcp-options ip-options prefix "DROP "
DROP       all  --  anywhere             anywhere

Chain other2wan (1 references)
target     prot opt source               destination
RETURN     all  --  anywhere             anywhere
DROP       all  --  anywhere             anywhere

提前致谢!

相关内容