7

I'm using Windows Bash and I'm getting the error fox@FOX:/etc$ sudo true sudo: unable to resolve host FOX

I've seen people say I'm suppose to edit etc/hosts, but I don't know what to put in the file. Can someone tell me what I'm suppose to put to fix this?1

2 Answers 2

10

You can fix this by adding an entry to your /etc/hosts for your machine's hostname.

If you want a one-liner, something like this will do it:

printf "\n127.0.0.1   $HOSTNAME\n" | sudo tee -a /etc/hosts

This will append a line to your hosts file that will resolve the current hostname to 127.0.0.1.

When you run the command above you'll be prompted for the root password you set when the Windows Linux subsystem was installed. Also, since this command starts a shell for the root user just before it runs you'll actually see the sudo: unable to resolve host WHATEVER message one last time just before the change is made.

Alternatively, you run an editor (such as nano) as root and add the entry manually:

sudo nano /etc/hosts
1

Here's a link to a workaround posted on the github issues tracker by user benhillis, stating:

This is occurring because the /etc/hosts file does not contain your machine's name. To work around this you can remove /etc/hosts and it will be re-created after closing all open bash.exe windows and launching bash.exe

I can confirm this worked for me on Windows 10 Pro 64 build 1607.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .