Skip to content

Instantly share code, notes, and snippets.

@limkokhole
Forked from leommoore/dns_basics.md
Created January 30, 2021 03:34
Show Gist options
  • Save limkokhole/9d3b97fb353580ec401deb99b2a09651 to your computer and use it in GitHub Desktop.
Save limkokhole/9d3b97fb353580ec401deb99b2a09651 to your computer and use it in GitHub Desktop.
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).

127.0.0.1       localhost
89.101.26.166   api.nodenx.com

# 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)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 127.0.1.1

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

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

nslookup www.microsoft.com

Server:		127.0.1.1
Address:	127.0.1.1#53

Non-authoritative answer:
www.microsoft.com	canonical name = toggle.www.ms.akadns.net.
toggle.www.ms.akadns.net	canonical name = g.www.ms.akadns.net.
g.www.ms.akadns.net	canonical name = lb1.www.ms.akadns.net.
Name:	lb1.www.ms.akadns.net
Address: 65.55.57.27

###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

;; QUESTION SECTION:
;.				IN	NS

;; ANSWER SECTION:
.			85901	IN	NS	g.root-servers.net.
.			85901	IN	NS	h.root-servers.net.
.			85901	IN	NS	e.root-servers.net.
.			85901	IN	NS	j.root-servers.net.
.			85901	IN	NS	b.root-servers.net.
.			85901	IN	NS	f.root-servers.net.
.			85901	IN	NS	c.root-servers.net.
.			85901	IN	NS	k.root-servers.net.
.			85901	IN	NS	a.root-servers.net.
.			85901	IN	NS	m.root-servers.net.
.			85901	IN	NS	i.root-servers.net.
.			85901	IN	NS	d.root-servers.net.
.			85901	IN	NS	l.root-servers.net.

;; Query time: 12 msec
;; SERVER: 127.0.1.1#53(127.0.1.1)
;; 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:

www.mysite.com    182.167.122.110
www.mysite.com    182.167.122.111

In this situation, one of the ip addesses at random will be used when someone request the domain name www.mysite.com. 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