With the discharge of the Home windows 10 Insider construct 18945, the Home windows Subsystem for Linux model 2 now helps the power for Home windows 10 functions to hook up with WSL2 apps through localhost.
When WSL2 was first launched, it not had the power to connect with a WSL2 Linux server from Home windows 10 functions utilizing the localhost tackle.
In case you needed to hook up with a WSL2 app out of your Home windows functions, you’d now need to lookup the IP tackle assigned to the operating Linux distribution and connect with that as a substitute.
Home windows 10 Insider construct 18945 has now added the localhost characteristic to WSL2 and you may connect with your domestically operating Docker, NPM, or different providers through Localhost. That is illustrated utilizing the nc command within the picture beneath.
With this characteristic added, customers can now take pleasure in the advantages of the elevated WSL2 efficiency whereas nonetheless having the ability to simply entry any linux servers that they’re operating.
Bind servers to 0.0.0.0 for localhost to work
Some customers have had points getting the localhost characteristic to work in WSL2 as a result of their servers are sure to 127.0.0.1.
WSL program supervisor Craig Loewen has said in a WSL2 bug publish that to ensure that the localhost to work, server must be accessible to all IP tackle and thus sure to 0.0.0.0.
“Are you able to verify what IP tackle your php occasion is sure to? I believe that it is solely accepting connections from localhost (127.0.0.1) and it wants to have the ability to settle for incoming connections from all IP addresses (i.e: bind it to 0.0.0.0).
So that you would wish to run the command: php -S 0.0.0.0:8000″
For instance, the consumer reported that they had been unable to get PHP engaged on localhost with the php -S localhost:8000 command.
It’s because the HOSTS file maps localhost to the precise 127.0.0.1 loopback tackle and thus the characteristic did not work.
When the consumer sure PHP to 0.0.0.0, utilizing the php -S 0.0.0.0:8000 command, the localhost connection characteristic labored.