Error message when I run sudo: unable to resolve host

I have this issue on AWS on some servers. Whenever I run sudo the terminal is stuck doing seemingly nothing, until it finally spits out this error message. My terminal looks like this:ubuntu

ubuntu@(none):~$ sudo true
sudo: unable to resolve host (none)

What can I do to solve it?app

Please post the contents of /etc/hostname and /etc/hostsdom

make sure your hostname same with hosts. e.g. the hostname is ubuntu-pc and hosts is ubuntu-pcmust be same.ide

wo things to check (assuming your machine is called my-machine, you can change this as appropriate):post

  1. That the /etc/hostname file contains just the name of the machine.this

  2. That /etc/hosts has an entry for localhost. It should have something like:spa

     127.0.0.1    localhost.localdomain localhost
     127.0.1.1    my-machine

If either of these files aren't correct (since you can't sudo), you may have to reboot the machine into recovery mode and make the modifications, then reboot to your usual environment.code