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

WSL 2 Linux host cannot be accessed by a custom domain name or 127.0.0.1 #5728

Closed
JiXiaoYao opened this issue Aug 6, 2020 · 10 comments
Closed

Comments

@JiXiaoYao
Copy link

Environment

Windows 10 Professional Insider Preview Build 20180.1000
WSL 2: Ubuntu 20.04 (Linux MSI 4.19.121-microsoft-standard #1 SMP Fri Jun 19 21:06:10 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux)

Windows build number: [run `[Environment]::OSVersion` for powershell, or `ver` for cmd]
Your Distribution version: [On Debian or Ubuntu run `lsb_release -r` in WSL]
Whether the issue is on WSL 2 and/or WSL 1: [run `cat /proc/version` in WSL]

Steps to reproduce

I follow this document: https://docs.nvidia.com/cuda/wsl-user-guide/index.html
NVIDIA GPU Docker support installed in WSL 2.
Everything went well, I successfully used RTX 2080 for calculations in WSL 2 Docker.
But when I tried to access the service in Docker on windows, there was a problem.
If I execute curl localhost on the Windows command line, I can access the http (jupyter) service in Docker, but when I customize the domain name in hosts that points to 127.0.0.1, this domain name cannot be used normally when it is accessed Up.

Expected behavior

Successfully use my custom domain name to access the docker service

Actual behavior

The server rejected our connection request.

@shuohao
Copy link

shuohao commented Aug 7, 2020

same

@buby84
Copy link

buby84 commented Aug 14, 2020

I think i have the same issue but not with docker

i did upgrade my wsl from 1 to 2 almost allworking smoothly but connection to wsl is not so easy ..

in my ubuntu wsl there is installed apache so when i try to connect i have this beavhior:

http://localhost/ <- WORK
http://127.0.0.1/ <- NOT WORK !!!!!!!!
http://WSL.IPADDRESS <- WORK

i use tcp dump to check in coming connection and it look like with 127.0.0.1

i try to check if there is other windows app which use port 80 but i got just this

` Get-Process -Id (Get-NetTCPConnection -LocalPort 80).OwningProcess

Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName


101       8     1012       4692       0,03  11396   1 wslhost`

this is big problem because i have different sites to reach according to domain name.. so on hosts of windows i setup the dns but since i cant use 127.0.0.1 because is not working i need use wsl ipaddress which keep change everytime i restart the machine....

@Rainbowlemon
Copy link

Rainbowlemon commented Aug 17, 2020

Having similar issues with OS Build 20185.1000, on WSL2 Ubuntu 18.04.5 LTS (Release 18.04). Trying to access a docker container running in my linux version of docker, and I can access the page using localhost:port but can't access it with dev.project:port, despite adding the URL to my windows hosts file (and checking the linux hosts file). 127.0.0.1:port doesn't work either.

EDIT: Turns out this is probably due to IP allocation being different, or something. If I find the IP of Ubuntu's eth0 using ifconfig, and use that in my hosts file, everything works as intended... though that's not exactly an ideal solution since it'll change every time you restart your PC. Looks like this issue contains a few potential fixes, but definitely isn't ideal.

@Nek-
Copy link

Nek- commented Aug 18, 2020

As I posted here: #4150 (comment)

127.0.0.1 does not work but its alter-ego ::1 actually work. You can use http://[::1] !

And you can add a custom domain to your hosts:

# Instead of `127.0.0.1 custom.wip`
::1 custom.wip

@Rainbowlemon
Copy link

As I posted here: #4150 (comment)

127.0.0.1 does not work but its alter-ego ::1 actually work. You can use http://[::1] !

And you can add a custom domain to your hosts:

# Instead of `127.0.0.1 custom.wip`
::1 custom.wip

Unfortunately this doesn't work with my current setup (perhaps due to my docker containers)

@Nek-
Copy link

Nek- commented Aug 18, 2020

@Rainbowlemon I'm using it with docker (inside WSL2). I actually use a router on port 80 inside my docker and it works using https://custom.wip. Here is a sample of what I did if it can help:

# docker-compose.yaml
services:
  router:
    build: docker/router
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"
    ports:
      - 80:80
      - 443:443
  game:
    image: game-dev:latest
    build:
      target: builder
    volumes:
      - .:/workdir
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.game.rule=Host(`gangbowl.local`)"
      - "traefik.http.routers.game.tls=true"
      - "traefik.http.routers.game-unsecure.rule=Host(`game.local`)"
      # Comment the next line to be able to access frontend via HTTP instead of HTTPS
      - "traefik.http.routers.game-unsecure.middlewares=redirect-to-https@file"

I even used mkcert for the certificates and it worked! :)

# Makefile
prepare.windows: ## Prepare your system for Gangbowl
	sudo ./build/tools/gang_domain.sh # This setup the hosts!
	./build/tools/mkcert.exe -install
	./build/tools/mkcert.exe -cert-file docker/router/etc/ssl/certs/game.wip.pem -key-file docker/router/etc/ssl/certs/game.wip-key.pem "game.local"

@therealkenc
Copy link
Collaborator

127.0.0.1 does not work but its alter-ego ::1 actually work. You can use http://[::1] !

/dupe #4851 (+ #5298)

@ghost
Copy link

ghost commented Sep 10, 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!

@mokanfar
Copy link

mokanfar commented Feb 17, 2021

#4210 (comment)
This worked for me as a hot fix. I can not be bothered as a developer with networking quirks so I manually point to static IP in my Windows etc/hosts file for the time being until it happens again:

in WSL run:
ip addr show eth0 | grep 'inet\b' | awk '{print $2}' | cut -d/ -f1

copy that IP into your windows etc/hosts file to point to a custom domain of your choice

Example in etc/hosts of windows host:
192.168.1.148 site.com www.site.com

@J-Rincon
Copy link

This works for me. In the files of /etc/hosts and /Windows/System32/drivers/etc/hosts. Added as follows:

127.0.0.1 example.test
::1 example.test localhost

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

8 participants