Cloud Platforms- sudo: unable to resolve host [closed]
Asked Answered
P

2

8

I use linux for my cloud based servers on Amazon-EC2 and openstack. When trying to run:

sudo chhown ubuntu somepath

I get this error every once in a while:

sudo: unable to resolve host

Most answers to this question on the internet are to edit the /etc/hosts file.

However, I deploy my servers automatically. besides that, I am not logging on using "localhost", but rather my AWS public DNS:

ssh -i mykey.pem [email protected]

So I cannot just trivially insert localhost, not to mention that my IP can change after I reset my machine. (Don't want to "waste" my precious floating IPs for every server)

Also, I deploy tens of servers at a time, so I cannot afford the manual step of editing a text file. Is there an automated fix for this issue? Recently I've started using openstack, and the issue is present there too.

Priapism answered 2/1, 2015 at 11:2 Comment(5)
how about sudo -s; chown ubuntu somepath? any error?Capitate
Same error: unable to resolve hist SOME_DNS .Strange, this time I was unable to re-create it from AWS. But it consistantly manifested in openstack. I have noticed that while I ssh to an IP, the shell prompt is: ubuntu@SOME_DNS . SOME_DNS is the internal server name so i cannot ssh to it from the outside.Priapism
from outside, you need use public ipCapitate
In this case (openstack), I did use a public IP (otherwise SSH would not have worked). But when I am already logged on, the prompt shows the hostname. With AWS I also have a public host-name, but that is not the case this time around.Priapism
When you type your command, your terminal displays : username@yourservername:~$ sudo chhown ubuntu somepath. To fix this issue, you could try to add the line 127.0.0.1 yourservername to the file /etc/hosts. Works for me.Louisville
N
24

EC2 instances inside VPC will resolve their auto-assigned internal hostnames correctly, only if you configure the VPC correctly. You need:

DNS hostnames: yes
DNS resolution: yes

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

Naldo answered 2/1, 2015 at 18:57 Comment(6)
Looks reasonable, I can't duplicate the error in my environment, then can't judge this answer. Wait for OP's feedback.Capitate
Thanks, Any idea about Openstack?Priapism
wow, I've been wondering how to properly do this for a while. Great pro tip!Adventure
I have the same issue, I have tried this but it still doesn't work for me :(Anodic
@Anodic if you have configured a domain suffix in your dhcp settings for the VPC, this will also happen if the records aren't in DNS.Naldo
@Michael-sqlbot Can you elaborate on that? What records need to be in DNS? I'm trying to understand my company's AWS setup and I think what you're describing might be the problemJacksnipe
O
4

To resolve this problem I ran the following commands:

sudo vi /etc/hosts

Then in the hosts file that opens up add:

127.0.0.1     10.0.30.150

Obviously the 10.0.30.150 address would be the IP of the host in the warning message.

Oralee answered 16/9, 2015 at 8:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.