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

/etc/hosts not getting generated with the contents of the windows hosts file #11719

Closed
1 of 2 tasks
lucastheisen opened this issue Jun 20, 2024 · 7 comments
Closed
1 of 2 tasks
Labels
emailed-logs Logs have been emailed

Comments

@lucastheisen
Copy link

lucastheisen commented Jun 20, 2024

Windows Version

Microsoft Windows [Version 10.0.22621.3737]

WSL Version

2.2.4.0

Are you using WSL 1 or WSL 2?

  • WSL 2
  • WSL 1

Kernel Version

5.15.153.1-microsoft-standard-WSL2

Distro Version

Rocky Linux 9.0 (Blue Onyx)

Other Software

No response

Repro Steps

Add an entry to windows hosts file:

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
#       127.0.0.1       localhost
#       ::1             localhost

127.127.127.127 test.local

ensure generateHosts=true

[boot]
systemd=true
[network]
generateHosts = true
generateResolvConf = false
[user]
default = ltheisen

remove /etc/host and restart:

(wsl-rocky9) ltheisen@PC ~
$ sudo rm /etc/hosts

(wsl-rocky9) ltheisen@PC ~
$ cat /etc/hosts
cat: /etc/hosts: No such file or directory

(wsl-rocky9) ltheisen@PC ~
$ wsl.exe --shutdown

[process exited with code 1 (0x00000001)]

Open a new terminal and view /etc/hosts:

(wsl-rocky9) ltheisen@PC ~
$ cat /etc/hosts
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateHosts = false
127.0.0.1       localhost
127.0.1.1       PC.LUCASTHEISEN.COM   PC

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Expected Behavior

My windows entries should be in the generated hosts file, for example:

# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateHosts = false
127.0.0.1       localhost
127.0.1.1       PC.LUCASTHEISEN.COM   PC

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

# From C:\Windows\System32\drivers\etc\hosts
127.127.127.127 test.local

Actual Behavior

just these:

# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateHosts = false
127.0.0.1       localhost
127.0.1.1       PC.LUCASTHEISEN.COM   PC

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Diagnostic Logs

No response

Copy link

Logs are required for review from WSL team

If this a feature request, please reply with '/feature'. If this is a question, reply with '/question'.
Otherwise please attach logs by following the instructions below, your issue will not be reviewed unless they are added. These logs will help us understand what is going on in your machine.

How to collect WSL logs

Download and execute collect-wsl-logs.ps1 in an administrative powershell prompt:

Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/collect-wsl-logs.ps1" -OutFile collect-wsl-logs.ps1
Set-ExecutionPolicy Bypass -Scope Process -Force
.\collect-wsl-logs.ps1

The scipt will output the path of the log file once done.

Once completed please upload the output files to this Github issue.

Click here for more info on logging
If you choose to email these logs instead of attaching to the bug, please send them to [email protected] with the number of the github issue in the subject, and in the message a link to your comment in the github issue and reply with '/emailed-logs'.

View similar issues

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it!

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@lucastheisen
Copy link
Author

/emailed-logs

Copy link

Diagnostic information
Found '/emailed-logs', adding tag 'emailed-logs'

@github-actions github-actions bot added the emailed-logs Logs have been emailed label Jun 20, 2024
@CatalinFetoiu
Copy link
Collaborator

hello @lucastheisen . thanks for reporting this.

I see you are using the 2.2.4 build, which has dnsTunneling enabled by default. When dnsTunneling is enabled, the Windows hosts file is not copied to the Linux hosts file, because Linux DNS queries are proxied to Windows and Windows DNS settings, including Windows hosts file are already applied to those queries.

To confirm, you can try running dig test.local in Linux and we would expect it to return 127.127.127.127

@lucastheisen
Copy link
Author

lucastheisen commented Jun 21, 2024

@CatalinFetoiu , when i run dig test.local i dont get back my 127.127.127.127 as i expect:

(wsl-rocky9) ltheisen@PC ~
$ dig test.local

; <<>> DiG 9.16.23-RH <<>> test.local
;; global options: +cmd
;; Got answer:
;; WARNING: .local is reserved for Multicast DNS
;; You are currently testing what happens when an mDNS query is leaked to DNS
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 55406
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1220
; COOKIE: a3aabcb13eac55f5e00b0b68667580ddf31c7bf9f3019eb8 (good)
;; QUESTION SECTION:
;test.local.                    IN      A

;; AUTHORITY SECTION:
.                       10800   IN      SOA     a.root-servers.net. nstld.verisign-grs.com. 2024062100 1800 900 604800 86400

;; Query time: 90 msec
;; SERVER: 10.20.100.53#53(10.20.100.53)
;; WHEN: Fri Jun 21 09:32:13 EDT 2024
;; MSG SIZE  rcvd: 142

And just for clarity:

(wsl-rocky9) ltheisen@PC ~
$ cat /mnt/c/Windows/System32/drivers/etc/hosts
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
#       127.0.0.1       localhost
#       ::1             localhost

127.127.127.127 test.local

... using the 2.2.4 build, which has dnsTunneling enabled by default

The documentation says it is false by default, and i do not have it explicitly set in my configuration. Is there a way to see what the runtime value of all the configuration options is given that the documentation clearly does not agree with your assertion that it is true by default? Also, this just recently stopped working (we just noticed yesterday, and the last i can guarantee it was working was about a month ago), is this change that recent?

Also, is there some documentation on this dnsTunneling that could explain how it interoperates with entries in C:\Windows\System32\drivers\etc\hosts? Regular DNS does not do resolution of /etc/hosts entries, you need your nsswitch.conf to include files to get it to look at hosts.

I am struggling to understand what the expected behavior is here and how i can have my own hosts file, or similar feature, that will resolve my local aliases....

@lucastheisen
Copy link
Author

@CatalinFetoiu , i think i found the problem. We were also doing:

[network]
generateResolvConf = false

And my guess is that you need to generate a nameserver entry to point to the dns tunnel. And after switching that to true, and a handy wsl.exe --shutdown i now get the response you indicated i should expect:

(wsl-rocky9) ltheisen@PC ~
$ 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 10.255.255.254
search LUCASTHEISEN.COM lucastheisen.home

(wsl-rocky9) ltheisen@PC ~
$ dig test.local

; <<>> DiG 9.16.23-RH <<>> test.local
;; global options: +cmd
;; Got answer:
;; WARNING: .local is reserved for Multicast DNS
;; You are currently testing what happens when an mDNS query is leaked to DNS
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 33790
;; flags: qr aa rd ad; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; WARNING: recursion requested but not available

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;test.local.                    IN      A

;; ANSWER SECTION:
test.local.             254050  IN      A       127.127.127.127

;; Query time: 0 msec
;; SERVER: 10.255.255.254#53(10.255.255.254)
;; WHEN: Fri Jun 21 10:39:31 EDT 2024
;; MSG SIZE  rcvd: 65

Can you confirm that these settings are indeed intertwined? Is there a place i could submit an MR to the documentation that would indicate this relationship for future reference?

Also, feel free to close this issue if my assertions here are correct...

@CatalinFetoiu
Copy link
Collaborator

CatalinFetoiu commented Jun 21, 2024

@lucastheisen, glad to hear the scenario works now

thanks for pointing out that dns tunneling stills shows as disabled by default in the docs - will get that fixed. 2.2.4 is the first release build where we have this enabled by default

I also plan to add documentation notes to mention the Windows hosts file is not copied in Linux and that generateResolvConf needs to be true when DNS tunneling is enabled

thanks for your feedback!

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

No branches or pull requests

2 participants