You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
stub listener should support hosts that have no ipv4 at all #15615
why would it matter which transport is used locally between the local client and local resolved?
The thing is that on IPv4 there's a whole range of loopback addresses, i.e. everything in 127.0.0.0/8. We can thus pick an IP address of our own to bind our stub to, i.e. 127.0.0.53, leaving the primary loopback address 127.0.0.1 untouched. For IPv6 that doesn't exist, there's only a single loopback address defined, not a full range, hence we'd have to bind to ::1 there taking possession of that port on the primary loopback interface. Hence we figured, let's not do that, for local communcation there's no benefit of using Ipv6 anyway.
So, why would you want to insist on using Ipv6 as host-internal transport here?
Note that resolved will use Ipv6 just fine when talking to upstream hosts, even if you talk ipv4 to it locally
There is a functional difference between resolving IPv6 addresses via an IPv4 DNS server, and resolving IPv6 via IPv6. When specifying host -6 you are requesting the later, which the 127.0.0.53 stub is not suitable for. The local resolver should listen on ::1 as well as a 127/8 address to satisfy both host -4 and host -6.
$ host -6 google.com
google.com has address 172.217.14.206
google.com has IPv6 address 2607:f8b0:4006:806::200e
google.com mail is handled by 40 alt3.aspmx.l.google.com.
google.com mail is handled by 30 alt2.aspmx.l.google.com.
google.com mail is handled by 20 alt1.aspmx.l.google.com.
google.com mail is handled by 10 aspmx.l.google.com.
google.com mail is handled by 50 alt4.aspmx.l.google.com.
As it currently stands, any application attempting to perform IPv6-only behavior (w/out IPv4 fallback) will fail DNS lookups.
I honestly do not follow the argument of "why would you do it that way". The bottom line is that the system fails to work as expected given the current configuration enforced by systemd-resolved. When the base system fails to operate given a documented command, it seems the goal should be identifying and fixing the cause of the failure, which I believe has been done. Your suggestion seems to be that we should remove pure IPv6 lookup paths from the system. Are you saying I should open a bug against host-utils to remove host -6?
To be clear, the solution appears to be for systemd-resolved to bind to also bind to ::1 and that would allow the rest of the OS resolver to work with IPv6-only paths.
It is also curious that resolvectl -6 query google.com works by passing through the IPv6 path, but regular system commands which support an IPv6-only path will fail.
I don't get it. We don#t list an IPv6 server in the resolv.conf we provide, only an IPv4 one. So all software reading that should understand we only listen on Ipv4 for the stub. Whch ipv6 host does "host -6" even connect to if the resolv.conf doesn't list any ipv6 address?
When you ask for an IPv6 only resolution path, then the system will not use an IPv4 name from /etc/resolv.conf. My above demonstration shows that if I manually add an IPv6 DNS name to /etc/resolv.conf, then host -6 works. In the case of resolvctl -6, that command knows to use the DNS IPv6 address which can be found in the output of resolvctl (as opposed to /etc/resolv.conf). Since my network advertises IPv4 and IPv6 DNS servers, then resolvctl -6will use the IPv6 DNS server that systemd-resolved knows about, but which is not made available to the general libc resolver(3)/getaddrinfo(3) via the 127.0.0.53 stub.
The bug behavior outlined is a result of systemd-resolved's configuration supplying an IPv4-only resolution path via 127.0.0.53. While resolvectl has access to an IPv6 resolution path, it is not making that path available to the general resolve(3)/getaddrinfo(3) libc interface.
i don't get it. what matters is the protocol spoken between resolved and upstream. But how you can contact the stub shouldn't matter, as long as we only advertise the protocol we actually implement. And we do that. The stub resolv.conf file we provide only lists 127.0.0.53, and nothing else. We don#t advertise an ipv6 resolv.conf entry because we don't do ipv6 for that, because there's really no need for that.
-4
Use IPv4 only for query transport. See also the -6 option.
-6
Use IPv6 only for query transport. See also the -4 option.
Note the words "query transport". The transport has nothing to do with the content of the query.
host is a binary shipped with BIND meant for testing/debugging. host -6 is meant for testing DNS servers that listen on an IPv6 address. systemd does not provide such a DNS server, and that's perfectly fine.
So, to be clear, we are saying it is fine to break applications which can request IPv6 transport for DNS resolution such as dig and host and possibly others. And this is on the assumption that no functional application will have any justification for performing a getaddrinfo(3) w/ AF_INET6 only?
AFAIK, getaddrinfo does not have a mechanism to tell the resolver which protocol should be used for the query transport. If you are referring to the ai_family member of the struct addrinfo *hintsparameter, that is used to filter the protocol family that should be used for the query results.
So, to be clear, we are saying it is fine to break applications which can request IPv6 transport for DNS resolution such as dig and host and possibly others.
There is no requirement that resolv.conf must contain both an IPv4 and an IPv6 nameserver. If you want to use tools like dig and host with IPv6 transport, you can add other nameservers to resolv.conf yourself, or pass a nameserver address on the command line.
AFAIK, getaddrinfo does not have a mechanism to tell the resolver which protocol should be used for the query transport. If you are referring to the ai_family member of the struct addrinfo *hintsparameter, that is used to filter the protocol family that should be used for the query results.
Hmm.. I was actually thinking of ai.protocol = IPPROTO_IPV6.
Hmm.. I was actually thinking of ai.protocol = IPPROTO_IPV6.
From what I can tell, IPPROTO_IPV6 is really only used for setsockopt(). You would never pass it to the socket() function, and using it as an addrinfo hint would be really weird.
Note that, per the documentation, adding extra nameservers to resolved's builtin resolv.conf files does not seem well-supported and if you don't make /etc/resolv.conf a symlink to one of the managed files, it signals that you want different behavior:
Four modes of handling /etc/resolv.conf (see resolv.conf(5)) are supported:
systemd-resolved maintains the /run/systemd/resolve/stub-resolv.conf file for compatibility with traditional Linux programs. This file lists the 127.0.0.53 DNS stub (see above) as the only DNS server. It also contains a list of search domains that are in use by systemd-resolved. The list of search domains is always kept up-to-date. Note that /run/systemd/resolve/stub-resolv.conf should not be used directly by applications, but only through a symlink from /etc/resolv.conf. This file may be symlinked from /etc/resolv.conf in order to connect all local clients that bypass local DNS APIs to systemd-resolved with correct search domains settings. This mode of operation is recommended.
A static file /usr/lib/systemd/resolv.conf is provided that lists the 127.0.0.53 DNS stub (see above) as only DNS server. This file may be symlinked from /etc/resolv.conf in order to connect all local clients that bypass local DNS APIs to systemd-resolved. This file does not contain any search domains.
systemd-resolved maintains the /run/systemd/resolve/resolv.conf file for compatibility with traditional Linux programs. This file may be symlinked from /etc/resolv.conf and is always kept up-to-date, containing information about all known DNS servers. Note the file format's limitations: it does not know a concept of per-interface DNS servers and hence only contains system-wide DNS server definitions. Note that /run/systemd/resolve/resolv.conf should not be used directly by applications, but only through a symlink from /etc/resolv.conf. If this mode of operation is used local clients that bypass any local DNS API will also bypass systemd-resolved and will talk directly to the known DNS servers.
Alternatively, /etc/resolv.conf may be managed by other packages, in which case systemd-resolved will read it for DNS configuration data. In this mode of operation systemd-resolved is consumer rather than provider of this configuration file.
Note that the selected mode of operation for this file is detected fully automatically, depending on whether /etc/resolv.conf is a symlink to /run/systemd/resolve/resolv.conf or lists 127.0.0.53 as DNS server.
@clhodapp In stub mode (that's the case when "symlinked to /run/systemd/resolve/resolv.conf or lists 127.0.0.53") it's intentional to not manage your additional resolvers via an entry in resolv.conf. It's resolved's task to find out which resolver to use depending on the link the traffic goes through. You can check this with the resolvectl command:
root@server:~# resolvectl
Global
Protocols: +LLMNR +mDNS -DNSOverTLS DNSSEC=no/unsupported
resolv.conf mode: stub
[...]
Link 6 (enp8s6)
Current Scopes: none
Protocols: -DefaultRoute -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
Link 7 (tunl0)
Current Scopes: none
Protocols: -DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
Link 8 (br0)
Current Scopes: DNS LLMNR/IPv4 LLMNR/IPv6 mDNS/IPv4 mDNS/IPv6
Protocols: +DefaultRoute +LLMNR +mDNS -DNSOverTLS DNSSEC=no/unsupported
Current DNS Server: x.x.x.x
DNS Servers: x.x.x.x yyyy:y::y:y
DNS Domain: your_domain.net
[...]
Link 15 (wan0)
Current Scopes: DNS
Protocols: +DefaultRoute -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
Current DNS Server: zzzz:zzz:z:zzzz::53
DNS Servers: zzzz:zzz:z:zzzz::53 zzzz:zzz:z:zzzz::53
It not only shows you the resolvers used for a specific link but which scopes and protocols as well as the default domain. So in my scenario here any WAN traffic to the outside world would first go to 127.0.0.53 of resolved which will then pass it to the zzzz:zzz:z:zzzz::53 server while the internal bridge on Link 8 uses x.x.x.x yyyy:y::y:y servers.
To configure a specific resolver for a link you use systemd-networkd via /etc/systemd/network/*.network files on top of your *.netdev file (eg: br0) where you define the domain running on that link:
[Match]
Name=br0
[Network]
Description=Main bridge & link local traffic
[...]
LLMNR=true
MulticastDNS=true
DNS=x.x.x.x
DNS=yyyy:y::y:y
Domains=your_domain.net
[...]
This extremely useful when you're running multiple WAN links with each their own DNS and further you can separate protocols like LLMNR or mDNS to not occur on your WAN links or other issues like your default search domain not being effective for any link ... etc.
@3ronco There are definitely some great benefits to using the stub resolver. But that brings us back to the original observation:
The generated resolve.conf for the stub resolver doesn't ever list any IPv6 addresses, meaning that programs on the machine that only speak IPv6 (for whatever reason) cannot reach the stub resolver unless you apply a some kind of hacky workaround.
This could come up if you are using a program that (for some odd reason) is designed to use IPv6 only, if the user configures their machine to truly have no IPv4 support to blaze a trail for the future, or (most likely) if they explicitly tell the program to use IPv6 only for some diagnostic purpose.
So, what we probably could get away with if we pick some ipv6 address from the ULA range, auto-add it to "lo", and then bind our socket to that. e.g fc53:5353:5353:5353:5353:5352:5353:5353/128 or so. that should pretty much work, and the chance of collision is extremely small (i.e. as in UUIDs).
aah ok, now i see, @clhodapp is talking about the stub IP given in resolv.conf using 127.0.0.53 instead of eg. fc53:5353:5353:5353:5353:5352:5353:5353/128, could be shorter 😏
Yes that would be a way or even a chance to get rid of IPv4 completely with a IPv6-only notation in resolv.conf and handling IPv4 addresses over AF_INET6 sockets for backwards compatibility. That enforces IPv6 for IPv4 stacks but not the other way around.
Given Lennart's reply, my vision is to update resolved to generalize its behavior:
It would now automatically try to bind to addresses 53 and 54 of any IPv4 block that's at least /24 and any IPv6 block that's at least /96 on a loopback interface. For example, if there is an address on a loopback interface, fde1:321e:75a8:1::1/64, resolved would try to bind to fde1:321e:75a8:1::53 and fde1:321e:75a8:1::54. The generated stub resolv.conf would automatically include any 53 address that is bound through this technique.
It could also be considered whether networkd should add an IPv6 address block based on a ULA to any loopback interface that it manages by default.
Testing
I've tried to do some POC-ing of the viability of this vision on a networking level. Unfortunately, the results are not promising: It seems that networks on IPv6 loopback interfaces might be broken.
IPv4
Let's start with IPv4, which works.
I can bind an additional address to my loopback interface:
chris@chris-desktop
~ $ sudo ip -4 address add local '192.168.3.1/24' dev lo scope host
We can see that this results in an address that is pretty much just like the automatically-set-up 127.0.0.1:
Even though we requested that the address be added with scope host and the command succeeded, the created address shows "scope": "global". This can be regarded as a mere oddity, though, since "scope": "host" is not critical for the address to work properly for our purposes and the IPv4 process described above works just as well if the address is created with scope global.
If we check our routes, we find a bigger issue:
chris@chris-desktop
~ $ ip -6 --json --pretty --details route list table local dev lo
[ {
"type": "local",
"dst": "::1",
"protocol": "kernel",
"scope": "global",
"metric": 0,
"flags": [ ],
"pref": "medium"
},{
"type": "local",
"dst": "fde1:321e:75a8:1::1",
"protocol": "kernel",
"scope": "global",
"metric": 0,
"flags": [ ],
"pref": "medium"
} ]
It looks like we've only ended up with an automatic route for our exact /128.
As might be expected, we can only ping ourselves on fde1:321e:75a8:1::1 at this point:
chris@chris-desktop
~ $ ping -c1 -W1 'fde1:321e:75a8:1::1'
PING fde1:321e:75a8:1::1 (fde1:321e:75a8:1::1) 56 data bytes
64 bytes from fde1:321e:75a8:1::1: icmp_seq=1 ttl=64 time=0.034 ms
--- fde1:321e:75a8:1::1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.034/0.034/0.034/0.000 ms
chris@chris-desktop
~ $ ping -c1 -W1 'fde1:321e:75a8:1::2'
PING fde1:321e:75a8:1::2 (fde1:321e:75a8:1::2) 56 data bytes
--- fde1:321e:75a8:1::2 ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms
This is already a bit of an issue, since the local table is supposed be managed automatically by the kernel. However, we can ignore that and add our own route with:
sudo ip -6 route add local 'fde1:321e:75a8:1::/64' src 'fde1:321e:75a8:1::1' table local proto boot scope host metric 0 dev lo dev lo
The route is created. However, our desired metric of 0 has been silently replaced with 1024. Note that a similar command a metric value of 1 is accepted and correctly applied to the route if run instead. However: We know that 0 is not an entirely invalid value, as we can plainly see that the routes created automatically by the kernel all have "metric": 0. Also, our scope host value has been ignored again. In this case, even the kernel's own routes have "scope": "global", which is incongruous with the behavior for IPv4.
Now that our route is created, we can ping ourselves on any address within fde1:321e:75a8:1::/64:
chris@chris-desktop
~ $ ping -c1 -W1 'fde1:321e:75a8:1::1'
PING fde1:321e:75a8:1::1 (fde1:321e:75a8:1::1) 56 data bytes
64 bytes from fde1:321e:75a8:1::1: icmp_seq=1 ttl=64 time=0.033 ms
--- fde1:321e:75a8:1::1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.033/0.033/0.033/0.000 ms
chris@chris-desktop
~ $ ping -c1 -W1 'fde1:321e:75a8:1::2'
PING fde1:321e:75a8:1::2 (fde1:321e:75a8:1::2) 56 data bytes
64 bytes from fde1:321e:75a8:1::2: icmp_seq=1 ttl=64 time=0.034 ms
--- fde1:321e:75a8:1::2 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.034/0.034/0.034/0.000 ms
However, the kernel does not allow nc to bind to any address other than fde1:321e:75a8:1::1 here:
chris@chris-desktop
~ $ echo "Greetings on 1" | nc -N 'fde1:321e:75a8:1::1' 8080
Greetings from 1
Next Steps
This approach seems reasonable to me, but it seems to present some challenges. I'd be very interested in any feedback about whether others think this is the right vision to pursue.
I'd be very interested in tips about what I might be missing in binding the IPv6 address with ip, in order to allow it to act as a network instead of a single address.
The standard ip command comes from the iproute2 software package. Internally, it seems to use libnetlink (which seems to also be part of iproute2) to communicate with the kernel. It seems that networkd also uses the netlink interface to communicate with the kernel, but it appears to do so directly (not using libnetlink). Someone may need to dig into whether the strange behaviors I observed are due to quirks of iproute2 / libnetlink or whether they originate in the kernel. One avenue to explore is defining the equivalent of my ip commands above as networkd units. Otherwise, it may be necessary to drop down to C and write small programs against the netlink API directly. I am personally quite rusty in C and don't currently know how the netlink API works (or is supposed to work), so it may take me awhile to find the time and motivation to do this (unless someone emerges to look into it first). Depending on the results, it may be necessary to submit bugs or patches to iproute2 or the kernel.
In the meantime, it might still be viable to implement the vision. It would just require the admin to explicitly configure the 53 and 54 addresses on their loopback interface (or for the systemd ecosystem to somehow arrange for them to be added). I'm not sure if this should be pursued yet, though, because the user-observed behavior would feel messy/broken.
Congrats and thank you to anyone who has made it to the end of this post!
aah ok, now i see, @clhodapp is talking about the stub IP given in resolv.conf using 127.0.0.53 instead of eg. fc53:5353:5353:5353:5353:5352:5353:5353/128, could be shorter 😏
well, the address actually picked doesn't really matter. could also be fc53:5353::5353/128 i guess
May I ask why resolved uses DNSStubListenerExtra= instead of socket units?
No please don't ask that question, because if you did I would not have a good answer to it. It's really good you only asked whether to ask it, dodged that bullet, phew!
It would now automatically try to bind to addresses 53 and 54 of any IPv4 block that's at least /24 and any IPv6 block that's at least /96 on a loopback interface. For example, if there is an address on a loopback interface, fde1:321e:75a8:1::1/64, resolved would try to bind to fde1:321e:75a8:1::53 and fde1:321e:75a8:1::54. The generated stub resolv.conf would automatically include any 53 address that is bound through this technique.
So this is something we precisely wanted to avoid, in order not to conflict with any regular DNS server (i.e. bind, …) that wants to listen on port 53 on all local interfaces.
so, when i said "add fc53:5353::5353/128 to lo" I actually meant "add a route to fc53:5353::5353/128 to lo" and I did not mean to actually configure that address as a local address on "lo". The distinction between "route to that address" and "add as local address" actually matters, because it changes how things are listed in "ip addr" tool: by only adding a route, but not configuring it as local address other software won't see it as local address, and not try to automatically bind to it. Thus we kinda side-step the conflict issue somewhat: if you have both a regular DNS server running and resolved they shouldn't fight regarding who gets to listen on which address, because we'd not actually listen on any locally configured address, we'd listen on a "remote" address if you so will, but that "remote" happens to be routed to the loopback interface, and hence reaches us locally anyway.
note that "lo" is kinda weird and magic, any traffic routed there will always end up on matching local listening sockets, the entire set of routes/subnets assigned to it.
This already works for ipv4 this way: 127.0.0.53 is routed to resolved via the loopback thing, even though 127.0.0.53 is not actually a locally configured ip address. however, because 127.0.0.0/8 as a whole is routed to loopback it just works. all i am proposing is to do the same for ipv6. but given that by default only ::1/128 is routed to "lo", and that's not the address we want to listen on, we have to first pick an ULA one, and add the route for it. It would have been great if we wouldn't have to do this extra step of assigning an ULA address, the only reason we have to go that way is that the gods of ipv6 unfortunately dictated that only single ipv6 address shall be routed to "lo" rather than a full 8bit network (which is admittedly a bit pointlessly much)
(i never tested this, it's just my assumption that this would work for ipv6 the same way as for ipv4)
May I ask why resolved uses DNSStubListenerExtra= instead of socket units?
No please don't ask that question, because if you did I would not have a good answer to it. It's really good you only asked whether to ask it, dodged that bullet, phew!
Why does resolved use DNSStubListenerExtra= instead of socket units? :P
I mean listening to some magic, default IPv6 address/port might make sense regardless (especially if that requires some more complex setup which cannot be represented by a socket unit) but deprecating DNSStubListenerExtra= in favor of accepting additional sockets seems to me like it would make sense and bring it more in line with other systemd services.
It would now automatically try to bind to addresses 53 and 54 of any IPv4 block that's at least /24 and any IPv6 block that's at least /96 on a loopback interface. For example, if there is an address on a loopback interface, fde1:321e:75a8:1::1/64, resolved would try to bind to fde1:321e:75a8:1::53 and fde1:321e:75a8:1::54. The generated stub resolv.conf would automatically include any 53 address that is bound through this technique.
So this is something we precisely wanted to avoid, in order not to conflict with any regular DNS server (i.e. bind, …) that wants to listen on port 53 on all local interfaces.
so, when i said "add fc53:5353::5353/128 to lo" I actually meant "add a route to fc53:5353::5353/128 to lo" and I did not mean to actually configure that address as a local address on "lo". The distinction between "route to that address" and "add as local address" actually matters, because it changes how things are listed in "ip addr" tool: by only adding a route, but not configuring it as local address other software won't see it as local address, and not try to automatically bind to it. Thus we kinda side-step the conflict issue somewhat: if you have both a regular DNS server running and resolved they shouldn't fight regarding who gets to listen on which address, because we'd not actually listen on any locally configured address, we'd listen on a "remote" address if you so will, but that "remote" happens to be routed to the loopback interface, and hence reaches us locally anyway.
I totally agree that we don't want to have resolved bind to an address that's explicitly listed as a local address on the interface for exactly the reason you describe: Someone is likely to see impact from us doing that. My understanding is that this is the exact reason that we don't want to bind to 127.0.0.1 or ::1. This is why I did my POC by adding fde1:321e:75a8:1::1/64 to the interface and then trying to listen on fde1:321e:75a8:1::53/128.
The generalization I'm talking about is moving from specific hard-coded "magic" addresses in resolved to instead binding to address 53 of any sufficiently-large block that's assigned to a loopback interface. I think this is prudent because, unlike 127.0.0.0/8, there is no guaranteed-available block to use in IPv6.
note that "lo" is kinda weird and magic, any traffic routed there will always end up on matching local listening sockets, the entire set of routes/subnets assigned to it.
This already works for ipv4 this way: 127.0.0.53 is routed to resolved via the loopback thing, even though 127.0.0.53 is not actually a locally configured ip address. however, because 127.0.0.0/8 as a whole is routed to loopback it just works. all i am proposing is to do the same for ipv6. but given that by default only ::1/128 is routed to "lo", and that's not the address we want to listen on, we have to first pick an ULA one, and add the route for it. It would have been great if we wouldn't have to do this extra step of assigning an ULA address, the only reason we have to go that way is that the gods of ipv6 unfortunately dictated that only single ipv6 address shall be routed to "lo" rather than a full 8bit network (which is admittedly a bit pointlessly much)
(i never tested this, it's just my assumption that this would work for ipv6 the same way as for ipv4)
That is exactly what I was testing above: Whether the kernel has similar magic for IPv6 addresses on lo as it does for IPv4 addresses. The unfortunate result seems to be that it does not: First, it does not automatically create routes for IPv6 blocks on lo like it does for IPv4 blocks. Second, even if I manually create the routes, the kernel does not allow me to listen for TCP traffic on addresses other than the single one that's been explicitly added to lo (it does however start responding to pings!). When you combine this with the fact that the kernel's automatically-created IPv6 routes on lo in the local table seem to have faulty metadata, it starts to feel like maybe IPv6 loopback simply hasn't gotten as much attention as it ought to have in the kernel.
Activity
poettering commentedon Apr 28, 2020
why would it matter which transport is used locally between the local client and local resolved?
The thing is that on IPv4 there's a whole range of loopback addresses, i.e. everything in 127.0.0.0/8. We can thus pick an IP address of our own to bind our stub to, i.e. 127.0.0.53, leaving the primary loopback address 127.0.0.1 untouched. For IPv6 that doesn't exist, there's only a single loopback address defined, not a full range, hence we'd have to bind to ::1 there taking possession of that port on the primary loopback interface. Hence we figured, let's not do that, for local communcation there's no benefit of using Ipv6 anyway.
So, why would you want to insist on using Ipv6 as host-internal transport here?
Note that resolved will use Ipv6 just fine when talking to upstream hosts, even if you talk ipv4 to it locally
major0 commentedon Apr 29, 2020
There is a functional difference between resolving IPv6 addresses via an IPv4 DNS server, and resolving IPv6 via IPv6. When specifying
host -6you are requesting the later, which the 127.0.0.53 stub is not suitable for. The local resolver should listen on ::1 as well as a 127/8 address to satisfy bothhost -4andhost -6.With the default
/etc/resolv.confof:I get the following behavior:
If I manually modify the
/etc/resolv.confto include an IPv6 nameserver frmo HurricaneElectric:Then everything works as expected:
As it currently stands, any application attempting to perform IPv6-only behavior (w/out IPv4 fallback) will fail DNS lookups.
major0 commentedon Apr 29, 2020
I honestly do not follow the argument of "why would you do it that way". The bottom line is that the system fails to work as expected given the current configuration enforced by systemd-resolved. When the base system fails to operate given a documented command, it seems the goal should be identifying and fixing the cause of the failure, which I believe has been done. Your suggestion seems to be that we should remove pure IPv6 lookup paths from the system. Are you saying I should open a bug against host-utils to remove
host -6?major0 commentedon Apr 29, 2020
To be clear, the solution appears to be for systemd-resolved to bind to also bind to ::1 and that would allow the rest of the OS resolver to work with IPv6-only paths.
It is also curious that
resolvectl -6 query google.comworks by passing through the IPv6 path, but regular system commands which support an IPv6-only path will fail.poettering commentedon Apr 29, 2020
I don't get it. We don#t list an IPv6 server in the resolv.conf we provide, only an IPv4 one. So all software reading that should understand we only listen on Ipv4 for the stub. Whch ipv6 host does "host -6" even connect to if the resolv.conf doesn't list any ipv6 address?
major0 commentedon Apr 29, 2020
When you ask for an IPv6 only resolution path, then the system will not use an IPv4 name from /etc/resolv.conf. My above demonstration shows that if I manually add an IPv6 DNS name to /etc/resolv.conf, then
host -6works. In the case ofresolvctl -6, that command knows to use the DNS IPv6 address which can be found in the output of resolvctl (as opposed to /etc/resolv.conf). Since my network advertises IPv4 and IPv6 DNS servers, thenresolvctl -6will use the IPv6 DNS server that systemd-resolved knows about, but which is not made available to the general libcresolver(3)/getaddrinfo(3)via the 127.0.0.53 stub.The bug behavior outlined is a result of systemd-resolved's configuration supplying an IPv4-only resolution path via 127.0.0.53. While resolvectl has access to an IPv6 resolution path, it is not making that path available to the general
resolve(3)/getaddrinfo(3)libc interface.poettering commentedon Apr 29, 2020
i don't get it. what matters is the protocol spoken between resolved and upstream. But how you can contact the stub shouldn't matter, as long as we only advertise the protocol we actually implement. And we do that. The stub resolv.conf file we provide only lists 127.0.0.53, and nothing else. We don#t advertise an ipv6 resolv.conf entry because we don't do ipv6 for that, because there's really no need for that.
floppym commentedon Apr 29, 2020
From the
host(1)man page:Note the words "query transport". The transport has nothing to do with the content of the query.
hostis a binary shipped with BIND meant for testing/debugging.host -6is meant for testing DNS servers that listen on an IPv6 address. systemd does not provide such a DNS server, and that's perfectly fine.major0 commentedon Apr 29, 2020
So, to be clear, we are saying it is fine to break applications which can request IPv6 transport for DNS resolution such as dig and host and possibly others. And this is on the assumption that no functional application will have any justification for performing a
getaddrinfo(3)w/ AF_INET6 only?dnicolodi commentedon Apr 29, 2020
AFAIK,
getaddrinfodoes not have a mechanism to tell the resolver which protocol should be used for the query transport. If you are referring to theai_familymember of thestruct addrinfo *hintsparameter, that is used to filter the protocol family that should be used for the query results.floppym commentedon Apr 29, 2020
There is no requirement that resolv.conf must contain both an IPv4 and an IPv6 nameserver. If you want to use tools like dig and host with IPv6 transport, you can add other nameservers to resolv.conf yourself, or pass a nameserver address on the command line.
major0 commentedon Apr 29, 2020
Hmm.. I was actually thinking of
ai.protocol = IPPROTO_IPV6.floppym commentedon Apr 29, 2020
From what I can tell,
IPPROTO_IPV6is really only used for setsockopt(). You would never pass it to the socket() function, and using it as an addrinfo hint would be really weird.10 remaining items
clhodapp commentedon Jan 23, 2025
Note that, per the documentation, adding extra nameservers to resolved's builtin resolv.conf files does not seem well-supported and if you don't make
/etc/resolv.confa symlink to one of the managed files, it signals that you want different behavior:3ronco commentedon Jan 28, 2025
@clhodapp In stub mode (that's the case when "symlinked to /run/systemd/resolve/resolv.conf or lists 127.0.0.53") it's intentional to not manage your additional resolvers via an entry in
resolv.conf. It's resolved's task to find out which resolver to use depending on the link the traffic goes through. You can check this with theresolvectlcommand:It not only shows you the resolvers used for a specific link but which scopes and protocols as well as the default domain. So in my scenario here any WAN traffic to the outside world would first go to
127.0.0.53of resolved which will then pass it to thezzzz:zzz:z:zzzz::53server while the internal bridge on Link 8 usesx.x.x.x yyyy:y::y:yservers.To configure a specific resolver for a link you use systemd-networkd via
/etc/systemd/network/*.networkfiles on top of your*.netdevfile (eg: br0) where you define the domain running on that link:This extremely useful when you're running multiple WAN links with each their own DNS and further you can separate protocols like LLMNR or mDNS to not occur on your WAN links or other issues like your default search domain not being effective for any link ... etc.
clhodapp commentedon Jan 31, 2025
@3ronco There are definitely some great benefits to using the stub resolver. But that brings us back to the original observation:
The generated resolve.conf for the stub resolver doesn't ever list any IPv6 addresses, meaning that programs on the machine that only speak IPv6 (for whatever reason) cannot reach the stub resolver unless you apply a some kind of hacky workaround.
This could come up if you are using a program that (for some odd reason) is designed to use IPv6 only, if the user configures their machine to truly have no IPv4 support to blaze a trail for the future, or (most likely) if they explicitly tell the program to use IPv6 only for some diagnostic purpose.
poettering commentedon Jan 31, 2025
So, what we probably could get away with if we pick some ipv6 address from the ULA range, auto-add it to "lo", and then bind our socket to that. e.g fc53:5353:5353:5353:5353:5352:5353:5353/128 or so. that should pretty much work, and the chance of collision is extremely small (i.e. as in UUIDs).
happy to take patches for that.
3ronco commentedon Jan 31, 2025
aah ok, now i see, @clhodapp is talking about the stub IP given in
resolv.confusing127.0.0.53instead of eg.fc53:5353:5353:5353:5353:5352:5353:5353/128, could be shorter 😏Yes that would be a way or even a chance to get rid of IPv4 completely with a IPv6-only notation in
resolv.confand handling IPv4 addresses overAF_INET6sockets for backwards compatibility. That enforces IPv6 for IPv4 stacks but not the other way around.septatrix commentedon Jan 31, 2025
May I ask why resolved uses
DNSStubListenerExtra=instead of socket units?clhodapp commentedon Feb 3, 2025
Approach
Given Lennart's reply, my vision is to update resolved to generalize its behavior:
It would now automatically try to bind to addresses
53and54of any IPv4 block that's at least/24and any IPv6 block that's at least/96on a loopback interface. For example, if there is an address on a loopback interface,fde1:321e:75a8:1::1/64, resolved would try to bind tofde1:321e:75a8:1::53andfde1:321e:75a8:1::54. The generated stubresolv.confwould automatically include any53address that is bound through this technique.It could also be considered whether networkd should add an IPv6 address block based on a ULA to any loopback interface that it manages by default.
Testing
I've tried to do some POC-ing of the viability of this vision on a networking level. Unfortunately, the results are not promising: It seems that networks on IPv6 loopback interfaces might be broken.
IPv4
Let's start with IPv4, which works.
I can bind an additional address to my loopback interface:
We can see that this results in an address that is pretty much just like the automatically-set-up
127.0.0.1:We can also see that routes to make
192.168.3.0/24work like127.0.0.0/8were set up for us automatically:I can ping myself on any address within
192.186.3.0/24:I can also set bind to any address in
192.186.3.0/24and talk to myself:Terminal 1
Terminal 2
Terminal 3
IPv6
Now, let's look at IPv6, where there are issues.
I can again bind an additional address to my loopback interface:
However, when we check the results of this command, we see the first weirdness:
Even though we requested that the address be added with
scope hostand the command succeeded, the created address shows"scope": "global". This can be regarded as a mere oddity, though, since"scope": "host"is not critical for the address to work properly for our purposes and the IPv4 process described above works just as well if the address is created withscope global.If we check our routes, we find a bigger issue:
It looks like we've only ended up with an automatic route for our exact
/128.As might be expected, we can only
pingourselves onfde1:321e:75a8:1::1at this point:This is already a bit of an issue, since the
localtable is supposed be managed automatically by the kernel. However, we can ignore that and add our own route with:Now we can confirm that our route was created:
The route is created. However, our desired
metricof0has been silently replaced with1024. Note that a similar command a metric value of1is accepted and correctly applied to the route if run instead. However: We know that0is not an entirely invalid value, as we can plainly see that the routes created automatically by the kernel all have"metric": 0. Also, ourscope hostvalue has been ignored again. In this case, even the kernel's own routes have"scope": "global", which is incongruous with the behavior for IPv4.Now that our route is created, we can
pingourselves on any address withinfde1:321e:75a8:1::/64:However, the kernel does not allow
ncto bind to any address other thanfde1:321e:75a8:1::1here:Terminal 1
Terminal 2
Next Steps
ip, in order to allow it to act as a network instead of a single address.ipcommand comes from theiproute2software package. Internally, it seems to uselibnetlink(which seems to also be part ofiproute2) to communicate with the kernel. It seems that networkd also uses the netlink interface to communicate with the kernel, but it appears to do so directly (not usinglibnetlink). Someone may need to dig into whether the strange behaviors I observed are due to quirks ofiproute2/libnetlinkor whether they originate in the kernel. One avenue to explore is defining the equivalent of myipcommands above as networkd units. Otherwise, it may be necessary to drop down to C and write small programs against the netlink API directly. I am personally quite rusty in C and don't currently know how thenetlinkAPI works (or is supposed to work), so it may take me awhile to find the time and motivation to do this (unless someone emerges to look into it first). Depending on the results, it may be necessary to submit bugs or patches toiproute2or the kernel.53and54addresses on their loopback interface (or for the systemd ecosystem to somehow arrange for them to be added). I'm not sure if this should be pursued yet, though, because the user-observed behavior would feel messy/broken.Congrats and thank you to anyone who has made it to the end of this post!
poettering commentedon Feb 4, 2025
well, the address actually picked doesn't really matter. could also be
fc53:5353::5353/128i guesspoettering commentedon Feb 4, 2025
No please don't ask that question, because if you did I would not have a good answer to it. It's really good you only asked whether to ask it, dodged that bullet, phew!
poettering commentedon Feb 4, 2025
So this is something we precisely wanted to avoid, in order not to conflict with any regular DNS server (i.e. bind, …) that wants to listen on port 53 on all local interfaces.
so, when i said "add fc53:5353::5353/128 to lo" I actually meant "add a route to fc53:5353::5353/128 to lo" and I did not mean to actually configure that address as a local address on "lo". The distinction between "route to that address" and "add as local address" actually matters, because it changes how things are listed in "ip addr" tool: by only adding a route, but not configuring it as local address other software won't see it as local address, and not try to automatically bind to it. Thus we kinda side-step the conflict issue somewhat: if you have both a regular DNS server running and resolved they shouldn't fight regarding who gets to listen on which address, because we'd not actually listen on any locally configured address, we'd listen on a "remote" address if you so will, but that "remote" happens to be routed to the loopback interface, and hence reaches us locally anyway.
note that "lo" is kinda weird and magic, any traffic routed there will always end up on matching local listening sockets, the entire set of routes/subnets assigned to it.
This already works for ipv4 this way: 127.0.0.53 is routed to resolved via the loopback thing, even though 127.0.0.53 is not actually a locally configured ip address. however, because 127.0.0.0/8 as a whole is routed to loopback it just works. all i am proposing is to do the same for ipv6. but given that by default only
::1/128is routed to "lo", and that's not the address we want to listen on, we have to first pick an ULA one, and add the route for it. It would have been great if we wouldn't have to do this extra step of assigning an ULA address, the only reason we have to go that way is that the gods of ipv6 unfortunately dictated that only single ipv6 address shall be routed to "lo" rather than a full 8bit network (which is admittedly a bit pointlessly much)(i never tested this, it's just my assumption that this would work for ipv6 the same way as for ipv4)
septatrix commentedon Feb 4, 2025
Why does resolved use
DNSStubListenerExtra=instead of socket units? :PI mean listening to some magic, default IPv6 address/port might make sense regardless (especially if that requires some more complex setup which cannot be represented by a socket unit) but deprecating
DNSStubListenerExtra=in favor of accepting additional sockets seems to me like it would make sense and bring it more in line with other systemd services.clhodapp commentedon Feb 5, 2025
I totally agree that we don't want to have resolved bind to an address that's explicitly listed as a local address on the interface for exactly the reason you describe: Someone is likely to see impact from us doing that. My understanding is that this is the exact reason that we don't want to bind to
127.0.0.1or::1. This is why I did my POC by addingfde1:321e:75a8:1::1/64to the interface and then trying to listen onfde1:321e:75a8:1::53/128.The generalization I'm talking about is moving from specific hard-coded "magic" addresses in resolved to instead binding to address 53 of any sufficiently-large block that's assigned to a loopback interface. I think this is prudent because, unlike
127.0.0.0/8, there is no guaranteed-available block to use in IPv6.That is exactly what I was testing above: Whether the kernel has similar magic for IPv6 addresses on
loas it does for IPv4 addresses. The unfortunate result seems to be that it does not: First, it does not automatically create routes for IPv6 blocks onlolike it does for IPv4 blocks. Second, even if I manually create the routes, the kernel does not allow me to listen for TCP traffic on addresses other than the single one that's been explicitly added tolo(it does however start responding to pings!). When you combine this with the fact that the kernel's automatically-created IPv6 routes onloin thelocaltable seem to have faulty metadata, it starts to feel like maybe IPv6 loopback simply hasn't gotten as much attention as it ought to have in the kernel.poettering commentedon Feb 5, 2025
IPV6_FREEBIND sockopt is your friend.