DNS is one of the most fundamental parts of a website. No website can run without a proper configuration on DNS. For beginners, it might be a bit difficult for them to understand and resolve DNS-related issues. This post aims to provide a bit more help for those who are still struggling to configure the DNS for their websites.
In short, what is DNS and why we need it?
DNS stands for Domain Name Service. You can think of it as a computer responsible for converting the domain name to an IP address. For example, if I type
facebook.com into my browser, the DNS will look into its database and return the IP address of this domain, which is
18.104.22.168. Because of this, most of the issues about the domain name of your websites are related to DNS.
We need DNS because our human memory is limited and we cannot remember all complex and meaningless IP addresses of all websites in the world. It is just like how we call other people by their names instead of using their social security IDs.
In DNS, there are multiple record types: CNAME, A, MX, etc. I am not going to talk about all of these. Instead, I am going to go through some common issues we might see when working with DNS.
- WWW and non-WWW are pointing to different places
In order to support www and non-www domain, we need to add both of them as records in the DNS. If you only add one of them, then the other won't work. Usually, we will add
non-www record as the A type (which points to the IP address), and then add a
www record as a CNAME which points to the non-www we have just added.
- Nothing happens after my updates to the DNS
There are cases when you point the domain to a different hosting (different IP) but it keeps redirect users to the old hosting. The reason is because there are many DNS servers placed around the world. When we modify our DNS settings, we only do that at a single place. We have to wait for this place to inform other places about our changes. This process is called "DNS propagation" and it can take minutes or hours to complete. Therefore, you need a bit of patience to see the new update. You can use this service to check the DNS propagation process: https://www.whatsmydns.net/
One more reason for a slow DNS update is the DNS cache on your own computer. In order to avoid the latency of requesting for the IP address of a specific domain, all IP address of a host is cached on our computer after the first request. And the next time you request for resources from a domain, the IP address of that domain will be returned immediately without asking the DNS. Because of this, even after you make changes to the DNS settings, the local computer might still contain the old IP address. The solution is to flush the DNS cache. This process is different on each computer depending on the operation system you are using. For MAC: https://support.apple.com/en-us/HT202516, for Ubuntu: http://www.cyberciti.biz/faq/rhel-debian-ubuntu-flush-clear-dns-cache/
- Email service
Assuming that you have the domain
example.com. How to create the email address
firstname.lastname@example.org so that people can send an email to that address? Remember that if you own the domain, then it means you also own all the email addresses associated with that domain.
The first thing you need to do is to install a Mail Transfer Agent (MTA) on the server. You can also use a third-party service like Google Apps instead of installing your own MTA. But at least, you need an MTA for receiving the email. The next step is to add an MX record to the DNS. MX stands for Mail Exchange and it tells you where to deliver the email when someone send an email to an address belongs to your domain. Missing MX records is a common mistake. You need to point the MX record to the MTA (which is your server or the third-party service).
An important point of configuring DNS is knowing exactly which name servers this domain belongs to. The domain might have been configured with different services and usually these services provide their own name servers for managing the domain (AWS, DigitalOcean, Hostgator, ...). Sometimes we forget the latest nameserver of the domain and keep making changes to the old nameserver. Then we wait for even up to 24 hours without seeing any update. This is also a common mistake and it can be easily avoided by checking domain's nameserver first (using http://whois.domaintools.com/).
- Some notes
Even though most of the issues about the website domain are related to DNS, some issues are not. The recommended first few steps to check the issue are:
- Check if the domain is pointing to correct IP address
- Check DNS propagation
- Clear the DNS cache
If everything seems to be fine, check your web server configuration.