EDIT: This question was closed as a duplicate of this question: WSL2: can ping by FQDN but not by host. However, that question does NOT answer my question, which is why name resolution works for 2 out of 3 hosts. This is not a general issue with all name resolution needing the search suffix.
I'm running Windows 11 Pro, and have WSL 2 installed and configured with the default Ubuntu installation.
My network is configured such that there is a default search domain/DNS suffix provided by DHCP. Let's call it "mydomain.dev".
In the Windows world, and with other clients, I can reach three other hosts on the network via bare hostname, without explicitly specifying the DNS suffix. For example:
C:\Users\Isaac>ping host1
Pinging host1.mydomain.dev [192.168.1.254] with 32 bytes of data:
Reply from 192.168.1.254: bytes=32 time=1ms TTL=64
C:\Users\Isaac>ping host2
Pinging host2.mydomain.dev [192.168.1.251] with 32 bytes of data:
Reply from 192.168.1.251: bytes=32 time<1ms TTL=64
This works for all three hosts on the network.
However, in the WSL environment, I can only reach 2 out of the 3 hosts in this manner. For the third host, I have to explicitly specify the domain name, or the name resolution fails:
isaac@ubuntu:~$ ping host1
ping: host1: Name or service not known
isaac@ubuntu:~$ ping host1.mydomain.dev
PING host1.mydomain.dev (192.168.1.254) 56(84) bytes of data.
64 bytes from 192.168.1.254 (192.168.1.254): icmp_seq=1 ttl=63 time=1.08 ms
isaac@ubuntu:~$ ping host2
PING host2 (192.168.1.251) 56(84) bytes of data.
64 bytes from 192.168.1.251 (192.168.1.251): icmp_seq=1 ttl=63 time=2.27 ms
I haven't made any changes to networking configuration in the WSL virtual machine. The resolv.conf
file specifies the Hyper-V interface, which (I believe) should end up passing DNS queries through to the host Windows resolver:
isaac@ubuntu:~$ cat /etc/resolv.conf
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 172.22.96.1
Why is this single host not reachable by hostname-without-suffix from within the WSL machine, even though other similar hosts are?
Another interesting note: The DNS on my network is handled by a PiHole, where I've added manual DNS entries for all the machines on my network (host1.mydomain.dev, host2.mydomain.dev, etc.). I tried adding another DNS entry for host1 WITHOUT the DNS suffix, resulting in two DNS entries for this host:
host1 192.168.1.254
host1.mydomain.dev 192.168.1.254
After doing this, I'm able to resolve host1 from the WSL machine via bare hostname, without the suffix. But if I remove that duplicate/extra DNS entry, it stops resolving again. The DNS server has single entries for the other hosts that are working. These entries include the search suffix.
search mydomain.dev
to/etc/resolv.conf
just to make sure that's the issue. It seems like there are a couple ways WSL can fail to import search domains/dns suffixes from the host: learn.microsoft.com/en-us/windows/wsl/…host1
to resolve, so I guess I could work around that way. But it's really bugging me that I can't explain why resolution works for host2 and host3, but NOT host1. (FWIW, bothhost1
andhost2
are Ubuntu machines running 22.04.host3
is FreeBSD).wslconfig
file and settingdnsTunneling=true
seems to fix the issue. The/etc/resolv.conf
file in the WSL VM has a different DNS address (nownameserver 127.0.0.42
instead ofnameserver 172.22.96.1
, and it includes thesearch mydomain.dev
flag. Name resolution to all 3 hosts seems to work as expected. Would still love to be able to explain why only one host was failing without thednsTunneling
setting!