sudo: unable to resolve host ubuntu

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):

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

Change the hostname in Mac OSX

When I log into the network at work my Mac’s hostname always turns to:

I have my local hostname set to:

So What I would like to do is set my Mac’s hostname to my local hostname. You can do this all from Terminal in a single line.

Run this command in Terminal:

This is also helpful if you’re in Terminal and have a really long hostname at your prompt. If you want to view your current hostname, run this command in Terminal:

Update (February 13, 2012): Some people have reported that their hostname is not updating. Please try closing your current Terminal session and starting up a new one. Then type “hostname” and you should see your changes.

This is what it looked like for me:

Assign a Static IP Address to Virtual Machine

Here we edit the /etc/network/interfaces file

Now you want to enter the following information (changing your address wherever necessary)

Now we edit the hosts file

and add the following

Edit the hostname file

and add the following

Then restart networking

That’s it!