Introduction to DNS

on Sunday 30th September, 2007 Gabe speculated thusly…

If you are a beginner with DNS then you might find this quick article useful. Recently I have had to play with various DNS records to get mail servers and web servers working.

Introduction to DNS

DNS stands for Domain Name System. In simple terms it’s like this: people are good at remembering and writing names. Computers are great with numbers and calculations. When you open your browser you may type in an address such as google.com or fartymarty.com, but that is not what the computers use. They use numbers, each and every computer on the internet has a unique number assigned to it. This is called an IP address. This is where DNS comes in to play, it translates your names into numbers (computer addresses). For example if you go to google.com your browser will send a DNS query, the reply comes back has the numeric IP address of the google server, which in my case is 72.14.207.99. If you were to go to this IP or type in google.com you would get to the same place!

If you have your own domain name you may need to configure the DNS for it, so people typing in yourdomain.com are given back the correct IP address of your server - otherwise they won’t be able to find your site!

‘A’ record

Firstly we will concern ourselves with three DNS record types, the most commonly used ones. Perhaps the most useful is the A record. This is what will convert your domain mydomain.com in to a numbered address that computers use (IP address). Thus, if you have a web server (for example) listening at the address 12.34.56.78 and you want to be able to type in mydomain.com to your browser to visit it, you will need to create an A record. The cool thing is that mail servers will fall back to using it in the event you haven’t created an MX record… something that we are going to move on to.

MX record

MX record stands for ‘mail exchanger’ and it is unique to email servers. If you have an email server at 12.34.56.78 and you want it to be able to receive emails that people address to you at mydomain.com you will want to create an MX DNS record. This record includes the hostname, the priority and the domain. Your first MX entry will probably want to have a priority of 0 or 10. The hostname for the mail server can be (for example) mail.mydomain.com and your domain can be mydomain.com. Whatever hostname you use for the mail server must also have an appropriate A record. So you might end up with something like this:

NAME TYPE DATA
mydomain.com A 12.34.56.78
mail.mydomain.com A 12.34.56.78
mydomain.com MX 10 mail.mydomain.com.

Notice the ‘10′ for the MX server, denoting priority. You can configure backup mail servers in case the primary one fails. You would create another MX record for the same name, with a higher priority (20 for example) and the address of another server. So ultimately you could have:

NAME TYPE DATA
mydomain.com A 11.11.11.11
mail.mydomain.com A 11.11.11.11
mail2.mydomain.com A 22.22.22.22
mydomain.com MX 10 mail.mydomain.com.
mydomain.com MX 20 mail2.mydomain.com.

CNAME record

That leaves CNAME records. These are easy and are basically aliases. They come in useful when you want to create wildcards and subdomains. It is normally a good idea to create at least one CNAME for www so that if someone types in www.mydomain.com they will still get to mydomain.com:

NAME TYPE DATA
www CNAME mydomain.com.

And that’s it for the basics. Just be sure you use IP addresses for some things and hostnames for the others. ‘A’ records always resolve to an IP address. MX and CNAME records resolve to a hostname. Hope that helps you.

Tags: , , ,

Leave a Reply