What is a DHCPv4 lease, and why does a DHCP server grant an address for a limited time rather than permanently?
answer
- borrowed, not owned
- clients leave without saying goodbye
- release message is optional
- expiry hands the address back
- renew halfway to keep it
basics
~20 sA DHCPv4 lease is the server's promise not to give an address to anyone else for a stated number of seconds. Leases expire because clients leave without telling the server, and expiry is how the server reclaims those addresses.
solid answer
~50 sA lease is a time-bounded allocation: for its duration the server guarantees not to hand the address to another client, and the client may use it only while the lease runs. RFC 2131 makes it time-limited because a server cannot tell a switched-off or departed client from a live one. `DHCPRELEASE` exists, but the RFC states that correct operation does not depend on it, and a client that keeps its address across reboots does not normally send it at shutdown. Expiry is therefore how the server reclaims addresses on its own. A live client keeps its address by extending the lease, by default at half its duration (`T1`), so a short absence costs it nothing. The duration travels as relative seconds (option 51), so client and server need no synchronised clocks, and `0xffffffff` means an infinite lease.
go deeper
Recall that a lease is a loan with a duration, that the client extends it before it ends, and that the address returns to the server when it expires.
Explain why expiry rather than DHCPRELEASE is what reclaims addresses, and that lease times are relative seconds so the two clocks need not agree.
Show you know what silent departures, clock drift and an infinite lease each do to a server's address bookkeeping, and why a server may report a shorter lease than it stores.
Frame the lease as a liveness mechanism: the protocol cannot observe departure, so it trades a bounded window of wasted addresses for never needing an explicit goodbye.
## What a lease is In **DHCPv4** (RFC 2131), a server does not give a host an address; it lends one. RFC 2131 §2.2 calls the period of the loan a **lease**: the collection of DHCP servers "guarantees not to reallocate that address within the requested time and attempts to return the same network address each time the client requests an address." The client, in turn, may use the address only while the lease is valid. A lease is identified by the client (its `client identifier` option, or its hardware address in `chaddr`) together with the address. The server keeps the binding in its database; the client keeps its own copy, plus the timers that tell it when to act. ## Why not simply hand addresses out permanently The core problem is that **a DHCP server cannot see whether a client still exists**. Laptops close their lids, phones walk out of range, virtual machines are deleted, desks are cleared. None of these events sends anything to the server reliably. - **`DHCPRELEASE` is optional.** RFC 2131 §4.4.6 says a client that no longer needs its address sends `DHCPRELEASE`, and in the same breath: "correct operation of DHCP does not depend on the transmission of DHCPRELEASE messages." - **Clients that remember their address do not release it.** §3.2 notes that a client retaining its address locally "will not normally relinquish its lease during a graceful shutdown"; it releases only when it explicitly must, for example when it is about to move to another subnet. - **Crashes and power loss send nothing at all.** No protocol message can be relied on to announce a client's disappearance. - **Expiry is the server's own clean-up.** When a lease runs out, the address becomes available again, and §2.2 lets a server facing exhaustion reuse addresses whose lease has expired, probing them first (an ICMP echo is the example the RFC gives). A permanent assignment would leak an address for every client that ever left silently. A time limit turns that leak into a bounded delay. ## How the time is expressed RFC 2131 §3.3 represents every time as a **relative** number of seconds in an unsigned 32-bit field, "to be interpreted with respect to the client's local clock." Because nothing is an absolute timestamp, the client and server do not need synchronised clocks. The value `0xffffffff` is reserved to mean **infinity**. | Option (RFC 2132) | Code | Meaning | |---|---|---| | IP Address Lease Time | 51 | Lease duration in seconds; a client may request one, the server states what it grants | | Renewal (T1) Time Value | 58 | Seconds from assignment until the client enters `RENEWING` | | Rebinding (T2) Time Value | 59 | Seconds from assignment until the client enters `REBINDING` | The client computes its expiry as the time it **sent** the request plus the duration in the server's `DHCPACK`, so any network delay counts against the client, never in its favour. Because the two clocks may still drift, §3.3 lets a server hand the client a **shorter** lease than the one it records for itself. ## What keeps a lease alive A client does not wait for the end. With the defaults of RFC 2131 §4.4.5: 1. **`BOUND`** — the client uses the address normally. 2. **`T1`, half the lease** — the client enters `RENEWING` and unicasts a `DHCPREQUEST` to the server that granted the lease. 3. **`T2`, 87.5% of the lease** — if no `DHCPACK` has arrived, it enters `REBINDING` and broadcasts the `DHCPREQUEST` so any server with authority can extend it. 4. **Expiry** — if still nothing, the client must stop using the address at once and start over from `INIT`. Every successful `DHCPACK` restarts the clock. This is why a laptop that sleeps through lunch on a long lease wakes with the same address: its lease simply has not run out. ## What happens to a released address When a `DHCPRELEASE` does arrive, it is **unicast** to the server, and RFC 2131 §4.3.4 has the server mark the address as not allocated while it "SHOULD retain a record of the client's initialization parameters for possible reuse." RFC 2131 defines no reply to it. Release is a courtesy that frees an address early; expiry is the guarantee. ## What a lease is not - **Not ownership.** Even an infinite lease is a lease; §2.2 notes a server may prefer lengthy but non-infinite leases for "permanent" hosts so that it can detect when a client has been retired. - **Not a promise of the same address next time.** Servers *attempt* to return the same address; once a lease has expired and the address has gone to someone else, the client gets a different one. - **Not a reservation.** Tying an address to a particular client in the server's configuration is a separate server-side feature; the lease mechanics above apply to it as well. - **Not chosen by this mechanism.** How long a lease should be on a given network is a pool-design decision, not part of the lease state machine.
- Can a DHCPv4 server grant a permanent address, and why might it still choose not to?Yes: RFC 2131 lets a client ask for an infinite lease, and the lease-time value `0xffffffff` is reserved to mean infinity. Even for hosts meant to keep an address, §2.2 notes a server may hand out lengthy but non-infinite leases, so that a client that has been retired is eventually detected and its address comes back.
- Why might a DHCPv4 server give a client a shorter lease than the one it records in its own database?Lease times are relative and run on each side's own clock. If the clocks drift, the server could consider a lease expired while the client still uses it. RFC 2131 §3.3 lets the server compensate by telling the client a shorter duration than it commits to locally, so the client always stops first.
A lease is like a parking permit with an expiry date: renew it halfway through and you keep the space, drive away without handing it back and the space frees itself when the date passes.
saying these in an interview costs you the question
- A client must send DHCPRELEASE or its address stays allocated forever.
- A lease means the client owns that address until it next reboots.
- Lease times are absolute timestamps, so client and server clocks must agree.
- The server sends a message telling the client its lease has expired.
- Any short absence makes a client lose its address immediately.