Sunday, May 8, 2011

EC2 Sudo: Unable to Resolve Host

Sometimes after changing elastic-IP settings or stopping/starting instances on EC2, I get an irritating error like this when I execute a command with sudo:

sudo: unable to resolve host domU-12-34-ab-cd-56-78

The fix is to lookup the instance's private dns name (via ec2-describe-instances or the AWS console ui) and update the hostname on the instance with the first segment of that DNS name (which is something that looks like ip-12-34-56-78 or domU-12-34-ab-cd-56-78). On ubuntu, this is what you need to do (assuming ip-12-34-56-78 is the new hostname):

$ sudo hostname ip-12-34-56-78 $ echo 'ip-12-34-56-78' | sudo tee /etc/hostname

The first line will set the hostname until you reboot; and the second line will configure the hostname to use once you do reboot.

3 comments:

  1. Justin, Thanks a bunch for posting this fix. I looked high & low for how to get this fixed.

    ReplyDelete
  2. I have the same settings as mentioned by the answer: first part of private DNS in /etc/hostname, Still I am getting this irritating message
    sudo: unable to resolve host XXXX

    ReplyDelete
  3. I have the same settings as mentioned by the answer: first part of private DNS in /etc/hostname, Still I am getting this irritating message
    sudo: unable to resolve host XXXX

    ReplyDelete