Unable to resolve host name in WSL

Solution 1:

I don't know why it happens (please improve the answer with an explanation), here is a working solution for this problem:

1. Execute:

nano /etc/hostname

Type your machine name in capital letters ( it would be something like DESKTOP-SOMETHING). Delete anything besides your machine name.

Save and exit.

2. Then, execute:

nano /etc/hosts

Then, Make sure the file's first two rows looks as follows:

  127.0.0.1 localhost.localdomain localhost
  127.0.1.1 DESKTOP-SOMETHING

Save and exit.