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

ddev hostname should edit both WSL2 and Windows hosts file when used #3818

Closed
1 task done
nico-loeber opened this issue May 8, 2022 · 9 comments
Closed
1 task done
Milestone

Comments

@nico-loeber
Copy link
Collaborator

Is there an existing issue for this?

  • I have searched the existing issues

Run a Diagnostic and Paste Link Here

No response

Current Behavior

When using DDEV inside WSL and starting a new ddev project the first time ddev adds entries in the /etc/hosts file of the system to ensure the project.ddev.site domain can be resolved locally.
This does not work well on WSL as ddev is currently editing the hosts file inside WSL which is not exposed to the windows host, so accessing the website via a browser on the host system is not possible.
Additionally the WSL hosts file will be regenerated on every WSL start to pepresent the state of the windows one.

DDEV warns you about this fact by outputting:

You are on WSL2, so should also manually execute 'sudo ddev hostname some-project.ddev.site 127.0.0.1' on Windows if you use a Windows browser.

This suggestion will only work if ddev is also installed on the windows host.
So you have to install ddev on Windows and inside WSL to be able to ensure the basic functionallity is working, wihtout the need to manually editing files.

Expected Behavior

I would expect ddev to work within WSL just as it does installed on a native operating system.
I don't expect to have to manually edit any files with an editor.
I don't expect to have to install and keep ddev up to date in Windows and WSL.

Steps To Reproduce

  1. Setup DDEV inside WSL according the documentation https://ddev.readthedocs.io/en/stable/
    • Skip "Windows (traditional/legacy)"
  2. Run ddev config and ddev start in a new project inside WSL
  3. Try to access the website through a browser installed on the host system

Anything else?

This issue can be avoided by using the Windows binary inside WSL as proposed by the concept DDEV Interop Based WSL Integration, but @rfay had valid reasons for not implementing this concept as default.

This issue does affect the following issue of the DDEV Integration Plugin: php-perfect/ddev-intellij-plugin#32

@rfay
Copy link
Member

rfay commented May 8, 2022

That warning only happens when either there's no internet or a non-ddev.site URL is in place. ddev hostname is not used otherwise. The normal situation is a lookup of *.ddev.site using DNS, which resolves fine to 127.0.0.1 both inside WSL2 and on Windows.

@nico-loeber
Copy link
Collaborator Author

Thanks for your fast response!

From my windows host resolving some-project.ddev.site is not possible while google.com is, so internet should be available.

Microsoft Windows [Version 10.0.22000.652]
(c) Microsoft Corporation. Alle Rechte vorbehalten.

C:\Users\nl>ping some-project.ddev.site
Ping-Anforderung konnte Host "some-project.ddev.site" nicht finden. Überprüfen Sie den Namen, und versuchen Sie es erneut.

C:\Users\nl>ping google.com

Ping wird ausgeführt für google.com [2a00:1450:4001:827::200e] mit 32 Bytes Daten:
Antwort von 2a00:1450:4001:827::200e: Zeit=6ms
Antwort von 2a00:1450:4001:827::200e: Zeit=4ms

In my WSL both the ddev domain, as well as google is reachable

nl@XPS-9510-NL:~/projects/some-project$ ping some-project.ddev.site -c 1
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.023 ms

--- localhost ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.023/0.023/0.023/0.000 ms
nl@XPS-9510-NL:~/projects/some-project$ ping google.com -c 1
PING google.com (142.250.184.206) 56(84) bytes of data.
64 bytes from fra24s11-in-f14.1e100.net (142.250.184.206): icmp_seq=1 ttl=117 time=5.68 ms

--- google.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 5.682/5.682/5.682/0.000 ms

Do I understand you right, that the ddev hostname notices shouldn't appear at all?
Can I provide you any additional debug information?
I'm also available in discord.

Thanks for your help!

@rfay
Copy link
Member

rfay commented May 8, 2022

You can ping dkdkskdj.ddev.site on the Windows side and you should see it hit 127.0.0.1. This is just a function of DNS and the DNS wildcard for *.ddev.site.

There is a problem with certain routers though where DNS rebinding is prohibited, this could be your situation, as described in https://ddev.readthedocs.io/en/latest/users/troubleshooting/#dns-rebinding-prohibited - but I'd think that would affect WSL2 and Windows equally.

Again, lookup of *.ddev.site is not (normally) a feature of ddev, it's a feature of DNS configuration. If your Windows system can't resolve it, you'll find others that can, and we can chase the problem on your specific system.

@nico-loeber
Copy link
Collaborator Author

Yes, adding ddev.site to the whitelist solved this issue for me. But this issue might be more more important than you might think. Everyone of my colleagues helping me test the plugin had the same issue. AVM (FritzBox) has quite a large market share, at least in germany. Also this might be a problem in enterprise environments, as admins will not be happy to open their firewalls for rebinding attacks.

As this issue was about the host entry, it has lower priority to me now. But the actual problem of setting the host entries from WSL still exists.

Your decission if you like to keep this issue open or close it as my actual problem with that is solved.

@rfay rfay changed the title DDEV hostname not working in WSL ddev hostname should edit both WSL2 and Windows hosts file when used May 8, 2022
@rfay
Copy link
Member

rfay commented May 8, 2022

I have always wanted ddev hostname to update both hosts files ever since the beginning, to work around this class of problems, kept hoping for a contribution that would solve it. sudo.exe ddev.exe hostname on the Windows side could be executed by ddev hostname. The message emitted by ddev hostname currently was a workaround.

@rfay rfay added this to the v1.20 milestone May 16, 2022
@morvy
Copy link

morvy commented Jun 26, 2022

maybe this could be useful?

https://github.com/shayne/go-wsl2-host

@rfay
Copy link
Member

rfay commented Jun 26, 2022

Thanks so much @morvy, please continue to keep your eyes open! - It seems go-wsl2-host only adds an IP address on the Windows side to access the WSL2 environment directly. The goal here is for ddev to be able to add a *.ddev.site or other additional_hosts or additional_fqdns entry that gets added in wsl2 into the Windows hosts files.

@mhsdesign
Copy link

There is a problem with certain routers though where DNS rebinding is prohibited, this could be your situation, as described in https://ddev.readthedocs.io/en/latest/users/troubleshooting/#dns-rebinding-prohibited - but I'd think that would affect WSL2 and Windows equally.

Thanks i think that was it! Link changed to: https://ddev.readthedocs.io/en/stable/users/troubleshooting/#dns-rebinding-prohibited

and here the tutorial for Fritzbox: #2409 (comment)

@rfay
Copy link
Member

rfay commented Nov 11, 2022

@nico-loeber @morvy @mhsdesign and anybody else, would love it if you could test #4377 - the binary should be in the PR in just a few minutes. You will need both the Windows and linux binaries/installers.

@rfay rfay closed this as completed in 97ada0d Nov 23, 2022
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

4 participants