Salta al contenuto
Note per Studenti DNS - Domain Name System Report

DNS - Domain Name System

In questa pagina 10

Purpose

TCP/IP identifies hosts by IP address, but people prefer names: 104.106.125.36 or www.amazon.com? The DNS is the application-layer service that translates names to addresses (Network Layer and IPv4 AddressingThe network layer delivers datagrams host to host through routers (encapsulation, routing, forwarding); an IPv4 address is 32 bits split into a network prefix and a host suffix, and modern classless addressing (CIDR) gives a block of 2^(32-n) addresses from a.b.c.d/n, with network and broadcast addresses computed through the netmask.Network Layer and IPv4 Addressing →). It is not called by the user: the browser, mail client or ping ask it before opening a connection.

A single central directory would be too big for one machine and, if it failed, the whole network would collapse. DNS is therefore distributed: information is spread on many computers, and a host contacts the closest one that has the needed mapping.

Hierarchical name space

Names must be unique, as are the addresses they map to. To guarantee that without a single authority the name space is hierarchical, an inverted tree with the root at the top, at most 128 levels (0 for the root to 127).

                       .  (root, level 0)
          ┌────────────┼────────────┐
         it           com          org        <- top-level domains
          │
        unipd                                 <- organisation
          │
         dei                                  <- department
          │
        signet                                <- group

signet.dei.unipd.it is read right to left: it the geographic zone, unipd the organisation, dei the department, signet the group. Each label is at most 63 characters, the whole name at most 255.

Definition. A domain name is the sequence of labels from a tree node up to the root, separated by dots. A domain is the subtree starting at that node.

signet.dei.unipd.it has 4 labels; signet is at level 4 and belongs to the domains dei.unipd.it, unipd.it and it.

DNS servers and registrars

Information is distributed over DNS servers: worldwide there are 13 root servers (published addresses; the real machines are many more). A new domain is added through a registrar, a commercial entity accredited by ICANN.

Local DNS and resolver

There are only 13 root servers but every ISP has a local DNS server (default name server).

Definition (resolution). Translating a name into an address is name-address resolution. The host that needs it is the resolver; it asks the closest server. If the server has the information it answers; otherwise it refers the resolver to other servers or asks them itself.

These are the two query modes: iterative (the server answers "I do not know, ask this other one") and recursive (the server finds the final answer for you).

A full example

A program on some.anet.com needs the IP of engineering.mcgraw-hill.com:

  1. The resolver asks the local DNS.
  2. If unknown, the local DNS asks a root server (whose address it knows).
  3. The root points to the server of the top-level domain (com).
  4. That server points to the DNS of McGraw-Hill.
  5. That DNS knows the address and returns it; it goes back to the local DNS and to the host.
step  from -> to                         content
 1    host -> local DNS                  engineering.mcgraw-hill.com ?
 2    local DNS -> root                  engineering.mcgraw-hill.com ?
 3    root -> local DNS                  don't know: ask the "com" server
 4    local DNS -> "com" server          engineering.mcgraw-hill.com ?
 5    "com" server -> local DNS          don't know: ask the DNS of mcgraw-hill.com
 6    local DNS -> McGraw-Hill DNS       engineering.mcgraw-hill.com ?
 7    McGraw-Hill DNS -> local DNS       the requested IP address
 8    local DNS -> host                  the requested IP address

Formula (resolution time with empty cache). Each question-answer pair costs one RTT with its partner (DNS messages are tiny, so RTT ≈2τp\approx2\tau_p): T=RTThost-local+RTTroot+RTTTLD+RTTauthoritativeT=\text{RTT}_{\text{host-local}}+\text{RTT}_{\text{root}}+\text{RTT}_{\text{TLD}}+\text{RTT}_{\text{authoritative}}. With a fraction hh of requests answered from the local DNS cache, Tˉ=h RTThost-local+(1−h) T\bar T=h\,\text{RTT}_{\text{host-local}}+(1-h)\,T.

Example. RTTs: host-local 5 ms, local-root 30 ms, local-com 25 ms, local-company DNS 40 ms. T=5+30+25+40=100T=5+30+25+40=100 ms. If the company DNS address is cached, root and com are skipped: 5+40=455+40=45 ms; if the answer itself is cached: 5 ms. With h=0.9h=0.9: Tˉ=0.9⋅5+0.1⋅100=14.5\bar T=0.9\cdot5+0.1\cdot100=14.5 ms (a weighted mean, Tˉ=100−95 h\bar T=100-95\,h).

All-recursive variant. If each server forwards the request and answers return along the chain, with RTTs 5 (host-local), 30 (local-root), 20 (root-TLD), 15 (TLD-authoritative) ms: 5+30+20+15=705+30+20+15=70 ms. The load, however, moves to top servers; normally recursion is used between host and local DNS, and the local DNS queries the others iteratively.

