Salta al contenuto
Note per Studenti Network Services - DHCP and DNS Configuration Report

Network Services - DHCP and DNS Configuration

In questa pagina 4

See also: 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 → for the protocol in depth.

The program lists DHCP, DNS and firewall among the network elements configured in the laboratory (Emulating Networks with KatharàKatharà is a network emulator where every device is a Docker container joined to virtual collision domains; a lab is a folder with lab.conf (topology), one .startup file per machine and optional per-device folders; machines are configured with ifconfig, tested with ping and observed with tcpdump and Wireshark.Emulating Networks with Katharà →); the firewall part is in Firewall Configuration with iptables in KatharàLab 6 configures a packet-filter firewall on Linux with iptables (NetFilter): tables filter, nat, mangle and raw hold chains of rules, the first matching rule wins, otherwise the default policy applies; three experiences cover a firewall protecting a host (INPUT with DROP policy plus loopback, ping, SSH and ESTABLISHED,RELATED), a firewall on a LAN router (FORWARD) and NAT with SNAT and DNAT.Firewall Configuration with iptables in Katharà →. This note collects what must be known to configure and test the other two services. In the lab a DNS server is placed on a machine and queried with nslookup.

DHCP

Assigning address and netmask by hand to each host is inefficient and error-prone. BOOTP (deprecated) keeps a fixed table MAC →\to IP, assigns the address only at boot and new hosts must be added by hand. DHCP (Dynamic Host Configuration Protocol) is dynamic: the address is lent (lease) for a limited time, also when the operating system is already running; hosts can outnumber the addresses (e.g. Wi-Fi); when all addresses are assigned, new requests are refused.

Protocol phases

DHCP uses UDP: server port 67, client port 68. Broadcast and UDP are needed because the client has no IP address and does not know the server, so it cannot open a TCP connection; the frame carrying the DISCOVER has destination MAC ff:ff:ff:ff:ff:ff. The two broadcasts are on different layers: 255.255.255.255255.255.255.255 for the network, all-ones MAC for the link.

  1. DHCPDISCOVER: the client broadcasts a message with its MAC and a random transaction ID; source IP 0.0.0.00.0.0.0, destination 255.255.255.255255.255.255.255.
  2. DHCPOFFER: each DHCP server answers with its identifier, the proposed IP address and the lease time.
  3. DHCPREQUEST: the client accepts one offer, broadcasting a message containing the identifier of the chosen server (so the others know they were not chosen).
  4. DHCPACK: the server assigns the address and sends everything needed to configure the interface: netmask, default gateway, DNS server.
  5. DHCPRELEASE: when the address is no longer needed, the client sends it in unicast to the chosen server and the address returns to the pool.
message direction source IP destination IP purpose
DHCPDISCOVER client →\to server 0.0.0.00.0.0.0 255.255.255.255255.255.255.255 looking for a server
DHCPOFFER server →\to client server IP 255.255.255.255255.255.255.255 proposes an IP and a lease
DHCPREQUEST client →\to server assigned IP 255.255.255.255255.255.255.255 accepts the offer of server X
DHCPACK server →\to client server IP 255.255.255.255255.255.255.255 confirms, gives IP, netmask, gateway, DNS
DHCPRELEASE client →\to server client IP server IP releases the address

Example. A laptop joins a Wi-Fi network using 192.168.1.0/24192.168.1.0/24 with a DHCP server at 192.168.1.1192.168.1.1 and a pool from .100.100 to .200.200 (101 addresses). It sends DISCOVER (0.0.0.0→255.255.255.2550.0.0.0\to255.255.255.255, UDP 68→6768\to67); the server offers 192.168.1.123192.168.1.123 with a one-hour lease; the laptop sends REQUEST; the server sends ACK with netmask 255.255.255.0255.255.255.0, gateway 192.168.1.1192.168.1.1 and a DNS server. At the end the laptop sends RELEASE and .123.123 is available again.

Client state machine and lease renewal

state event message sent next state
Initializing boot DHCPDISCOVER Selecting
Selecting offer(s) arrive DHCPREQUEST Requesting
Requesting DHCPACK none Bound
Bound 50%50\% of the lease elapsed DHCPREQUEST (to the server that gave the address) Renewing
Renewing DHCPACK: new lease none Bound
Renewing no answer by 87.5%87.5\% DHCPREQUEST (any server, broadcast) Rebinding
Rebinding DHCPACK none Bound
Rebinding lease expired or DHCPNACK none Initializing
Bound the client deletes the lease DHCPRELEASE Initializing

