Problem:
Windows 10 thinks localhost is ::1.
PS C:\Users\michael> ping localhost
Pinging DESKTOP[::1] with 32 bytes of data:
Reply from ::1: time<1ms
Ubuntu thinks localhost is 127.0.0.1
$ ~ > 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 DESKTOP.localdomain DESKTOP
Current Solution: 5/31/2022
I haven't been having this problem recently. I think I've done "Network Reset" once in the last 4 months.
'Network Reset' Solution: 7/27/2021
WSL is changing relatively quickly.
My current solution w/ WSL2 is
- "Start->Network Reset (system settings)->Reset
- Casually reboot windows like it's 1998.
- Get on with my life.
Solution 1:
- Read this documentation
- Notice the obscure note in wsl settings about true except for some builds.
- Add a file with these contents to
C:\Users\Me\.wslconfig, or, respectively, C:\Users\%UserProfile%\.wslconfig:
[wsl2]
localhostForwarding=true
This is what worked for me.
Solution 2:
This didn't work so well for me, but might for you. Stop automatic generation as instructed in the comments in /etc/hosts, and change localhost to ::1 so they refer to the same adapter. For compatibility, 0.0.0.0 binds to all interfaces (127.0.0.1 and ::1) so it works.
# 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 ip4-localhost
::1 localhost
...
Will this mess things up? Probably. If it does, you'll have to remember to fiddle this to get that to work.