When I try to access my website on Amazon Lightsail, I receive errors similar to "curl: (6) Could not resolve host" or "ERR_NAME_NOT_RESOLVED."
Short description
The "curl: (6) Could not resolve host" or "ERR_NAME_NOT_RESOLVED" error means that your browser or command-line tool can't resolve the domain name of your website.
Resolution
Check the domain registration
Check whether your domain is registered. Run the following whois command:
whois your_domain
Note: Replace your_domain with the name of your domain.
If the output shows the domain details, then your domain is registered.
If you receive a response such as "No match for domain 'example.com', your domain isn't registered," then you must register your domain before you proceed to the next steps.
Verify the nameservers
Make sure that your domain has the correct nameservers configured. To check the nameservers that are associated with your domain, run the following dig or whois command:
dig your_domain NS
-or-
whois your_domain | grep "Name Server"
Note: Replace your_domain with the name of your domain.
If the nameservers aren't correctly set up or if you receive an error message, then update the nameservers with your domain registrar.
Check whether the issue is local or global
Check local versus global resolution
Determine whether the issue is specific to your local machine or if it's a global problem. Access your website from a different network or device. If the website loads, then the issue is within your local network or machine configuration.
Verify resolver configuration
If the issue is localized, then check the DNS resolver configuration on your local machine. The DNS resolver translates domain names into IP addresses. Be sure that the DNS servers that are configured on your machine can resolve the IP address.
To check the DNS server settings in Windows, run the following command in the command prompt:
ipconfig /all
To check the resolver configuration on macOS or Linux, open the /etc/resolv.conf file and verify the listed DNS servers.
If the configured DNS servers are incorrect or unresponsive, then update them or contact your network administrator for help.
To identify where the DNS resolution process fails, run the following dig +trace command:
dig +trace your_domain
Note: Replace your_domain with the name of your domain.
Use the dig +trace command to perform a recursive DNS lookup and find the path of DNS servers that you queried to resolve your domain.
Failure at TLD
If the query stops at the TLD level, then there's an issue with the domain registration or nameservers. Run the whois command to verify the registration status and nameserver information.
Failure at the nameserver
If the query reaches the nameserver but fails to retrieve the A record (IP address), then there are several issues to investigate:
- The A record for your domain isn't configured on the nameserver.
- The nameservers listed at the registrar are incorrect or outdated.
- There's no hosted zone configured on the nameserver for your domain.
To check whether the nameservers have the A record, run the following command:
dig your_domain @nameserver_ip
Note: Replace your_domain with the name of your domain. Replace nameserver_ip with the IP address of your nameserver.
If the output shows the correct IP address for your domain, then the issue is unrelated the nameserver.
Update the nameserver or register the domain
Check the hosts file for a nameserver and registered domain
The hosts file on your local machine is a static file that maps hostnames to IP addresses. If there's an incorrect entry for your domain in the hosts file, then it causes resolution errors.
Note: On Windows, the hosts file is located at C:\Windows\System32\drivers\etc\hosts. On macOS or Linux, the hosts file is located at /etc/hosts.
Open the hosts file with a text editor, and then check whether there's an entry for your domain. If there's an entry, then verify that its associated IP address is correct. If the entry is incorrect or unnecessary, then remove or comment it out.
If the domain is unregistered or the nameservers are incorrect, then register the domain or update the nameservers at the registrar.
For an unregistered domain, complete the following steps:
- Verify that the domain name is registered.
- Enter the nameservers provided by your hosting provider or DNS service.
For incorrect nameservers, complete the following steps:
- Log in to your domain registrar's AWS account.
- Navigate to the domain management section and locate the nameserver settings.
- Update the nameservers with the correct information provided by your hosting provider or DNS service.
- Save the changes, and wait for the DNS updates to propagate globally (up to 48 hours).
Configure the A record on the nameserver or update the nameserver records at the registrar
If the dig +trace output reaches the nameserver but fails to retrieve the A record (IP address), then configure the A record on the nameserver. Or, update the nameserver records at the registrar.
To configure the A record on the nameserver (Lightsail DNS), complete the following steps:
- In the Lightsail console, navigate to the Networking section.
- Select the DNS zone for your domain.
- Choose Add record. Then, create a new A record with your domain name and IP address (such as the public IP address of your Lightsail instance).
- Save the changes, and then wait for the DNS updates to propagate globally (up to 48 hours).
If you use a custom nameserver (a nameserver that's not hosted on Lightsail), then update the nameserver records at your domain registrar. To update the nameserver records at the registrar, complete the following steps:
- Log in to your domain registrar's AWS account.
- Navigate to the domain management section, and then locate the nameserver settings.
- Update the nameserver records with the correct IP addresses of the nameservers hosting your domain.
- Save the changes, and then wait for the DNS updates to propagate globally (up to 48 hours).
Create a hosted zone and update the zone files with the correct DNS records
The dig +trace output might reach the nameserver but fail to retrieve the A record. Check whether there's a hosted zone configured for your domain on the nameserver. For more information, see Create a DNS zone to manage domain records for Lightsail instances.
Related information
How can I use AWS CLI commands to manage my Lightsail instance?
Understanding DNS in Lightsail