If you are running Raspbian on your Raspberry Pi, you might see a message like the following when you try to sudo after changing your devices’s hostname:

sudo: unable to resolve host hostname

Of course, replace “hostname” with your own machine’s hostname. Everything works just fine even despite this warning, it’s just annoying to look at. Luckily, the fix is very simple.

It is likely that you only changed the hostname in one of two locations, while you should change it in both of these files in order to get rid of this message:

  • /etc/hostname
  • /etc/hosts

That’s it!