Cache and TTL

A server that learns a mapping caches it. The reply from cache is marked non-authoritative; for an authoritative answer one must ask the DNS of the organisation managing the name. Entries expire: each record carries a TTL.

Property. While the TTL has not expired the server answers from cache without asking anyone; at expiry it deletes the entry. A change in the zone stays invisible to caches until the TTL ends.

Example. www.example.it with TTL 3600 s: for an hour all clients of the same local DNS get the answer in one RTT; after an address change the old value may circulate up to 60 minutes, so before a migration the TTL is lowered (e.g. to 300 s).

Record format

Each DNS record has five fields: (name, type, value, class, TTL): name (domain name), type (what the value means), value, class (IN = Internet), TTL.

Common types: A (IPv4 address), AAAA (IPv6 address), NS (authoritative name server of the domain), CNAME (alias), MX (mail server of the domain: E-mail - SMTP, POP3, IMAP and MIMEE-mail is a one-way transaction, so intermediate servers are used: two user agents (UA), push client-server programs (MTA, protocol SMTP, from sender to its server and between servers) and a pull program (MAA, POP3 or IMAP4, from the recipient's server to the recipient); SMTP uses TCP port 25 with commands HELO, MAIL FROM, RCPT TO, DATA, QUIT and three-digit replies (220 ready, 250 ok, 354 start mail input, 221 closing, 421 unavailable) in three phases (opening, transfer, closing), POP3 (port 110) downloads messages one by one after login while IMAP4 (port 143) adds header preview, search, partial download and server-side folders, and MIME turns non-ASCII data into 7-bit ASCII, for example with base64 (3 bytes become 4 characters).E-mail - SMTP, POP3, IMAP and MIME →), PTR (name for an address).

Examples. www.example.it. 3600 IN A 192.0.2.80; example.it. 3600 IN MX 10 mail.example.it. (the 10 is the preference: lowest wins).

nslookup

nslookup www.example.it
Server:   192.168.1.1        <- the local DNS used (address and port 53)
Address:  192.168.1.1#53

Non-authoritative answer:    <- from the cache, not from the authoritative server
Name:     www.example.it
Address:  192.0.2.80

For an authoritative answer ask an authoritative server directly (nslookup www.example.it ns1.example.it).

DNS and NAT

A server with a private address (10.0.0.207) must be reachable by name from an outside client (NAT and Private AddressesPrivate networks (intranets) use TCP/IP with private address blocks (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16) that may be reused by different intranets but are never routed in the public Internet; to reach the Internet an intranet needs an application proxy or NAT, a router that translates private to public addresses using a NAT table and per-session mappings: Basic NAT translates only the IP address one to one, NAPT also translates the port so many sessions share one public IP, and Twice NAT adds DNS support and static mappings so sessions can also start from outside.NAT and Private Addresses →): (1) the client sends a DNS request for myserver.com; (2) the intranet DNS knows 10.0.0.207; (3) the NAT converts it with its table to the public 194.54.21.6; (4) the DNS reply contains the public address, used for all later communication. Without this conversion the client would get an address that is not routable on the Internet.

Attacks on DNS

A false answer sends the user to the wrong site. Four types:

  1. Compromised machines: an attacker modifies a host's DNS cache directly.
  2. User's machine: the attacker sends a spoofed answer to a DNS request.
  3. Local DNS cache poisoning: during recursive or iterative queries the attacker sends false answers to the local DNS, which caches them; all its users are redirected for the whole TTL.
  4. Malicious DNS servers: a malicious server supplies fraudulent information in optional fields of the answer.

How easy is it to guess? The attacker must match the 16-bit transaction identifier (216=65 5362^{16}=65\,536 values) and arrive before the real answer. Each false answer succeeds with probability 2−16≈1.5⋅10−52^{-16}\approx1.5\cdot10^{-5}; with nn independent false answers P(success)=1−(1−2−16)n≈n65 536(n≪65 536).P(\text{success})=1-\left(1-2^{-16}\right)^{n}\approx\frac n{65\,536}\quad(n\ll65\,536). n=1000n=1000 gives about 1.5%1.5\%, n=10 000n=10\,000 about 14%14\%, n=65 536n=65\,536 about 63%63\%. Modern resolvers also randomise the UDP source port, adding about 16 bits: probability per attempt about 2−322^{-32}, so roughly 10910^9 false answers are needed for a 20% success.

Common mistakes

DNS also has MX, NS, PTR, CNAME (not only name to IP); local DNS (cache, asks on behalf of the host) differs from an authoritative server; a record change is not visible until the TTL ends; the local DNS address must already be known (from DHCP); a full resolution with empty cache costs four RTTs, not one.

Versione ripasso

Teoria collegata