I was trying to add a SMB storage to use as a backup destination. That did not work, and the error message was that HA could not resolve the name. This was when I used nas5.example.com as the FQDN for the server. It did work when I used the name nas5.local.
After some serious head-banging, the problem turns out to be result of my lazyness and systemd-resolved behavior and IPv6. I have my own DNS servers, and there I had defined the server names using the shortest name for them, so I had an A record for the name “nas5”, and a CNAME record of “nas5” for the name “nas5.example.com”:
nas5: A 10.10.10.5
nas5.example.com: CNAME "nas5"
This works fine in most cases: client asks for the name “nas5.example.com” and gets back both the CNAME and the actual IPv4 address of “nas5”. However, with HAOS, on the host os, the systemd-resolved was not happy:
# resolvectl query nas5.example.com
nas5.example.com: resolve call failed: No appropriate name servers or networks for name found
nslookup works fine, of course:
# nslookup nas5.example.com
Server: 192.168.1.13
Address: 192.168.1.13:53
nas5.example.com canonical name = nas5
Name: nas5
Address: 10.10.10.10
nas5.example.com canonical name = nas5
So, why would systemd-resolved fail? It seems the reason is that my network (and HA) has IPv6 enabled, so systemd-resolved decides to query both A and AAAA records. The DNS knows the A records for nas5, but not the AAAA records. Thus the A records work fine, and the DNS response includes both the CNAME and IPv4 address. However, for the AAAA query the DNS server only returns the CNAME, as there really is nothing else it could return. And at this stage (I believe) systemd-resolved looks at the CNAME it got, and decides that it is a single-label name and calls it quits and decides to throw away even the IPv4 result it got. Why not return just the IPv4 A, I do not know or understand.
The situation is a bit different if I use multi-label CNAMEs: If I haver the following in DNS:
test4.example.com: A 10.0.0.4
test2.example.com: CNAME test4.example.com
Query for the test4 works as expected:
# resolvectl query test4.example.com
test4.example.com: 10.0.0.4 -- link: end0
-- Information acquired via protocol DNS in 1.6ms.
-- Data is authenticated: no; Data was acquired via local or encrypted transport: no
-- Data from: network
#
However, test2 fails, somewhat unexpectedly:
# resolvectl query test2.example.com
test2.example.com: Name 'test4.example.com' not found
#
Note that the error is different this time: “not found” instead of “No appropriate name servers”. And notice that it explained that the CNAME was not found. But the end result is the same, even the successful IPv4 A resolution gets thrown away. Again, I have no clue as to why throw away a successful resolution.
Also, the result that the CNAME of test4 was a failure gets stored somewhere in the cache, which is a bummer as well, as it poisons further queries that succeeded earlier:
# resolvectl query test4.example.com
test4.example.com: 10.0.0.4 -- link: end0
-- Information acquired via protocol DNS in 1.7ms.
-- Data is authenticated: no; Data was acquired via local or encrypted transport: no
-- Data from: network
# resolvectl query test2.example.com
test2.example.com: Name 'test4.example.com' not found
# resolvectl query test4.example.com
test4.example.com: Name 'test4.example.com' not found
# resolvectl flush-caches
# resolvectl query test4.example.com
test4.example.com: 10.0.0.4 -- link: end0
-- Information acquired via protocol DNS in 1.4ms.
-- Data is authenticated: no; Data was acquired via local or encrypted transport: no
-- Data from: network
I can think of a few ways to fix this:
- make systemd-resolved return the successful A record, even if the AAAA query fails with the CNAME.
- Disable IPv6 on HAOS
- Add IPv6 AAAA records for all the hosts
- Change the order of what is a CNAME vs what is an alias
Option 1 sounds like it could take some time.
Option 2 is not for me, but might work for others.
Option 3 works if everything is IPv6 -capable. I verified that it works, but not a solution for me.
Option 4 is the solution I chose. This means that I have now:
nas5.example.com: A 10.10.10.10
nas5: CNAME nas5.example.com
And this works without systemd-resolved throwing away the IPv4 A, even though it gets a NXDOMAIN for the AAAA query:
# resolvectl query nas5.example.com
nas5.example.com: 10.10.10.10 -- link: end0
-- Information acquired via protocol DNS in 116.5ms.
-- Data is authenticated: no; Data was acquired via local or encrypted transport: no
-- Data from: network
If anyone knows how to fix or explain this systemd-resolved behaviour, I would be interested.
