Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WSL2: resolver ignores LOCALDOMAIN env variable #7328

Closed
1 of 2 tasks
joslinpr opened this issue Aug 19, 2021 · 4 comments
Closed
1 of 2 tasks

WSL2: resolver ignores LOCALDOMAIN env variable #7328

joslinpr opened this issue Aug 19, 2021 · 4 comments

Comments

@joslinpr
Copy link
Contributor

Windows Build Number

Microsoft Windows [Version 10.0.18363.1621]

WSL Version

  • WSL 2
  • WSL 1

Kernel Version

Linux version 5.10.43.3-microsoft-standard-WSL2 (oe-user@oe-host) (x86_64-msft-linux-gcc (GCC) 9.3.0, GNU ld (GNU Binutils) 2.34.0.20200220) #1 SMP Wed Jun 16 23:47:55 UTC 2021

Distro Version

CentOS Linux release 7.9.2009 (Core)

Other Software

Not applicable.

Repro Steps

# 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 <Windows IP>

# nslookup SERVER
Server:     <Windows IP>
Address:    <Windows IP>

# export LOCALDOMAIN="domainA.example.com domainB.example.com domainC.example.com"
# nslookup SERVER
Server:     <Windows IP>
Address:    <Windows IP>
** server can't find SERVER: NXDOMAIN

# sudo bash -c "cat /etc/resolv.tmpl >> /etc/resolv.conf"
# 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 <Windows IP>
search example.com domainA.example.com domainB.example.com domainC.example.com

# nslookup SERVER
Server:     <Windows IP>
Address:    <Windows IP>

Non-authoritative answer:
SERVER.domainA.example.com  canonical name = SERVER.domainB.example.com.
Name:   SERVER.domainB.example.com
Address: <redacted> #  <--- correct address returned.

Expected Behavior

resolver seems to be ignoring environment variables.

On RHEL 7.9, setting LOCALDOMAIN overrides any search directive in /etc/resolv.conf. This is documented in the man pages (man resolv.conf):

The search keyword of a system's resolv.conf file can be overridden on a per-process basis by setting the environment variable LOCALDOMAIN to a space-separated list of search domains.

# cat /etc/resolv.conf
search          domainA.example.com example.com
nameserver      <redacted>
nameserver      <redacted>

# LOCALDOMAIN="domainB.example.com example.com" nslookup SERVER
Server:         <redacted>
Address:        <redacted>

Non-authoritative answer:
SERVER.domainA.example.com   canonical name = SERVER.domainB.example.com.
Name:   SERVER.domainB.example.com
Address: <redacted>
  • In my organization, "hostname" is set to shortname, not a fully qualified domain name.
  • It appears /etc/resolv.conf is recreated each time a wsl session starts? A file with a "search" directive is overwritten. The address added to resolv.conf is the correct IP for my Windows laptop.
  • I cannot use generateResolvConf = false because my IP address changes.

Actual Behavior

resolver fails unless there is a domain or search directive containing the proper domain. Adding a LOCALDOMAIN environment variable does not fix the problem.

Diagnostic Logs

I have created a GIST with the output of
strace nslookup host.example.com
and
LOCALDOMAIN="domainB.example.com" strace nslookup host.example.com.

To my casual inspection they look identical.

@benhillis
Copy link
Member

For WSL2 the DNS resolver runs on the host, so the Linux environment variables will not be respected.

@joslinpr
Copy link
Contributor Author

Thanks for responding. So this will remain "working as intended"?

Guess I'll hack up a file watcher or cron job to camp on /etc/resolv.conf.

@mat-m
Copy link

mat-m commented Sep 14, 2021

Thanks for responding. So this will remain "working as intended"?

Guess I'll hack up a file watcher or cron job to camp on /etc/resolv.conf.

You can chattr +i as suggested in #5420

Copy link
Contributor

This issue has been automatically closed since it has not had any activity for the past year. If you're still experiencing this issue please re-file this as a new issue or feature request.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants