大网数据广告活动
服务器运维问答

Allowing inbound IPv6 traffic to a host and port when the IPv6 prefix is dynamic?

· 52CE 我爱测

With IPv4, you used to be able to give a host a static local IP address on the LAN, and use a firewall rule on the firewall/router to forward a port on the (possibly dynamic) Internet-facing IP used by the network to a port on ta…

问题原文

原帖链接 · interfect · CC BY-SA 4.0

With IPv4, you used to be able to give a host a static local IP address on the LAN, and use a firewall rule on the firewall/router to forward a port on the (possibly dynamic) Internet-facing IP used by the network to a port on tat particular host, using the host's static LAN IPv4 address as a stable way to identify the host in the firewall rule.

But with IPv6, every host is using real routable Internet IPs, so the incoming traffic for the host will already be addressed to it, and there's no need for NAT. But you still need to be able to write a firewall rule to say that inbound traffic to one particular host and port should be allowed, while traffic to other hosts or ports is blocked.

But if the prefix under which the network assigns IPv6 addresses is dynamic, how would you refer to a particular host in a firewall rule to allow traffic to it? You can't just allow traffic to its IPv6 address, because next week it will have an IPv6 address with a different prefix, because the ISP will have assigned the network a different prefix.

How do you then actually configure a firewall to allow inbound traffic to that host on some port? In ip6tables it looks like there's a --dest option to match by destination, but that only seems to let you put in an entire address and not e.g. a suffix of the address which you can ensure is kept static for a host. From the man page:

       [!] -s, --source address[/mask][,...]
              Source  specification.  Address can be either a network name, a
              hostname, a network IP address (with /mask), or a plain IP  ad‐
              dress. Hostnames will be resolved once only, before the rule is
              submitted to the kernel.  Please note that specifying any  name
              to  be resolved with a remote query such as DNS is a really bad
              idea.  The mask can be either an ipv4 network mask  (for  ipta‐
              bles)  or  a  plain number, specifying the number of 1's at the
              left side of the network mask.  Thus, an iptables mask of 24 is
              equivalent to 255.255.255.0.  A "!" argument before the address
              specification inverts the sense of the address. The flag  --src
              is  an alias for this option.  Multiple addresses can be speci‐
              fied, but this will expand to multiple rules (when adding  with
              -A), or will cause multiple rules to be deleted (with -D).

       [!] -d, --destination address[/mask][,...]
              Destination  specification.   See  the  description  of  the -s
              (source) flag for a detailed description of  the  syntax.   The
              flag --dst is an alias for this option.

Is there a way to handle this with ip6tables? Is there some other layer over ip6tables that is supposed to generate rules that change as the network is renumbered, that everyone is actually using? Is there some kind of ip6tables plugin that can let me match traffic that will go to a particular host even if the network number changes? Do other OS firewalls handle this differently?

已采纳解答

原帖链接 · Florian Bach · CC BY-SA 4.0

ip6tables accepts a bitmask for the address. Unlike with iptables and IPv4, these bits don't necessarily all have to be at the beginning of the address, so something like this should work fine:

ip6tables -A INPUT -d ::1234:56ff:fe78:90ab/::ffff:ffff:ffff:ffff -j ACCEPT

That would make ip6tables accept all packets going to an IPv6 address that ends in ::1234:56ff:fe78:90ab, no matter the prefix.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2022-12-05)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。