Salta al contenuto
Note per Studenti DHCP - Dynamic Host Configuration Report

DHCP - Dynamic Host Configuration

In questa pagina 4

Once an organisation has a block of 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 →, Subnetting, VLSM and SupernettingSubnetting splits an address block into smaller subnets by lengthening the mask (2^s subnets when s bits are borrowed), supernetting does the opposite by shortening the prefix to merge contiguous blocks; design rules for variable-size subnets are power-of-two sizes M with M at least hosts plus 2, prefix 32 minus log2 M, and start addresses divisible by M (largest subnet first), while 2^j blocks of prefix n aggregate into one block of prefix n minus j only if contiguous and aligned.Subnetting, VLSM and Supernetting →), configuring IP and netmask by hand on every host is inefficient and error-prone. Two protocols automate it: BOOTP (deprecated) and DHCP.

BOOTP versus DHCP

BOOTP is static: the server has a table MAC →\to IP; new hosts must be added by hand. DHCP is dynamic: hosts may outnumber the addresses (e.g. Wi-Fi where users connect in turn); the address is given on lease (loan) for a limited time and must be returned or renewed; when addresses run out new requests are refused; it is client-server.

BOOTP DHCP
IP assignment only at computer start also with the OS already running
mapping MAC →\to IP in a fixed table dynamic (lease)
flexibility changing IP needs a reboot renews or reassigns leases itself
mobility stationary connections handles mobile machines

The phases

DHCP uses UDP (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 →): server port 67, client port 68 (an exception to ephemeral client ports). The client at the start has no IP and does not know the server, so it cannot open a TCP connection: it uses broadcast and UDP, with frame destination MAC ff:ff:ff:ff:ff:ff (a link-layer broadcast, distinct from the network-layer broadcast 255.255.255.255255.255.255.255).

  1. Discovery. The client broadcasts DHCPDISCOVER 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. Offer. Each DHCP server replies in broadcast with DHCPOFFER: its identifier, the proposed IP and the lease time. Source: server IP; destination 255.255.255.255255.255.255.255. Several servers may answer.
  3. Request. The client picks the best offer and broadcasts DHCPREQUEST containing the identifier of the chosen server (so the others know they were not chosen). (In the course table the source is the new IP; in practice it is often still 0.0.0.00.0.0.0 until the ACK, with the proposed IP inside the message.)
  4. ACK. The server binds the IP to the host and broadcasts DHCPACK with the configuration: netmask, default gateway (for forwarding to other networks: Forwarding and Routing TablesForwarding moves each packet one hop at a time toward its destination; it is direct when the destination is on a local network (ARP gives its MAC) and indirect otherwise (the packet goes to the next hop or default gateway given by the routing table). With netmasks, delivery is direct on interface x if the destination AND the mask equals the interface address AND the mask; otherwise the table is scanned from the longest mask (longest prefix match) and the default route 0.0.0.0/0 always matches; route aggregation shortens tables.Forwarding and Routing Tables →), DNS server (DNS - Domain Name SystemDNS translates names such as www.amazon.com into IP addresses; it is a distributed hierarchical database (an inverted tree of up to 128 levels, with 13 root servers and domains registered through ICANN-accredited registrars), each ISP has a local DNS whose address the host gets from DHCP, the host asks it (usually over UDP) and it queries root, top-level and organisation servers, every server caches what it learns marking answers as non-authoritative until the TTL expires, records are (name, type, value, class, TTL), with NAT the DNS must return the public address, and there are four types of attack including cache poisoning.DNS - Domain Name System →).
  5. Release. When the address is no longer needed the client sends DHCPRELEASE in unicast to the server; 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 IP and lease
DHCPREQUEST client to server new 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; IP, netmask, gateway, DNS
DHCPRELEASE client to server client IP server IP frees the address

Example. A laptop joins Wi-Fi with block 192.168.1.0/24192.168.1.0/24, DHCP server 192.168.1.1192.168.1.1 and pool .100.100-.200.200 (101 addresses). 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; REQUEST; 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 RELEASE returns .123.123 to the pool: more than 101 devices can be served provided they are not all connected together.

Client state machine and lease renewal

state event message sent next state
Initializing boot DHCPDISCOVER Selecting
Selecting one or more offers arrive, client chooses DHCPREQUEST Requesting
Requesting DHCPACK none Bound
Bound 50% of the lease elapsed DHCPREQUEST (to the original server) Renewing
Renewing DHCPACK none Bound (new lease)
Renewing no answer by 87.5% of the lease DHCPREQUEST (broadcast, any server) Rebinding
Rebinding DHCPACK none Bound
Rebinding lease expired or DHCPNACK none Initializing
Bound client deletes lease DHCPRELEASE Initializing

Example. A 24-hour lease: renewal attempt at 0.5⋅24=120.5\cdot24=12 h, rebinding at 0.875⋅24=210.875\cdot24=21 h, expiry at 24 h (restart from DISCOVER). For a 1-hour lease: 30 min and 52.552.5 min.

How many addresses are needed. If devices arrive at rate λ\lambda and each keeps the address for mean time TT, the mean number of occupied addresses is N=λTN=\lambda T (Little's formula). 120 devices per hour, each staying 2 hours: N=240N=240; a /24 pool of 254 leaves only 14 spare, so peaks would be refused. A shorter lease frees addresses sooner but costs more renewal messages.

Client and server on different networks

A limited broadcast does not cross routers. A relay agent on the client's router receives the broadcast and forwards it by unicast to the DHCP server, then carries the reply back. Addresses distributed by DHCP are often private (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 →).

Versione ripasso

Teoria collegata