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?
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?
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
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
enableDnsHostnames
and enableDnsSupport
attributes are set to True
. –
Caelian ip-172-16-13-42
which is default hostname afaik. –
Caelian 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 Options: domain-name-servers = AmazonProvidedDNS
. –
Caelian sudo: unable to resolve host ip-172-16-13-188
. –
Caelian {"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 ec2.internal
as the domain name for my DHCP settintg, and then all was resolved. –
Petition 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
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
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:~$
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.
ec2.internal
as the domain name for my DHCP settintg, and then all was resolved. –
Petition Two Options:
Enabling the DNS hostnames for your VPC, so all the instances launched within the VPC will resolve the host
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.
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.
sudo apt-get -y autoremove
to get rid of old linux-aws-header files in /usr/src/ –
Escolar 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
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.
Run the following command;
sudo su -
and work as root. Then the start command will work.
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.
/etc/hosts
because the disk was completely full. –
Depositor 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
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.
© 2022 - 2024 — McMap. All rights reserved.
10.0.xx.xx
(where you have replaced thexx
s with digits, of course).ip-10-0-xx-xx
is not the actual IP or hostname. – Skysailsudo 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) – Aquilarsudo
command referencingip-10-0-xx-xx
. – Skysail