Example. Lease of 24 hours: renewal at 0.5⋅24=120.5\cdot24=12 h, rebinding at 0.875⋅24=210.875\cdot24=21 h, at 24 h the client restarts from DISCOVER. With a 1-hour lease the thresholds are 30 min and 52.552.5 min.

Pool size. If devices arrive at rate λ\lambda and each keeps the address for a mean time TT, the mean number of occupied addresses is N=λTN=\lambda T (Little's formula). Example. 120120 devices per hour, 22 hours each: N=240N=240; a /24/24 pool has 254254 assignable addresses, a margin of only 1414.

Different networks. A limited broadcast does not cross routers: a relay agent on the router forwards the client's broadcast in unicast to a DHCP server in another network. The DHCPACK also tells the host its default gateway, needed for indirect forwarding.

DNS

The DNS (Domain Name System) translates names into IP addresses. It is distributed (a central directory would be too large and a single point of failure) and hierarchical: an inverted tree with the root at the top, at most 128128 levels. Names read right to left: signet.dei.unipd.it is group signet (level 44) inside dei, unipd and it. A label is at most 6363 characters, the whole name at most 255255. A domain is the subtree starting at a node. There are 1313 root server addresses; new domains are registered with an ICANN-accredited registrar.

Local DNS and resolver. Each ISP has a local name server acting as a proxy. The host (resolver) sends the request to it, usually over UDP. Its address reaches the host through DHCP (in the DHCPACK). Iterative: the server answers "ask this other server"; recursive: the server finds the final answer. Normally the recursive part is between host and local DNS, which queries the others one at a time.

Resolution chain (empty cache; host some.anet.com looks up engineering.mcgraw-hill.com):

step  from -> to                          content
 1    host -> local DNS                   engineering.mcgraw-hill.com ?
 2    local DNS -> root                   engineering.mcgraw-hill.com ?
 3    root -> local DNS                   ask the server of "com"
 4    local DNS -> "com" server           engineering.mcgraw-hill.com ?
 5    "com" server -> local DNS           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

Resolution time. 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 answered from the local cache, Tˉ=h RTThost-local+(1−h) T\bar T=h\,\text{RTT}_{\text{host-local}}+(1-h)\,T. Example. RTTs 55, 3030, 2525, 4040 ms: T=100T=100 ms; with the company DNS cached, 5+40=455+40=45 ms; answer cached, 55 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.

Cache and TTL. A server stores every association it learns and marks such answers non-authoritative; an authoritative answer needs the server of the organisation that manages the name. Entries expire after the record's TTL: a change in the zone stays invisible to cached copies until the TTL ends (TTL 36003600 s means up to 6060 minutes; before a migration the TTL is lowered, e.g. to 300300 s).

Records. Each item is a resource record (name, type, value, class, TTL); class IN is Internet. Types: A (IPv4 address), AAAA (IPv6), NS (authoritative DNS server of the domain), CNAME (alias), MX (mail server), PTR (name for an address).

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

nslookup.

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

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

An authoritative answer is obtained by querying an authoritative server directly: nslookup www.example.it ns1.example.it (the second argument is the server to use).

DNS and NAT. A server with a private address (10.0.0.207) must be reachable by name from outside: the intranet DNS knows myserver.com as 10.0.0.207, the NAT converts it into the public address 194.54.21.6, and the DNS reply to the client carries the public address.

Attacks on the DNS

A false answer sends the user to a wrong site (Network Security - Threats and AttacksA threat is any event that can violate a security goal (confidentiality, integrity, availability, accountability, privacy) and its realisation is an attack; security services and mechanisms counter the threats, and sniffing and spoofing underlie the main network attacks, DoS and man-in-the-middle.Network Security - Threats and Attacks →). Four types: compromised machines (the attacker modifies the host's DNS cache); a spoofed answer sent to a request of the user's machine; local DNS cache poisoning (false answers to the local DNS are cached and users go to a fake site for the whole TTL); malicious DNS servers (fraudulent data in the optional fields of the reply).

How easy is it to guess? The false answer must carry the same 1616-bit transaction identifier (216=65 5362^{16}=65\,536 values) and arrive before the true one. With nn independent false answers, P(success)=1−(1−2−16)n≈n/65 536P(\text{success})=1-\left(1-2^{-16}\right)^{n}\approx n/65\,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 (about 1616 more bits): the probability per attempt falls to about 2−322^{-32}.

Common mistakes

  • Saying the DNS only translates names to IP: it also has MX, NS, PTR, CNAME.
  • Confusing the local DNS (cache, asks on behalf of the host) with an authoritative server.
  • Thinking a record change is visible immediately: it stays cached until the TTL ends.
  • Forgetting that the host must already know the DNS address (it comes from DHCP).
  • Counting one RTT for a full resolution: with an empty cache there are four.
  • Using TCP ideas for DHCP: the client has no IP yet, so it uses UDP broadcast on ports 68 and 67.

Versione ripasso

DHCP

  • BOOTP vs DHCP. BOOTP (deprecated): fixed table MAC →\to IP, only at boot. DHCP: dynamic, lease, also with the OS running, more hosts than addresses, requests refused when addresses end.
  • Transport. UDP, server port 6767, client port 6868; DISCOVER with MAC ff:ff:ff:ff:ff:ff, IP 0.0.0.0→255.255.255.2550.0.0.0\to255.255.255.255 (client has no IP and does not know the server).
  • Phases. DISCOVER (broadcast, transaction ID); OFFER (server id, proposed IP, lease); REQUEST (accepts one server); ACK (IP, netmask, default gateway, DNS server); RELEASE (unicast, address returns to the pool).
  • Example. Pool .100-.200 of 192.168.1.0/24192.168.1.0/24, server 192.168.1.1192.168.1.1: offer 192.168.1.123192.168.1.123 with 1-hour lease, ACK with netmask 255.255.255.0255.255.255.0 and gateway 192.168.1.1192.168.1.1.
  • States. Initializing →\to DISCOVER →\to Selecting →\to REQUEST →\to Requesting →\to ACK →\to Bound. At 50%50\% of the lease: Renewing (REQUEST to the same server); no answer by 87.5%87.5\%: Rebinding (REQUEST in broadcast); lease expired or NACK: restart from DISCOVER. Lease 24 h: 12 h and 21 h; lease 1 h: 30 min and 52.552.5 min.
  • Pool size. N=λTN=\lambda T (Little): 120 devices/h, 2 h each, N=240N=240 against 254254 addresses of a /24/24.
  • Different networks. Limited broadcast does not cross routers: a relay agent forwards in unicast.

DNS

  • Purpose. Names to IP. Distributed and hierarchical: inverted tree, root at top, at most 128128 levels, labels ≤63\le63 characters, name ≤255\le255; 1313 root server addresses; registrar accredited by ICANN. signet.dei.unipd.it reads right to left.
  • Local DNS. Proxy of the ISP, address learned via DHCP; resolver sends the request, usually over UDP. Iterative vs recursive (recursive between host and local DNS).
  • Chain with empty cache. host →\to local DNS →\to root →\to TLD server →\to authoritative DNS, each answering with the next server; T=T= sum of four RTTs. RTTs 5,30,25,405,30,25,40 ms: 100100 ms; company DNS cached: 4545 ms; answer cached: 55 ms; h=0.9h=0.9: Tˉ=14.5\bar T=14.5 ms.
  • Cache and TTL. Non-authoritative answers come from the cache; entries expire after the TTL (3600 s means up to 60 min of stale data; lower the TTL before a migration).
  • Records. (name, type, value, class, TTL), class IN. A, AAAA, NS, CNAME, MX (lowest preference wins), PTR. www.example.it. 3600 IN A 192.0.2.80.
  • nslookup. nslookup www.example.it shows server, Non-authoritative answer, name, address; nslookup www.example.it ns1.example.it queries an authoritative server directly.
  • DNS and NAT. The reply to an external client carries the public address (10.0.0.207 →\to 194.54.21.6).
  • Attacks. Compromised host; spoofed answer; local cache poisoning (fake site for the whole TTL); malicious DNS server. Transaction ID 1616 bits: P≈n/65 536P\approx n/65\,536 (1.5%1.5\% at n=1000n=1000, 63%63\% at 65 53665\,536); random source port makes it about 2−322^{-32} per attempt (Network Security - Threats and AttacksA threat is any event that can violate a security goal (confidentiality, integrity, availability, accountability, privacy) and its realisation is an attack; security services and mechanisms counter the threats, and sniffing and spoofing underlie the main network attacks, DoS and man-in-the-middle.Network Security - Threats and Attacks →).
  • Mistakes: DNS also has MX, NS, PTR, CNAME; local DNS vs authoritative; changes cached until TTL; DNS address comes from DHCP; four RTTs, not one; DHCP uses UDP broadcast (68 and 67).