I have a server on amazon which normally runs like a champ; after increasing the instance size this weekend, then decreasing it back down to its normal size, I've started to get odd errors every time I run a command under sudo
. Here's an example:
sudo ps -ef
sudo: unable to resolve host domU-##-##-##-##-##-##
Where # is a number. Its important to note the command then executes as expected. I thought there might be something bound oddly in my hosts file so I had a look at that:
127.0.0.1 localhost
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
And it seems pretty normal although I don't know enough to be sure. Can anyone shed some light on this repeating error and how to go about fixing it?
Ensure that your hostname is in /etc/hostname. To see what is in there now, you can either run hostname -f or cat /etc/hostname.
When you move your EC2 instances around, you lose your hostname so it no longer matches the hostname at the time you installed Ubuntu.
It seems that you are not using the correct Amazon DNS.
If your EC2 instance is in the VPC
172.31.0.0
, the DNS you should use is172.31.0.2
. So you have to "add two" to the last number.Only the DNS of your VPC will respond to your local hostname
ip-XXX-XXX-XXX-XXX
.From the documentation:
http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_DHCP_Options.html#AmazonDNS
I had this issue when I copied settings from one availability zone to another. The DHCP Option Set for my VPC was pointing at us-west-1 but my new VPC was in us-west-2. As a result, when the machine was started, the EC2 scripts that set up the machine were putting this into my resolv.conf file
After creating a new DHCP option set with domain=us-west-2.compute.internal and applying that to my VPC, once I restarted my EC2 instance, the resolve.conf file looked like this
(note the us-west-2 in the second block versus the us-west-1 in the first), and I no longer got the "unable to resolve host" error.