先说结论,ip6tables 需要允许 ICMPv6 通过,IPv6 高度依赖 ICMPv6。

iptables

IPv4 的规则主要参考了 Debian 的文档 iptables

*filter

-A INPUT -i lo -j ACCEPT -m comment --comment "Loopback"
-A INPUT ! -i lo -d 127.0.0.0/8 -j DROP
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

-A INPUT -p icmp -m icmp --icmp-type 8 -m limit --limit 7/minute -j ACCEPT -m comment --comment "Ping"

-A INPUT -p tcp --dport 80 -j ACCEPT -m comment --comment "HTTP"
-A INPUT -p tcp --dport 443 -j ACCEPT -m comment --comment "HTTPS"

-A OUTPUT -j ACCEPT
-A INPUT -j DROP
-A FORWARD -j DROP

COMMIT

ip6tables

复制粘贴 IPv4 的规则,改下协议,搞定 IPv6 无法连接。

ip6tables 资料不多,查了好久才看到 GitHub 上的一份规则,里面关于 ICMPv6 有一行注释

# Accept all ICMP packets. Unlike with IPv4, it's not a good idea to block ICMPv6 traffic as IPv6 is much more heavily dependent on it:

ip6tables -A INPUT -p ipv6-icmp -j ACCEPT

参考 ICMPv6 的 Wiki,原因之一应该是 IPv6 的 NDP 协议。NDP 用于替代 IPv4 的 ARP,且基于 ICMPv6,而 ARP 则是基于 IPv4 的。ICMPv6 整合实现了 IPv4 中的 ICMP、ARP 以及 IGMP 的所有功能,为了正常使用 IPv6 ,需要允许 ICMPv6 流量通过。

Last modification:October 4, 2022
如果觉得我的文章对你有用,请随意赞赏