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 127.0.0.1 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.


After doing this, all network related Ubuntu tools should not produce this error.See the following screenshot:

That's it.

Support us

Winaero greatly relies on your support. You can help the site keep bringing you interesting and useful content and software by using these options:

If you like this article, please share it using the buttons below. It won't take a lot from you, but it will help us grow. Thanks for your support!

Author: Sergey Tkachenko

Sergey Tkachenko is a software developer who started Winaero back in 2011. On this blog, Sergey is writing about everything connected to Microsoft, Windows and popular software. Follow him on Telegram, Twitter, and YouTube.

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

  1. Your listed command
    echo 127.0.0.1 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 ‘127.0.0.1 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 127.0.0.1 `hostname` >> /etc/hosts

  2. 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. Specifically, trying things like…

      sudo apt update

      Fails with a number of errors, including…

      Err http://archive.ubuntu.com trusty Release.gpg
      Could not resolve ‘archive.ubuntu.com’

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

Leave a Reply

Your email address will not be published.

Exit mobile version
Using Telegram? Subscribe to the blog channel!
Hello. Add your message here.