11

I have a bunch of amazon ec2 instances. Today, for no reason I can determine, three of them became unable to resolve a specific url. When I try curl <url>, those three instances say "curl: (6) Could not resolve host", while all the other instances are able to resolve the url and return the correct data. It's only that specific url, as well - all other urls work fine.

What could have caused this? I haven't changed anything on any of the instances, so it's not something I did. How do I find out why it happened?

1
  • just happened to me as well, /etc/hosts looks just fine, and btw curl 127.0.0.1 gives the same error, so it cannot be /etc/hosts or resolv.conf. it happened when i started a process that took quite a bit of memory, and made the instance super slow. once the process was killed, the instance recovered and curl started working again, so it's some aws fluke.
    – milan
    Oct 8, 2018 at 7:55

8 Answers 8

11

I was able to fix it after enabling that service:

sudo systemctl enable --now systemd-resolved.service
2
  • Thanks! Solved my problem too. Sep 30, 2021 at 22:01
  • --now is necessary because it means starting the service immediately after enabling a service. Enabling only is not enough, and need to start the service as well.
    – Felix Htoo
    Jun 20, 2022 at 5:40
6

Check and compare /etc/resolv.conf (for Linux instances) between working and non-working hosts. here is info from my Linux instance:

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 10.0.0.2
search us-west-2.compute.internal

In case of Windows instances, check and compare the output of ipconfig /all command for DNS entries between working and non-working hosts. here is info from my windows instance:

Windows IP Configuration

   Host Name . . . . . . . . . . . . : WIN-************
   Primary Dns Suffix  . . . . . . . :
   Node Type . . . . . . . . . . . . : Hybrid
   IP Routing Enabled. . . . . . . . : No
   WINS Proxy Enabled. . . . . . . . : No
   DNS Suffix Search List. . . . . . : us-west-2.ec2-utilities.amazonaws.com
                                       ec2.internal
                                       us-east-1.ec2-utilities.amazonaws.com
                                       compute-1.internal
                                       us-west-2.compute.internal

Ethernet adapter Local Area Connection:

   Connection-specific DNS Suffix  . : us-west-2.compute.internal
   Description . . . . . . . . . . . : Citrix PV Ethernet Adapter #0
   Physical Address. . . . . . . . . : 02-E6-AB-83-C6-8A
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
   IPv4 Address. . . . . . . . . . . : 10.0.0.251(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Lease Obtained. . . . . . . . . . : Friday, March 21, 2014 11:36:17 AM
   Lease Expires . . . . . . . . . . : Tuesday, March 25, 2014 5:07:59 AM
   Default Gateway . . . . . . . . . : 10.0.0.1
   DHCP Server . . . . . . . . . . . : 10.0.0.1
   DNS Servers . . . . . . . . . . . : 10.0.0.2
   NetBIOS over Tcpip. . . . . . . . : Disabled
0
5

If you’re not using the default VPC, or a VPC created by the VPC wizard, you’ll need to make sure that the DNS hostname and DNS resolution options are enabled.

3

I have encountered the same issue. This might be the reason of the issue .Disk space full so /etc/resolve.conf file gets cleared then Its unable to resolved the host

This solution works for me.

Clean the fulled spaces

Update the resolve.conf from the working ec2 instance of same vpc

1

Here is my checklist of things to verify. Are you 100% sure nobody / nothing changed the following:

  • DNS Settings on the instance? (check with dig to see if name resolution is OK)
  • NACL rules on the subnet where your instance is running?
  • Security Group rules of the SG attached to your instances?

Seb

0

this answer will probably solve your issue, as it did mine. you must fix your hosts file to

127.0.0.1    localhost.localdomain localhost
127.0.1.1    my-machine

or

127.0.0.1    localhost
127.0.1.1    my-machine

where my-machine is the host name that appears at the end of the error message.
(e.g. mine was domX-A2-33-D9-CB-F4-A8)

don't forget to reboot your instance from your management console after you have changed the hosts file. ;)

2
  • 1
    How will this solve the issue? 127.0.0.1 is the loopback address, which is not externally reachable. I was trying to connect to the server from an external machine, are you saying that amazon is somehow using localhost to produce the dns entries?
    – Benubird
    Nov 4, 2014 at 9:01
  • you use BOTH localhost 127.0.0.1 AND 127.0.1.1 machine-name as stated in the "host unreachable" error. i dont know the technical background behind it, only that it worked for me. ;)
    – tony gil
    Nov 4, 2014 at 18:26
0

Make sure VPC has the below configuration enabled DNS resolution: Enabled DNS hostnames: Enabled

As well as correct DHCP options set attached to VPC

0

It worked after reinstalling resolvconf

sudo apt-get install --reinstall resolvconf

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.