{"canonical_url":"https://engineer.company/glossary/dhcp/","content_markdown":"# DHCP\n\n## What it is\n\nDHCP, the Dynamic Host Configuration Protocol, is how a device that has just\njoined a network finds out where it stands on that network. A laptop that\nconnects to a Wi-Fi network knows its own hardware address and little else. DHCP\ngives it an IP address, the subnet mask, the router to send traffic through and\nthe DNS servers to ask, without anybody typing them in. The protocol is defined\nin RFC 2131, published in March 1997, whose abstract presents it as a way to\nhand configuration information to the hosts of a TCP/IP network. It grew out of\nthe older Bootstrap Protocol, BOOTP, and its main addition was the automatic\nallocation of addresses that can be reused.\n\nRFC 2131 names three ways to hand out an address. In automatic allocation the\nclient gets a permanent address. In dynamic allocation it gets one for a limited\nperiod, or until it gives the address back. In manual allocation the network\nadministrator chooses the address and DHCP merely delivers it. Of the three,\nonly dynamic allocation lets an address go back to the pool on its own once its\nholder no longer needs it, and it is the mechanism the rest of this article is\nabout.\n\nThe period for which an address is lent is called a lease. The client can extend\nit, can hand the address back early, and can even ask for an infinite lease; the\nRFC notes that a server may still prefer long but finite leases, so that it\neventually notices a client that has been retired. Behind the server sits what\nthe RFC calls persistent storage: one entry per client, keyed by an identifier,\nholding the parameters that client was given.\n\nDHCP runs over UDP. Clients send to server port 67 and servers answer on client\nport 68. The options a server can send, from the subnet mask to the lease time,\nare specified separately, in RFC 2132. IPv6 has a protocol of its own, DHCPv6,\nnow specified in RFC 9915, an Internet Standard from January 2026 that replaced\nRFC 8415. It uses other ports, 546 for clients and 547 for servers and relay\nagents, and it can run either in place of or alongside stateless address\nautoconfiguration (SLAAC). RFC 9915 itself calls the IPv4 protocol DHCPv4 when\nit needs to tell the two apart, and it records the IETF consensus that IPv4\nconfiguration should travel over DHCPv4 rather than DHCPv6.\n\n## Why it matters\n\nEvery device on a network needs the same handful of settings, and one wrong\nvalue is enough to cut it off: a mask that does not match the subnet, a router\naddress that belongs to someone else, a DNS server that was switched off last\nyear. Without DHCP each of those values has to be typed into each device and\nkept right whenever anything changes. With DHCP they live in one place, and\nchanging the DNS server for a whole office becomes a change to the server's\nconfiguration rather than a walk round the building.\n\nThe lease is what makes the protocol scale. Because dynamic allocation lends\naddresses for a fixed time, a pool can serve more devices over a week than it\nhas addresses, as long as they are not all present at once. RFC 2131 says\ndynamic allocation is particularly useful for clients that are connected only\ntemporarily, and for sharing a limited pool among clients that do not need\npermanent addresses. And because a client may simply vanish, the protocol does\nnot rely on goodbyes: the RFC states that correct operation does not depend on\nthe client sending a release message. An address comes back when its lease runs\nout, whether or not its holder ever says so.\n\nThat makes the lease length a real design decision, not a default to leave\nalone. A long lease keeps the addresses of departed devices locked up for\nlonger. A short one means more renewal traffic, and less time to fix a server\nthat has stopped answering, because a client whose lease expires before it\nreaches a server must stop using its address.\n\nDHCP is also a question of trust. The first answer a device accepts tells it\nwhich router carries all its traffic and which DNS server translates every name\nit looks up, so whoever controls that answer controls where the device goes. RFC\n2131 is plain about this: its security section calls the protocol, in its\ncurrent form, \"quite insecure\", because it is built directly on UDP and IP, and\nbecause the machines it was meant to serve are hard to equip with passwords or\nkeys. The same section notes that unauthorised servers are easy to set up and\ncan hand out wrong or duplicate addresses, spoofed routers and spoofed name\nservers. The protection has to come from the network around the protocol, not\nfrom the protocol.\n\n## What it looks like in practice\n\nTake a laptop with the hardware address 00-00-5E-00-53-2A joining an office\nsubnet, 192.0.2.0/24, where one machine at 192.0.2.1 is both the router and the\nDHCP server. The laptop starts out without an address, so its first message\nleaves with the source address 0.0.0.0 and is broadcast to everyone on the link.\nFour messages later it is configured:\n\n```text\nlaptop 00-00-5E-00-53-2A                        server 192.0.2.1\n\n1  DHCPDISCOVER  0.0.0.0 -\u003e 255.255.255.255, server port 67\n                 is there a server here?\n2  DHCPOFFER     offers 192.0.2.50 for 86400 s, server id 192.0.2.1\n3  DHCPREQUEST   broadcast: server id 192.0.2.1, requested 192.0.2.50\n4  DHCPACK       192.0.2.50 is the laptop's for 86400 s\n```\n\nAny number of servers may answer the discover, and the client may wait to\ncollect more than one offer. It then chooses one and broadcasts a request that\nnames the chosen server in the server identifier option and asks for the address\nthat server offered. Every other server that sees the broadcast takes it as a\nrefusal of its own offer. The chosen server commits the binding to its storage\nand confirms with an acknowledgement.\n\nThe acknowledgement carries the settings, each one a numbered option defined in\nRFC 2132. For this laptop it could contain:\n\n```text\noption 53  message type       5 (DHCPACK)\noption 54  server identifier  192.0.2.1\noption 51  lease time         86400 (seconds, one day)\noption 1   subnet mask        255.255.255.0\noption 3   router             192.0.2.1\noption 6   DNS servers        192.0.2.53\n```\n\nRFC 2132 requires the subnet mask to come before the router option when both are\npresent, and lets a server list several routers and several name servers, in\norder of preference. The lease time and the server identifier are not optional:\nRFC 2131 makes both mandatory in an acknowledgement to a request.\n\nBefore using 192.0.2.50, the client should check that nobody else is already\nusing it, for example with ARP. If the address turns out to be taken, the client\nmust send DHCPDECLINE and start again. Otherwise the timers start. Unless the\nserver sends values of its own, T1 is half the lease and T2 is seven eighths of\nit, so with a lease of one day:\n\n```text\nt = 0 s        DHCPACK received, lease starts\nt = 43200 s    T1: RENEWING, unicast DHCPREQUEST to 192.0.2.1\nt = 75600 s    T2: REBINDING, broadcast DHCPREQUEST to any server\nt = 86400 s    lease expires: stop using 192.0.2.50, start over\n```\n\nThe RFC asks for some random variation around both timers, so that a room full\nof laptops switched on together does not renew all at once. If a request gets no\nanswer, the client waits half of the remaining time before it tries again, down\nto a minimum of 60 seconds. A healthy client renews at the halfway mark and\nnever comes near the end of its lease.\n\nThe server does not have to sit on the laptop's subnet. A router can act as a\nrelay agent: it picks up the broadcast and passes it to a server elsewhere, and\nits own address, recorded in the message's giaddr field, tells the server where\nto send the answer. RFC 2131 counts on this, noting that relay agents remove the\nneed for a DHCP server on every network segment. At the scale our\n[networking and VPN services](/services/networking-vpn/) page describes, which\nlists configuring and deploying 1,000 Wi-Fi routers and administering network\ninfrastructure for more than 1,000 servers, typing addresses in by hand is not\nan option, and the layout of pools, leases and relays becomes part of the\nnetwork design.\n\n## Where it goes wrong\n\n**A rogue server answers first.** A home router plugged in the wrong way round,\na test machine bridged onto the office network or a deliberate attacker can all\nanswer a DHCPDISCOVER, and nothing in the protocol tells a client which server\nis the real one. RFC 2131 lists what such a server can do: hand out wrong or\nduplicate addresses, and point clients at a spoofed router or spoofed name\nservers. Switches can filter for this, and RFC 7610 notes that the IPv4 form of\nthe filter, DHCP snooping, is widely deployed. Allow DHCP server messages only\non the switch ports that lead to your real servers or relays, and drop them\neverywhere else.\n\n**The pool runs dry.** A pool holds a fixed number of addresses, and dynamic\nallocation only gets them back when leases end. On a guest network where phones\npass through by the hundred, a lease of a week means that every visitor of the\npast week still holds an address. RFC 2131 also warns that a malicious client\ncan claim every address for itself and leave none for anyone else. Size the pool\nfor the number of devices present within one lease period, and shorten the lease\nwherever devices come and go.\n\n**A new subnet without a relay.** The discover is a broadcast, and broadcasts\nstop at the router. A new VLAN or office floor with no relay agent configured\ngets no answer at all. A host that implements RFC 3927 may then give itself a\nlink-local address from 169.254/16, which only works on that one link, because\nrouters must not forward packets to or from such addresses. Configure a relay\nagent on the router of every subnet that has DHCP clients, and read a 169.254\naddress on a client as a sign that no server answered.\n\n**Two servers that disagree.** Running two servers for resilience is sensible,\nbut RFC 2131 says all servers should return the same parameters, apart from the\naddress itself, so that a client behaves the same whichever offer it takes, and\nit makes the administrator responsible for keeping them consistent. Two servers\nwhose ranges overlap can also lend the same address to two clients. Give each\nserver its own range, keep the options identical, and compare the two after\nevery change.\n\n**Fixed addresses inside the pool.** A printer given a static address by hand,\nfrom inside the range that DHCP lends out, will sooner or later collide with a\nlease. The protocol tries to catch this: a server should probe an address it is\nabout to reuse, for example with an ICMP echo request, and a client that finds\nits new address taken must decline it, after which the server marks the address\nas unavailable and should tell the administrator. Those are safety nets, not a\ndesign. Keep hand-configured addresses outside the pool, or use manual\nallocation, so that the server itself holds the reservation.\n\n**IPv6 left open.** Filtering DHCPv4 does nothing for DHCPv6, which runs on\nother ports and which a client may start when a router advertisement says DHCPv6\nis available. RFC 9915 points to RFC 7610, DHCPv6-Shield, for mitigating rogue\nDHCPv6 servers, and RFC 7610 states that rogue router advertisements are outside\nits scope; they are the job of Router Advertisement Guard. Filter DHCPv6 server\nmessages on access ports as you filter DHCPv4 ones, and run RA-Guard alongside.\n\n## Further reading\n\n- [RFC 2131: Dynamic Host Configuration Protocol](https://www.rfc-editor.org/rfc/rfc2131)\n  — the protocol itself: allocation mechanisms, leases, the message exchange,\n  the T1 and T2 timers and the security section.\n- [RFC 2132: DHCP Options and BOOTP Vendor Extensions](https://www.rfc-editor.org/rfc/rfc2132)\n  — every numbered option, from the subnet mask and the router list to the lease\n  time and the message type.\n- [RFC 9915: Dynamic Host Configuration Protocol for IPv6 (DHCPv6)](https://www.rfc-editor.org/rfc/rfc9915)\n  — the IPv6 protocol, its ports and messages, and how it works with SLAAC; it\n  obsoletes RFC 8415.\n- [RFC 7610: DHCPv6-Shield: Protecting against Rogue DHCPv6 Servers](https://www.rfc-editor.org/rfc/rfc7610)\n  — filtering server messages on the switch, the IPv4 precedent of DHCP\n  snooping, and what it leaves to RA-Guard.\n- [RFC 3927: Dynamic Configuration of IPv4 Link-Local Addresses](https://www.rfc-editor.org/rfc/rfc3927)\n  — the 169.254/16 addresses a host may give itself when no server answers, and\n  why routers never forward them.\n\n\u003chttps://engineer.company/glossary/dhcp/\u003e\n","date_modified":"2026-10-29T11:17:41Z","description":"How DHCP lends a device its IP address, router and DNS servers, why the lease length is a design decision, and how rogue servers and empty pools break it.","formats":{"gemtext":"https://engineer.company/glossary/dhcp/index.gmi","gopher":"https://engineer.company/glossary/dhcp/gophermap","html":"https://engineer.company/glossary/dhcp/","json":"https://engineer.company/glossary/dhcp/index.json","markdown":"https://engineer.company/glossary/dhcp/index.md","pdf":"https://engineer.company/glossary/dhcp/index.pdf"},"kind":"page","language":"en","title":"What is DHCP?","url":"https://engineer.company/glossary/dhcp/","version":1}