Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
DNS Basics

#DNS Basics Domain names are a core feature of the internet. It is simply a mechanism to give a friendly name to remove the need to use ip addresses directly. It also has a number of advantages, such as:

  1. It allows you to have more than one domain name pointing at the same ip address (ie same website).
  2. It allows you to host more than one website on a specific ip address (ie shared hosting, the website shown in the one associated with the domain name)
Record Type Description
A Record Translates machine names into IPV4 addresses
AAAA Record Translates machine names into IPV6 addresses
MX Record Specifies the names of the mail servers that handle mail for a specified domain
NS Record These records specify the name servers for a specified domain
PTR Record These are mainly used for reverse lookups - translating IP addresses to machine names
CNAME Record These simply redirect to another machine name, like an alias

##Client Side DNS

DNS Lookup Process

When you look for a domain name your system will consult /etc/nsswitch.conf. This file details the order in which locations will be check to help resolve the domain name.

# /etc/nsswitch.conf
# Example configuration of GNU Name Service Switch functionality.
# If you have the `glibc-doc-reference' and `info' packages installed, try:
# `info libc "Name Service Switch"' for information about this file.

passwd:         compat
group:          compat
shadow:         compat

hosts:          files mdns4_minimal [NOTFOUND=return] dns mdns4
networks:       files

protocols:      db files
services:       db files
ethers:         db files
rpc:            db files

netgroup:       nis

From this file you can see the order in which it checks to resolve the host.

hosts:          files mdns4_minimal [NOTFOUND=return] dns mdns4

This indicates that it should consult the host file first and the check the dns if an entry is not found.

###Host file The client host file is located in /etc/hosts (in Windows it is in c:\windows\system32\drivers\etc\hosts. This file is the first place that is checked for the domain name lookup. If it is not found here then it will proceed to check with the domain name server (DNS).       localhost

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

###DNS locations The location of the DNS servers to consult is stored in the /etc/resolv.conf file.

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)

# OpenDNS Fallback (configured by Linux Mint in /etc/resolvconf/resolv.conf.d/tail).

###Domain Name Lookup To lookup the entry associated with a name you can use nslookup.



Non-authoritative answer:	canonical name =	canonical name =	canonical name =

###NS Records You can get a list of the name servers using dig. For example to get the list of root name servers you can do the following:

dig ns .

; <<>> DiG 9.9.2-P1 <<>> ns .
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 36321
;; flags: qr rd ra; QUERY: 1, ANSWER: 13, AUTHORITY: 0, ADDITIONAL: 0

;.				IN	NS

.			85901	IN	NS
.			85901	IN	NS
.			85901	IN	NS
.			85901	IN	NS
.			85901	IN	NS
.			85901	IN	NS
.			85901	IN	NS
.			85901	IN	NS
.			85901	IN	NS
.			85901	IN	NS
.			85901	IN	NS
.			85901	IN	NS
.			85901	IN	NS

;; Query time: 12 msec
;; WHEN: Sun Jul 14 21:18:27 2013
;; MSG SIZE  rcvd: 241

This shows that there are 13 name servers named a to m. In reality, there are more than 13 physical servers. Each of these domain servers may consist of many load balanced servers.

DNS Simple Load Balancing It is possible to have more than one entry for a domain name. Thus you could have two A Records:

In this situation, one of the ip addesses at random will be used when someone request the domain name This is a simple way to spread the load over two or more servers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment