online posts 15
networking 101, part 2: hands on

task 3.2 · chapter 3 of 3: other networks · 30 min

Names for addresses

objective

See where the laptop’s DNS server came from, ask it for names with dig and nslookup, open web by name, then give the printer a name of its own.

you edit, in the labYour answerslab/dns/lab.hosts

in the lab app: Your answers, under the guide. Check task saves them

given
Lessons used4.1 DHCP (the DNS server is one of the four things it lends), 1.2 the OSI model, 5.1 ports (DNS is UDP port 53)
Log inclick laptop on the Topology tab
Your answersunder the guide, in the lab app
The DNS server's nameslab/dns/lab.hosts, in the same box (pick it with the switcher above the box): one line per name, address first. dns re-reads it as soon as it’s saved
new to this? step by stepbeginner
  1. Click laptop on the Topology tab. In the laptop tab: cat /etc/resolv.conf, dig web.lab, nslookup web.lab and curl web.lab.
  2. Write the DNS server and web’s address in Your answers, under the guide.
  3. Challenge: dig printer.lab finds nothing. Add a line to lab/dns/lab.hosts (the switcher above the box) so it does.
  4. Check task 3.2, under the guide.

more in meet the lab

1 explain

The internet’s phone book

Names are for people

You don’t remember your friends’ phone numbers; you remember their names, and your phone looks the number up. Computers are the other way round: to send anything, they need the IP address. But people would much rather type networkdoodles.com than a string of numbers.

DNS, the Domain Name System, joins the two. A DNS server is a computer that answers one question, over and over: what’s the IP address for this name? Your computer asks before it sends anything to a name.

in one sentence DNS turns a name into an IP address, so people can use names and computers can use numbers.

Where the laptop gets its DNS server

You’ve already seen it. In task 1.2, DHCP lent the laptop four things, and one was a DNS server: 192.168.2.53. The laptop wrote it in /etc/resolv.conf. Every program on the laptop that needs a name looked up reads that file to know who to ask.

The same file has search lab. It means: if someone types a short name with no dot in it, like web, try web.lab too. That’s why you can type the short name inside a network.

in one sentence The DNS server’s address comes from DHCP and lives in /etc/resolv.conf.

Records

A DNS server keeps a list of names and what goes with them. Each entry is a record. The kind that holds an IPv4 address is an A record (A for address). This lab’s DNS server, dns, reads its A records from one plain file: lab/dns/lab.hosts. In this task you can open it in the box under the guide.

192.168.2.10  web.lab
192.168.2.53  dns.lab
192.168.1.1   r1.lab

On the internet, DNS servers have millions of names, and they ask each other when they don’t know one. This one only knows the names in that file, and it never asks anyone else: the lab has no internet.

Two tools that ask

CommandWhat it’s good for
digshows the whole question and answer, every part labelled. Engineers use it to see exactly what a DNS server said
nslookupa shorter answer. It’s also on Windows and Mac, so it’s the one you can try on any computer

Both ask the DNS server directly. Other programs, like ping and curl, look the name up quietly first and then use the address.

2 show

Reading dig

laptop:~# dig web.lab
...
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 46697
...
;; QUESTION SECTION:
;web.lab.			IN	A

;; ANSWER SECTION:
web.lab.		60	IN	A	192.168.2.10

;; Query time: 3 msec
;; SERVER: 192.168.2.53#53(192.168.2.53) (UDP)
PartWhat it means
status: NOERRORit found the name. NXDOMAIN means no such name (non-existent domain)
QUESTION SECTIONwhat the laptop asked: the A record for web.lab
ANSWER SECTIONthe answer: web.lab is 192.168.2.10
60how many seconds the laptop may remember the answer before asking again (the time to live, like a lease)
SERVER: 192.168.2.53#53who answered: the DNS server, on port 53, the DNS port
(UDP)the question went in a UDP message: a single postcard, no conversation first

The port and UDP are layer 4, from lesson 1.2 and lesson 5.1: the address gets the question to the dns host, and port 53 gets it to the DNS program on it.

3 follow along

Ask for a name

  1. Log in to the laptop: click laptop on the Topology tab. In the laptop tab, see who it asks:

    run in the laptop tab
    cat /etc/resolv.conf
    

    nameserver 192.168.2.53 and search lab.

  2. Ask for web’s address, both ways:

    run in the laptop tab
    dig web.lab
    nslookup web.lab
    

    Find the answer in each. nslookup prints the server it asked (Server: 192.168.2.53), then the name and its address.

  3. Use the name. curl fetches a web page and prints what’s in it:

    run in the laptop tab
    curl web.lab
    ping -c 2 web
    

    curl prints Hello from web.lab, 192.168.2.10: the laptop looked up the name, then opened the page at that address. ping web works with the short name because of search lab, and ping prints the full name it found.

  4. Ask for a name that doesn’t exist:

    run in the laptop tab
    dig printer.lab
    

    status: NXDOMAIN, and no answer section. The DNS server has never heard of it.

  5. Fill in Your answers, under the guide:

    editYour answersunder the guide
    The laptop's DNS server: 192.168.2.53
    web.lab's address, from dig: 192.168.2.10
    

in one sentence dig and nslookup ask the DNS server directly; curl and ping look the name up and then use the address.

4 challenge

Name the printer

Make dig printer.lab on the laptop answer with the printer’s address, so that ping -c 2 printer.lab works. Then click Check task 3.2, under the guide.

hint

The names live in lab/dns/lab.hosts. Pick it with the small switcher above the box under the guide. You don’t log in to the dns host at all.

hint

Each line is an address, some spaces, then the name. The printer’s address is the one you found in task 1.1.

show the solutionlab/dns/lab.hosts

or let the lab do it: Solve it for me, next to Check task, does the task and fills in the answers, printing every step

192.168.1.20  printer.lab

Add that line, then click away from the box (or press Ctrl+S) to save it. The DNS server notices the file changed and reads it again by itself, within a second or two. Then, in the laptop tab:

laptop:~# dig +short printer.lab
192.168.1.20
laptop:~# ping -c 2 printer
PING printer.lab (192.168.1.20) 56(84) bytes of data.
64 bytes from printer.lab (192.168.1.20): icmp_seq=1 ttl=64 time=0.402 ms

(+short asks dig for just the answer.) Notice the printer’s ttl=64: it’s on the laptop’s own network, so no router took 1 off. Compare web’s ttl=62 in task 2.2.

The name gets the laptop to web’s address. Task 3.3 looks at the last step: which program on web answers, and on which port.

5 check: run it, then prove it

Check task 3.2 under the guide, in the lab app

when it's right, you'll see

╭─ task 3.2 · names for addresses
│  ✓ the laptop's DNS server (follow along): 192.168.2.53
│  ✓ web.lab's address, from dig (follow along): 192.168.2.10
│  ✓ dig printer.lab answers 192.168.1.20 (challenge): 192.168.1.20
│  ✓ ping printer.lab works from the laptop (challenge)
╰─ 4/4 checks passed  verified