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 <- groupsignet.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).
- A host sends its DNS requests to the local DNS, which acts as a proxy and forwards them into the hierarchy.
- The local DNS address must be known to all local hosts: they get it from DHCP - Dynamic Host ConfigurationBOOTP (obsolete) statically maps MAC addresses to IP addresses, while DHCP assigns addresses dynamically on lease, even after the operating system has started; the client-server dialogue runs over UDP (server port 67, client port 68) with DHCPDISCOVER, DHCPOFFER, DHCPREQUEST and DHCPACK (plus DHCPRELEASE), and the ACK delivers IP address, netmask, default gateway and DNS server, with lease renewal at 50 percent and rebinding at 87.5 percent of the lease.DHCP - Dynamic Host Configuration → together with netmask and default gateway.
- Usually UDP is used: request and reply are very short (UDP - User Datagram ProtocolUDP is the connectionless, unreliable transport protocol that adds to IP only process-to-process communication through ports and an optional checksum; its header is 8 bytes (source port, destination port, length, checksum), the checksum covers a pseudo-header (IP addresses, protocol 17, length), the UDP header and the data as a one's complement sum (0 means not computed and a computed 0 is sent as 0xFFFF), and UDP has no connection setup, sequence numbers, flow, error or congestion control, which makes it suitable for short messages (DNS, DHCP, RIP, SNMP) and real-time applications.UDP - User Datagram Protocol →).
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:
- The resolver asks the local DNS.
- If unknown, the local DNS asks a root server (whose address it knows).
- The root points to the server of the top-level domain (
com). - That server points to the DNS of McGraw-Hill.
- 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 addressFormula (resolution time with empty cache). Each question-answer pair costs one RTT with its partner (DNS messages are tiny, so RTT ): . With a fraction of requests answered from the local DNS cache, .
Example. RTTs: host-local 5 ms, local-root 30 ms, local-com 25 ms, local-company DNS 40 ms. ms. If the company DNS address is cached, root and com are skipped: ms; if the answer itself is cached: 5 ms. With : ms (a weighted mean, ).
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: 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.80For 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:
- Compromised machines: an attacker modifies a host's DNS cache directly.
- User's machine: the attacker sends a spoofed answer to a DNS request.
- 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.
- 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 ( values) and arrive before the real answer. Each false answer succeeds with probability ; with independent false answers gives about , about , about . Modern resolvers also randomise the UDP source port, adding about 16 bits: probability per attempt about , so roughly 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
- Translates names to IP addresses; distributed, hierarchical database: inverted tree, root level 0, at most 128 levels, labels at most 63 characters, name at most 255; read right to left (
signet.dei.unipd.it). 13 root servers; domains registered through ICANN-accredited registrars. - Each ISP has a local DNS; its address comes from DHCP (DHCP - Dynamic Host ConfigurationBOOTP (obsolete) statically maps MAC addresses to IP addresses, while DHCP assigns addresses dynamically on lease, even after the operating system has started; the client-server dialogue runs over UDP (server port 67, client port 68) with DHCPDISCOVER, DHCPOFFER, DHCPREQUEST and DHCPACK (plus DHCPRELEASE), and the ACK delivers IP address, netmask, default gateway and DNS server, with lease renewal at 50 percent and rebinding at 87.5 percent of the lease.DHCP - Dynamic Host Configuration →); queries usually over UDP port 53 (UDP - User Datagram ProtocolUDP is the connectionless, unreliable transport protocol that adds to IP only process-to-process communication through ports and an optional checksum; its header is 8 bytes (source port, destination port, length, checksum), the checksum covers a pseudo-header (IP addresses, protocol 17, length), the UDP header and the data as a one's complement sum (0 means not computed and a computed 0 is sent as 0xFFFF), and UDP has no connection setup, sequence numbers, flow, error or congestion control, which makes it suitable for short messages (DNS, DHCP, RIP, SNMP) and real-time applications.UDP - User Datagram Protocol →). Resolver asks the local DNS, which asks root, TLD, authoritative server (iterative; recursive = server finds the final answer).
- Empty cache: ( ms); with cache fraction : (: ms).
- Cache and TTL: cached answers are non-authoritative; entries expire after TTL; changes invisible until then (lower TTL before migrations).
- Record: (name, type, value, class, TTL); types A, AAAA, NS, CNAME, MX (preference, lowest wins; 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.
- DNS and NAT: the DNS must return the public address (: 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 →).
- Attacks: compromised host cache, spoofed answer to the user, local cache poisoning (guess the 16-bit ID: ; randomised source port adds about 16 bits), malicious DNS server.
- Typical errors: one RTT instead of four; confusing local DNS with an authoritative one; thinking changes are immediate.