Problem: "Could not resolve host" on AWS Lightsail – Domain Not Resolving Correctly

 

Problem: "Could not resolve host" on AWS Lightsail – Domain Not Resolving Correctly

Bash
$ curl -I http://mydomain.com
curl: (6) Could not resolve host: mydomain.com

Issue

Your Lightsail instance is accessible via its public IP but not when using your domain name. This typically happens due to:

  • Missing or Incorrect DNS Records – The domain is not pointing to the Lightsail instance.
  • Domain Not Configured in Lightsail DNS – The domain is registered elsewhere, but no DNS records exist in Lightsail.
  • Propagation Delay – DNS changes take time to update globally.
  • Incorrect Nameservers – The domain is using the wrong nameservers.

Fix: Check DNS Configuration, Update Records, and Verify Resolution

Bash
# Step 1: Check if the domain is configured in Lightsail
$ aws lightsail get-domains \
    --query "domains[].{Name:name}" \
    --output table

--------------------------------
|          GetDomains         |
--------------------------------
|  Name                       |
--------------------------------
# (No output means the domain is NOT configured)

# If missing, add the domain to Lightsail:
$ aws lightsail create-domain \
    --domain-name "mydomain.com"

# Step 1.1: Verify the domain is now listed
$ aws lightsail get-domains \
    --query "domains[].{Name:name}" \
    --output table

--------------------------------
|          GetDomains         |
--------------------------------
|  Name                       |
--------------------------------
|  mydomain.com               |
--------------------------------

# Step 2: List the DNS records for your domain
$ aws lightsail get-domain \
    --domain-name "mydomain.com" \
    --query "domain.resourceRecords" \
    --output table

--------------------------------------------------------
|                GetDomain (DNS Records)              |
--------------------------------------------------------
|  Name          |  Type   |  Value                   |
--------------------------------------------------------
# (If this is empty, no records exist)

# If no A record exists, create one pointing to the Lightsail instance
$ aws lightsail create-domain-entry \
    --domain-name "mydomain.com" \
    --domain-entry name="mydomain.com",type="A",target="54.123.45.67"

# Step 2.1: Verify DNS records after adding A record
$ aws lightsail get-domain \
    --domain-name "mydomain.com" \
    --query "domain.resourceRecords" \
    --output table

--------------------------------------------------------
|                GetDomain (DNS Records)              |
--------------------------------------------------------
|  Name          |  Type   |  Value                   |
--------------------------------------------------------
|  mydomain.com  |  A      |  54.123.45.67            |
|  www          |  CNAME  |  mydomain.com             |
--------------------------------------------------------

# Step 3: Check if your domain is using the correct Lightsail nameservers
$ dig +short NS mydomain.com

ns-123.awsdns-01.net.
ns-456.awsdns-02.org.
ns-789.awsdns-03.co.uk.

# If the output does NOT show AWS nameservers, update them 
# at your domain registrar (GoDaddy, Namecheap, etc.).

# Step 4: Verify if the domain resolves correctly
$ dig +short mydomain.com

54.123.45.67

# OR use nslookup:
$ nslookup mydomain.com

Non-authoritative answer:
Name: mydomain.com
Address: 54.123.45.67

# Step 4.1: What if the domain still doesn’t resolve?
# If the domain is still not resolving, force a DNS cache refresh:
$ sudo systemctl restart systemd-resolved  # For Linux
$ ipconfig /flushdns  # For Windows

# If DNS propagation is the issue, allow time (can take up to 24 hours).
# You can check DNS propagation using an online tool like:
# https://www.whatsmydns.net/

# If issues persist, double-check nameservers, DNS records, and SSL settings.

Need AWS Expertise?

If you're looking for guidance on Amazon Lightsail or any cloud challenges, feel free to reach out! We'd love to help you tackle your Lightsail projects. 🚀

Email us at: info@pacificw.com


Image: Gemini

Comments

Popular posts from this blog

The New ChatGPT Reason Feature: What It Is and Why You Should Use It

Raspberry Pi Connect vs. RealVNC: A Comprehensive Comparison

Running AI Models on Raspberry Pi 5 (8GB RAM): What Works and What Doesn't