While working with the new Windows Subsystem for Linux beta on Windows 10, I noticed that any time I ran a command with sudo I would get a long pause and the following error printed to the screen.

sudo: unable to resolve host OPTIMISTPRIME

The command would still run, but the pause would last for several seconds while this resolution failure happened.

It appears that the hosts file located at /etc/hosts was missing an entry. I added the entry and the problem went away. Here is what it looks like now:

Note the third line 127.0.0.1 OPTIMISTPRIME.

If you are unfamiliar with linux it might be confusing figuring out how to edit this file so here is a step by step guide.

  1. Make sure you know what your hostname is by running cat /etc/hostname.
  2. Open the hosts file in VIM sudo vim /etc/hosts.
  3. Navigate to an empty row with your arrow keys and hit the i key to enter insert mode.
  4. Type the localhost address followed by a space and your hostname exactly as it appears in the hostname file.
  5. Hit the Esc key to switch back to normal mode.
  6. Type :wq followed by enter, to write your changes and quit VIM.
  7. Close bash and reopen it just for good measure.

TEEHEE Yes my windows VM is named OptimistPrime and my OSX host is named Negatron.