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

Upgrading from WSL1 to WSL2 breaks custom hostnames #5780

Closed
sylfabre opened this issue Aug 18, 2020 · 8 comments
Closed

Upgrading from WSL1 to WSL2 breaks custom hostnames #5780

sylfabre opened this issue Aug 18, 2020 · 8 comments

Comments

@sylfabre
Copy link

Environment

Windows build number: Microsoft Windows [Version 10.0.19041.450]
Your Distribution version: Ubuntu 20.04
Whether the issue is on WSL 2 and/or WSL 1: WSL 2

Steps to reproduce

  1. Install Ubuntu 20.04 with WSL 1

  2. Install Apache2 in WSL

sudo apt-get install apache2
  1. Create an hello world file in Windows
#/mnt/c/www/index.html
Hello world!
  1. Configure a virtual host
# /etc/apache2/sites-enabled/custom.conf

Listen 0.0.0.0:80

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot /mnt/c/www

    <Directory "/mnt/c/www">
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>
  1. Reload Apache2
sudo service apache2 restart
  1. Install (Acrylic DNS)[https://mayakron.altervista.org/support/acrylic/Home.htm] to define wildcard subdomain as local hosts.
# Acrylic hosts file
127.0.0.1 *.test.tld
  1. Configure Acrylic to bind port 55 instead of 53 to free the 53 for WSL2 (as reported here WSL2 fails to start following 18965 update #4432 (comment))
# Acrylic conf file
LocalIPv4BindingPort=55
LocalIPv6BindingPort=55
  1. Restart Acrylic

  2. Install Yoga DNS

  3. Define Acrylic as a DNS server for Yoga DNS
    image

  4. Define a Yoga DNS rules to route DNS queries to Acrylic for *.test.tld
    image

  5. Check browsing to http://local.test.tld works in Chrome

  6. Upgrade your WSL to version 2 in PowerShell as admin

wsl --set-version Ubuntu-20.04 2
  1. Restart Apache in WSL 2
sudo service apache2 start

Expected behavior

Chrome still displays a page at http://local.test.tld

Actual behavior

Chrome displays an error page at http://local.test.tld "ERR_CONNECTION_REFUSED"

Additionnal information

# c:\windows\system32\drivers\etc\hosts
127.0.0.1 local.test.tld
::1 localhost local.test.tld
  • Accessing http://localhost/ works in Chrome in WSL2

  • Using the WSL 2 with the IP found with ip addr | grep eth0 does not work neither with:

  • A ping from Windows
  • In the Windows hosts file
  • In Acrylic hosts file
@stevebovy
Copy link

WSL2 Wish-List Feature Fix ??

PROBLEM DESCRIPTION: "DOUBLE TROUBLE"

NON UNIQUE WSL2 HOST NAME CREATES UNNECESSARY "NAME RESOLUTION" CONFUSION WHICH CAN CURRENTLY ONLY BE WORKED

AROUND BY USING FULLY-QUALIFIED HOST NAME

Example of problem (Accessing Windows Host X-Serv)

The following will not work: DISPLAY=HOSTNAME:0

THE WORK AROUND IS DISPLAY=HOSTNAME.WINHOST-DOMAIN:0

Additional wsl.conf Network Keywords ??

Allow custom configuration of HOSTNAME file so that WSL2 VM machine network name is unique and different from windows

host machine name ( I would prefer the default to be the linux distribution name ) this would of course impact the HOST file as well

@Biswa96
Copy link

Biswa96 commented Aug 26, 2020

I am not sure if this feature is documented or available in stable Windows OS versions. For my case, I have tried this in latest Windows Insider build and it works. Create a /etc/wsl.conf file in your preffered WSL-ed GNU/Linux distribution. Add the following two lines in that /etc/wsl.conf file.

[network]
hostname = HelloWorld

Change the host name as you want.

@therealkenc
Copy link
Collaborator

[network]
hostname = HelloWorld
Change the host name as you want.

That doesn't expose the hostname to Windows. Whether that is by-design or WIP I can't say.

@Biswa96
Copy link

Biswa96 commented Sep 9, 2020

In /etc/hosts file, 127.0.1.1 is assigned to the host name. It can be used somehow.

@therealkenc
Copy link
Collaborator

The somehow is you can gethostbyname(3) in WSL. Fornow.

@therealkenc
Copy link
Collaborator

Chrome displays an error page at http://local.test.tld "ERR_CONNECTION_REFUSED"

Whatever circuitous path Yoga and Acrylic are taking, the result is an ipv4 address is being given to Chrome. There's no ipv4 listener on the WSL2 side.

image

/dupe #4851 #5298

Similar #5844 (message), your options are: (a) get Chrome to point at ipv6 ::1 via your DNS scheme, or, (b) get apache2 to listen on ipv4.

Spiritually related #4592 (message), whether bouncing DNS queries off of two third-party Windows networking services is a good idea can be left to the beholder. For an alternate approach to accomplishing a similar end result, folks may want to consider avahi-daemon(8).

@ghost
Copy link

ghost commented Sep 9, 2020

Hi! We've identified this issue as a duplicate of another one that already exists in this repository. This specific instance is being closed in favor of tracking the concern over on the referenced thread.

Thanks for your report!

@ghost ghost closed this as completed Sep 9, 2020
@ghost ghost added the duplicate label Sep 9, 2020
@gmnowels
Copy link

I am not sure if this feature is documented or available in stable Windows OS versions. For my case, I have tried this in latest Windows Insider build and it works. Create a /etc/wsl.conf file in your preffered WSL-ed GNU/Linux distribution. Add the following two lines in that /etc/wsl.conf file.

[network]
hostname = HelloWorld

Change the host name as you want.

Need to restart to see the change. What this does is change the name /etc/hosts file; where as, changing in the host file does not persist. In this case the wsl.conf settings will not persist.

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

No branches or pull requests

5 participants