Fix unable to resolve host error in Bash on Ubuntu in Windows 10

If you run the sudo command in Bash on Ubuntu in Windows 10, you might face the issue that it shows an error message unable to resolve host followed by your computer name. Here is a quick fix for this issue.
bash error
Under Windows 10, Bash on Ubuntu can't resolve the host name defined in the standard configuration file /etc/hostname. To fix it, you need to specify the IP address manually which matches the host name.

This can be done with the following commands. Execute them one by one.

sudo su
echo your_pc_name >> /etc/hosts

The first command switches the user context to the root user.
The second adds a new line to the file /etc/hosts which tells that your_pc_name should be resolved to the local computer. Replace the your_pc_name portion with the actual PC name.

Fix unable to resolve host error in Bash
After doing this, all network related Ubuntu tools should not produce this error.See the following screenshot:

bash no errorThat's it.


6 thoughts on “Fix unable to resolve host error in Bash on Ubuntu in Windows 10

  1. celmor

    Your listed command
    echo your_pc_name > /etc/hosts
    doesn’t “*add* a new line to the file /etc/hosts “, it overwrites it so you will loose existing entries like ‘ localhost’.
    You need to use ‘>>’ to append standard output (produced by echo) to files
    Following command will work and automatically resolves hostname through command substitution (backquotes).
    echo `hostname` >> /etc/hosts

    1. Sergey Tkachenko Post author

      Sorry, sure it should be >>
      I made a typo.
      Thank you very much, fixed.

  2. Tj

    I *just* finished installing the “ubuntu on windows” components. I tried installing some packages with apt-get, but they fail to resolve the host names.

    I just came across your post here and tried what you suggested. However, even after the initial “sudo su” before adding the line to /etc/hosts file, “sudo su” fails to run with the same error (“sudo: unable to resolve host {PC NAME}”), as does any successive calls.

    Any ideas?

    1. Tj

      Specifically, trying things like…

      sudo apt update

      Fails with a number of errors, including…

      Err trusty Release.gpg
      Could not resolve ‘’

    2. Tj

      Please delete this threads (should you wish.) Rebooting seems to have resolved my issue (“sudo apt update” now executes without issue.)

      1. Sergey Tkachenko Post author

        Happy to hear!
        But why delete it. It might be helpful for others.


Leave a Reply

Your email address will not be published. Required fields are marked *