AWS error - sudo: unable to resolve host ip-10-0-xx-xx
Asked Answered
A

13

81

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?

Aquilar answered 30/10, 2015 at 17:40 Comment(3)
Use the IP address, i.e., 10.0.xx.xx (where you have replaced the xxs with digits, of course). ip-10-0-xx-xx is not the actual IP or hostname.Skysail
@EdCottrell, I am not doing any operations with the ip. I am doing a sudo apt-get update and I still get that error. Whenever I need to access the ip, I use the public ip which is different than the private ip(ip-10-0-xx-xx)Aquilar
Ah, that's important information. You should add that to your question; I thought you meant a sudo command referencing ip-10-0-xx-xx.Skysail
W
55

You should enable the DNS hostnames on your VPC: http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/vpc-dns.html#vpc-dns-updating

If for some reason, you cannot enable it, you can still use the /etc/hosts to make it resolve, but this is definitely not the recommended solution

10.0.xx.xx ip-10-0-xx-xx
Wolfie answered 30/10, 2015 at 17:51 Comment(1)
Though its enabled I still see this problem.Epidiascope
C
86

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

Cacoepy answered 30/10, 2015 at 18:52 Comment(13)
I feel this is a better answer as it solve the problem for all machines on the VPC, not just one at a time.Sannyasi
It doesn't solve a problem for me. Though enableDnsHostnames and enableDnsSupport attributes are set to True.Caelian
@cyrillk did you change to this or was it already set that way? If you changed it, you may now need to reboot the instance. If not, then are you using custom name servers in your VPC's DHCP DNS settings?Cacoepy
@Michael-sqlbot no, I didn't change it. It has been set to True already. My server names look like ip-172-16-13-42 which is default hostname afaik.Caelian
@cyrillk sorry, I can see how my question could be misinterpreted... I did not mean servers with customized names... but rather recursive name servers other than the default ones... custom nameservers :) Console > VPC > DHCP Options Sets if you have an entry where domain-name-servers is not set to AmazonProvidedDNS and it is linked to your VPC then you are using custom name servers. Otherwise, you most likely aren't.Cacoepy
@Michael-sqlbot I've checked my DHCP settings and they look alright Options: domain-name-servers = AmazonProvidedDNS.Caelian
@cyrillk I think my answer could potentially use some additonal information because there appear to be some other cofiguration options that might break this if set incorrectly even though they are using seemingly-sensible values... but I need some confirmation. What is your domain-name setting in the DHCP option set associated with this VPC, and what AWS region is the VPC in? Also can you confirm that newly-launched instances in the same VPC exhibit the same problem?Cacoepy
@Michael-sqlbot Yes, newly launched instances have the same problem sudo: unable to resolve host ip-172-16-13-188.Caelian
@Michael-sqlbot VPC: {"Vpcs":[{"VpcId":"vpc-XX","InstanceTenancy":"default","Tags":[],"State":"available","DhcpOptionsId":"dopt-411ee129","CidrBlock":"172.16.0.0/16","IsDefault":false}]} VPC Attributes: {"VpcId":"vpc-XX","EnableDnsHostnames":{"Value":true}} and {"VpcId":"vpc-XX","EnableDnsSupport":{"Value":true}} DHCP: {"DhcpOptions":[{"Tags":[{"Value":"default_dhcp","Key":"Name"}],"DhcpConfigurations":[{"Values":[{"Value":"AmazonProvidedDNS"}],"Key":"domain-name-servers"}],"DhcpOptionsId":"dopt-411ee129"}]}.Caelian
Just ran into this issue too. I was using a 'Custom VPC' which defaults to DNS Hostnames and DNS Resolution setting turned off. In order to fix issue, turn on DNS Hostnames and DNS Resolution in the VPC, and reboot the instance through the AWS CLI. Note that 'rebooting the instance' from the guest O/S does not seem to allow the DNS setting to propogate from the hypervisor to the guest.Simonsen
In my case, the VPC was configured correctly, but it was linked to bad DHCP settings. I needed to use ec2.internal as the domain name for my DHCP settintg, and then all was resolved.Petition
@Caelian sorry 6 year later ping but did you ever resolve this outside of the workaround posted below?Blockade
@Blockade I do not remember) Sorry.Caelian
W
55

You should enable the DNS hostnames on your VPC: http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/vpc-dns.html#vpc-dns-updating

