About 1 hour
- Lesson - 10 min
- Guided Practice - 10 min
- Independent Practice - 30-40 min
Understanding about DNS is important when it comes to IP address or URL of a website. DNS plays an important role in communicating with a website, like, when we enter "www.google.com", do you know what really happens behind the scenes? Let's find out.
- Participants will have a rudimentary understanding of how DNS works.
- What is DNS?
- First, what is domain name?
- Domain name vs website
- DNS stands for: Domain name system
- DNS is a directory that maps friendly/readable names to IP addresses
- Common metaphors
- Meh: Phone books (so old school)
- Better: Street addresses
- Common metaphors
- First, what is domain name?
- Computer with terminal application
- On your command line, enter
ping google.com
. Let it run for a few seconds, then press control+C. "Does anyone know what ping means?"- Ping: to query another computer on a network to determine whether there is a connection to it.
- The PING command sends packets of information to a specified IP Address and then measures the time it takes to get a response from the specified computer or device.
- Discuss output from
ping google.com
.
- DNS lookup: Act out what happens to the request. Literally have one person deliver a "packet," bouncing from different name servers, like what happens in this video or this comic.
If a browser has a domain name like www.abc.com that it needs an IP address for, it will query these systems in order:
-
Its own Operating System. If the domain name's corresponding IP address isn't on record, then it will query...
-
The name server (DNS server) it is set up to use. This is the recursive name server shown above. The name server doesn’t know the IP address for www.abc.com, so it will start the following chain of queries before it can report back the IP address to your computer
-
Query the Internet root servers to get the name servers for the .com TLD.
-
Query the .com TLD name servers to get the authoritative name servers for abc.com.
-
Query the authoritative name servers for abc.com to finally get the IP address for the host www.abc.com, then return that IP address to your computer.
-
-
Done! Now that your computer has the IP address for www.abc.com, it can access that host.
(photo and steps are from https://royal.pingdom.com/2009/06/08/a-visual-explanation-of-how-dns-lookups-work/)
Let's setup a DNS server locally, it's easy!
- Enter
sudo vim /etc/hosts
## # Host Database # # localhost is used to configure the loopback interface # when the system is booting. Do not change this entry. ## 127.0.0.1 localhost 255.255.255.255 broadcasthost ::1 localhost fe80::1%lo0 localhost
- discuss output of: ipaddress domain
## # Host Database # # localhost is used to configure the loopback interface # when the system is booting. Do not change this entry. ## 127.0.0.1 localhost 255.255.255.255 broadcasthost ::1 localhost fe80::1%lo0 localhost
- Edit hosts file to point '127.0.0.1' to 'whatever.whodat'
Example:
127.0.0.1 myblog.dev
- ping whatever.whodat
Expected output:
$ ping myblog.dev PING myblog.dev (127.0.0.1): 56 data bytes 64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.041 ms 64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.089 ms 64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.047 ms
-
Spend 20 minutes watching this video and reading this comic. Take notes if you think it will help.
-
Find a partner. Without any resources to look at, try to explain the process after your partner asks you, "What happens when you enter google.com in your browser search bar?"
- Run a local domain name server on your computer that can resolve all requests for a given top level domain to the localhost, and forward everything else to the Internet as normal.