Sub topic 2
The domain name hierarchy
This chapter assumes you know what IPv4 and IPv6 addresses are and can run commands in a terminal. It explains how DNS organizes names. The next chapters build on this structure.
Names form a tree
DNS names are not a flat list. They form an inverted tree. A single root sits at the top, and every name is a path from a leaf up to that root. This design lets thousands of independent organizations manage their own names without a central registry having to know about every host.
Labels and fully qualified names
A label is one segment of a name, the text between dots. The name www.example.com has three labels: www, example and com. Each label can be at most 63 bytes long. Labels are compared without regard to case, so Example.COM and example.com are the same name.
A fully qualified domain name (FQDN) names a position in the tree all the way to the root. Written in full, it ends with a dot:
www.example.com.The final dot stands for the root, which has an empty label. Most applications let you leave it off. DNS software treats the name as absolute only when the dot is present. Without it, a resolver may append a search domain first (a later chapter covers this). The whole name can be at most 253 characters in text form.
Read a name from right to left to move from general to specific. com is the broadest part, example is inside it, and www is inside that.
The levels of the tree
| Level | Example | Who manages it |
|---|---|---|
| Root | `.` | Root server operators, coordinated through ICANN and IANA |
| Top-level domain (TLD) | `com`, `org`, `uk` | A registry for each TLD |
| Second-level domain | `example.com` | The organization that registered it |
| Subdomain | `www.example.com` | Whoever runs the parent domain |
TLDs fall into a few groups. Generic TLDs such as com, org and net have no country tie. Country-code TLDs such as uk and de use two-letter codes. Newer generic TLDs, such as dev and app, also exist.
A domain is a name together with everything beneath it. example.com is a domain, and www.example.com is a subdomain of it. A hostname is a name that points to a machine, usually through an address record. A name can be both a domain and a hostname. In the zone file from a later chapter, example.com has its own A record and also has subdomains.
Looking at the top of the tree
You can ask a resolver which servers are responsible for a TLD. The NS record type lists them.
dig +short NS com.The command prints the name servers that handle com. Each name belongs to the registry that operates that TLD. The names are the entry point for every lookup under .com.
Why the tree matters
Each node in the tree can be managed by a different party. The owner of example.com creates www, mail and any other subdomains without asking anyone above them. Owners of the layers above only need to record where the next layer is managed. That handoff is called delegation, and the next chapter covers it.
Exercise
In the name api.shop.example.co.uk., how many labels are there, and which one is the top-level domain?
Show answer
There are five labels: api, shop, example, co and uk. The top-level domain is uk, the rightmost label before the root dot. The trailing dot marks the root and is not counted as a label here.
Exercise
Why does the trailing dot in www.example.com. matter to a resolver?
Show answer
The trailing dot marks the name as fully qualified, meaning it is measured from the root. Without the dot, a resolver may treat the name as relative and append a search domain before looking it up.