If for some reason, you cannot enable it, you can still use the /etc/hosts to make it resolve, but this is definitely not the recommended solution

10.0.xx.xx ip-10-0-xx-xx
Wolfie answered 30/10, 2015 at 17:51 Comment(1)
Though its enabled I still see this problem.Epidiascope
P
24

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

Pelvis answered 7/3, 2016 at 23:14 Comment(0)
Z
18

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:

ubuntu@ip-177-11-22-333:~$ sudo id
sudo: unable to resolve host ip-177-11-22-333
uid=0(root) gid=0(root) groups=0(root)

Fix:

ubuntu@ip-177-11-22-333:~$ 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:

ubuntu@ip-177-11-22-333:~$ sudo id
uid=0(root) gid=0(root) groups=0(root)
ubuntu@ip-177-11-22-333:~$
Zoology answered 3/3, 2017 at 9:44 Comment(0)
B
8

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.

Because answered 31/5, 2016 at 23:22 Comment(2)
In my case, problem is with the DHCP option set configuration which I changed recently. Thanks for giving the hint!Hardeman
In my case, the VPC was configured correctly, but it was linked to bad DHCP settings. I needed to use ec2.internal as the domain name for my DHCP settintg, and then all was resolved.Petition
M
8

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.

Marijuana answered 9/2, 2018 at 3:6 Comment(0)
S
7

I recently faced the same issue even though DSN was enabled in VPC.

I reviewed EC2 instances and found that my storage usage was 99%. So I truncated log files and cleaned up.

Afterwards, I rebooted it and everything worked fine.

Supererogate answered 19/7, 2022 at 17:55 Comment(1)
use sudo apt-get -y autoremove to get rid of old linux-aws-header files in /usr/src/Escolar
T
3

Add the following line to /etc/hosts

127.0.0.1 localhost
127.0.0.1 ip-xxx-xx-x-xx

The ip thing is your private ip address

Please also don't forget to reboot the instance after editing these

Tryst answered 10/9, 2020 at 10:42 Comment(0)
I
1

My issue was caused by an invalid DHCP Options set (in the VPC console). The default one that you typically want looks like this:

domain-name = ec2.internal
domain-name-servers = AmazonProvidedDNS

Somehow, my domain-name got changed to us-east-1.compute.internal, which resulted in the sudo: unable to resolve host ip-10-0-xx-xx warning every time I ran sudo. Changing back to the DHCP options above fixed it.

Interlocutor answered 23/3, 2018 at 1:43 Comment(0)
I
1

Run the following command;

sudo su -

and work as root. Then the start command will work.

Introversion answered 14/11, 2019 at 9:52 Comment(0)
C
1

I've had a similar case to @bhavesh-odedra's. My storage usage was 100%, I extended it to 5Gb more, restarted instance with sudo reboot and after that I started getting this error.

I checked disk usage with sudo df -h and found out that my Ubuntu system is not aware of extended storage. Rebooting again did not help.

I checked answers on this page. DNS hostname was Enabled in AWS VPC configs. Then I added private IP to /etc/hosts - it did not help too.

After some time and I decided to reboot instance using AWS console (not sudo reboot). I don't know whether AWS console informed my system that new storage is ready for use or something else happened, but then with sudo df -h I've convinced that my new storage space was in use. After that the error disappeared.

Creeps answered 3/11, 2022 at 9:12 Comment(1)
Same here. In my case, I couldn't even write the additional line to /etc/hosts because the disk was completely full.Depositor
M
0

To enable DnsSupport attribute just use this command in your terminal

aws ec2 describe-vpc-attribute --vpc-id vpc-****** --attribute enableDnsSupport

Make sure replace * with your VPC Id for more info https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-vpc-attribute.html

Magness answered 14/6, 2019 at 5:3 Comment(0)
A
0

In my case, I had my EC2 volume completely full. After modifying the volume and adding some space to the disk, probably my instance had some kind of corruption.

After reading the options above, I noticed that enableDnsSupport was already true for my VPC. So I didn't thought that chaning the configuration /etc/hosts sounded right.

So I interrupted the EC2 and started again. It worked without any configuration needed.

Be aware that interruption is different from reset. The behaviour is different. So if you have a window to stop the server or your service is already stopped, then you should give a try.

Albano answered 11/10, 2023 at 22:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.