amazon-web-services - ubuntu1604 - unable to resolve the host name




AWS error-sudo: unable to resolve host ip-10-0-xx-xx (6)

I launched a new aws instance. My private ip is ip-10-0-xx-xx as per amazon console. Everytime when I do a sudo command, I get the following error

sudo: unable to resolve host ip-10-0-xx-xx

How can I rectify this error?


Can patch easily from command line as follows:

sudo sed -i /etc/hosts -e "s/^127.0.0.1 localhost$/127.0.0.1 localhost $(hostname)/"

And checked that a reboot, or stop, then start the aws instance would preserve it. In case it is lost, can easily re-apply on boot, and can be added to any provision for new vms.

Example

Before:

[email protected]:~$ sudo id
sudo: unable to resolve host ip-177-11-22-333
uid=0(root) gid=0(root) groups=0(root)

Fix:

[email protected]:~$ sudo sed -i /etc/hosts -e "s/^127.0.0.1 localhost$/127.0.0.1 localhost $(hostname)/"
sudo: unable to resolve host ip-177-11-22-333

After:

[email protected]:~$ sudo id
uid=0(root) gid=0(root) groups=0(root)
[email protected]:~$

It seems that it cannot resolve the host so you can help it by adding this line to the /etc/hosts

10.0.xx.xx ip-10-0-xx-xx

The below answer with enableDnsHostnames is a better solution through


This issue is caused by not enabling enableDnsHostnames in your VPC configuration.

enableDnsHostnames

Indicates whether the instances launched in the VPC get DNS hostnames. If this attribute is true, instances in the VPC get DNS hostnames; otherwise, they do not. If you want your instances to get DNS hostnames, you must also set the enableDnsSupport attribute to true.

http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/vpc-dns.html#vpc-dns-updating


This worked for me:

Add the following line to /etc/hosts

127.0.0.1 ip-xxx-xx-x-xx

The ip thing is your private ip address


Two Options:

  1. Enabling the DNS hostnames for your VPC, so all the instances launched within the VPC will resolve the host

  2. Edit /etc/hosts and add the below line

    127.0.0.1 localhost    
    123.0.0.1 ip-10-0-1-18 ## (Replace with the private ip)
    

This is something you will need to do for every instance that will be launch within your VPC.


enableDnsHostnames as described in Michael's comment is one prerequisite. The other is having your VPC's DHCP option set configured correctly . The problem you are coming up against is caused by search line missing from your /etc/resolv.conf ; it will be put in there at the time of DHCP assignment if you set domain-name of your DHCP option set appropriately. Read the linked AWS doc.





sudo