DHCP // RFC 2131

DHCP gives a host an IPv4 address and the configuration that goes with it: routes, DNS servers, a lease lifetime and more. The packet is a BOOTP header followed by a magic cookie and a list of type-length-value options.

layer application transport UDP/67 · UDP/68 fixed header 236 B options TLV · magic cookie

01Message layout

BOOTP fixed header · magic cookie · options

Every DHCPv4 message starts with the 236-byte BOOTP header. The first four octets identify the operation and the client hardware address type; the next fields carry the transaction ID, timing, flags and four IPv4 addresses. A DHCP message then adds the magic cookie 63 82 53 63 and the option area.

FieldOffsetWidthMeaningReference
op01 B1 = BOOTREQUEST (client), 2 = BOOTREPLY (server).RFC 2131 §2 · RFC 951
htype11 BHardware type. 1 is Ethernet.RFC 2131 §2 · RFC 1700
hlen21 BHardware address length in bytes; normally 6.RFC 2131 §2
hops31 BRelay hop count, set by relay agents.RFC 2131 §2
xid44 BTransaction identifier, chosen by the client and echoed by the server.RFC 2131 §2
secs82 BSeconds elapsed since the client began address acquisition.RFC 2131 §2
flags102 BBroadcast bit (0x8000); remaining bits reserved and zero.RFC 2131 §2 · RFC 2132 §2
ciaddr124 BClient IP address, filled in by a client that already has one.RFC 2131 §2
yiaddr164 B“Your” IP address offered by the server.RFC 2131 §2
siaddr204 BNext server address for bootstrap; often the DHCP server or TFTP server.RFC 2131 §2
giaddr244 BRelay agent address; zero when no relay is involved.RFC 2131 §2
chaddr2816 BClient hardware address, padded to 16 bytes.RFC 2131 §2
sname4464 BOptional server host name, null-terminated. May be overloaded with options.RFC 2131 §2 · RFC 2132 §9.3
file108128 BBoot file name, null-terminated. May be overloaded with options.RFC 2131 §2 · RFC 2132 §9.3
magic cookie2364 B63 82 53 63 (0x63825363), marking the DHCP option area.RFC 2131 §3
options240varTLV options, terminated by option 255. Pad with option 0.RFC 2132

The flags word

the fixed header is not the whole message

A DHCP message is at least 240 bytes once the magic cookie is present. The option area carries the message type, addresses, lease timers and every other parameter. A message with no option 53 is BOOTP-shaped but cannot identify itself as DHCP.

02Message types

option 53 · one byte · eight standard messages

The DHCP message type lives in option 53. It is one byte and must be present in every DHCP message. The standard exchange is DISCOVER → OFFER → REQUEST → ACK; NAK rejects a request, while RELEASE and DECLINE are client notifications.

CodeMessageDirectionPurposeReference
1DISCOVERC → SClient broadcasts a request for an address; yiaddr is zero.RFC 2131 §4.3.1
2OFFERS → CServer offers an address and configuration in yiaddr.RFC 2131 §4.3.2
3REQUESTC → SClient requests an offered address or renewal; option 50 and/or option 54 identify the choice.RFC 2131 §4.3.2
4DECLINEC → SClient reports that an offered address is already in use.RFC 2131 §4.3.3
5ACKS → CServer commits the lease and returns the final configuration.RFC 2131 §4.3.3
6NAKS → CServer rejects a request, often because the address is no longer valid.RFC 2131 §4.3.4
7RELEASEC → SClient gives up its lease and returns the address to the server.RFC 2131 §4.4.1
8INFORMC → SClient already has an address and asks only for configuration parameters.RFC 2131 §4.3.5
DHCP is unauthenticated

Any host on the link can answer a DISCOVER. Rogue DHCP servers, spoofed ACKs and malicious option 82 data are operational security problems. DHCP snooping, port security and trusted relay ports are network controls, not protocol features.

03Options

code · length · value · end

Options are one-byte code and one-byte length TLVs. Code 0 is a one-byte Pad; code 255 is a one-byte End. A zero-length option is valid only when the option definition allows it. Repeated options are concatenated in the order they appear (RFC 3396).

CodeOptionLengthMeaningReference
0Pad1Alignment padding; no length or value.RFC 2132 §3.1
255End1End of the option area.RFC 2132 §3.2
1Subnet Mask4Client subnet mask.RFC 2132 §3.3
3Router4nDefault gateway addresses, in preference order.RFC 2132 §3.5
6Domain Name Server4nDNS resolver addresses.RFC 2132 §3.8
12Host NamenClient host name.RFC 2132 §3.14
15Domain NamenDNS domain suffix.RFC 2132 §3.17
28Broadcast Address4Broadcast address for the client subnet.RFC 2132 §5.3
50Requested IP Address4Address requested in a DHCPREQUEST.RFC 2132 §9.1
51IP Address Lease Time4Lease lifetime in seconds.RFC 2132 §9.2
52Option Overload11 = file, 2 = sname, 3 = both contain options.RFC 2132 §9.3
53DHCP Message Type1DISCOVER, OFFER, REQUEST, DECLINE, ACK, NAK, RELEASE or INFORM.RFC 2132 §9.6
54Server Identifier4DHCP server address; required in OFFER, ACK and NAK.RFC 2132 §9.7
55Parameter Request ListnOptions the client wants the server to return.RFC 2132 §9.8
56MessagenDiagnostic text, often in a NAK.RFC 2132 §9.9
57Maximum DHCP Message Size2Largest DHCP message the client accepts.RFC 2132 §9.10
58Renewal Time Value4Time until the client moves to RENEWING.RFC 2132 §9.11
59Rebinding Time Value4Time until the client moves to REBINDING.RFC 2132 §9.12
60Vendor Class IdentifiernVendor or platform identity.RFC 2132 §9.13
61Client IdentifiernStable client identity; type byte plus identifier bytes.RFC 2132 §9.14 · RFC 6842
66TFTP Server NamenBootstrap server name.RFC 2132 §9.4
67Bootfile NamenBoot file path.RFC 2132 §9.5
82Relay Agent InformationnRelay-added sub-options such as circuit-id and remote-id.RFC 3046
121Classless Static RoutenDestination prefix, prefix length and next-hop.RFC 3442
249Microsoft Classless RoutenMicrosoft encoding of classless static routes.RFC 3442 · Microsoft
option overload and concatenation

When option 52 is present, the server may place additional options in the file field (bit 1), the sname field (bit 2), or both (bit 3). RFC 3396 allows a single option to be split across multiple occurrences; a decoder must concatenate the values in order before interpreting them.

04Encoder

BOOTP header · common options · arbitrary TLVs

Build a DHCP message with a valid BOOTP header, magic cookie and option area. The message type is always emitted as option 53. Common lease fields have dedicated inputs; everything else can be supplied as one code = value option per line.

DHCP parameters

RFC 2131 · RFC 2132

Options can use numeric codes or names such as subnet-mask, router, dns, requested-ip, parameter-request-list, client-id, relay-agent and classless-route. Duplicate code 53 is generated from the message-type selector.

wire output

waiting
Set the fields and press Build DHCP.
DHCP message hex
no bytes built yet
message — options — type —
this is the DHCP message, not the UDP wrapper

The output starts at the BOOTP op byte and includes the magic cookie and option area. The decoder accepts raw DHCP, UDP, IPv4 or Ethernet input, so you can wrap these bytes in UDP/68→67 or UDP/67→68 for a lab test.

05Decoder

raw DHCP · UDP · IPv4 · Ethernet

Paste a DHCP message, a UDP datagram on ports 67/68, an IPv4 packet with protocol 17, or an Ethernet frame carrying IPv4/UDP. The decoder reports the BOOTP fields, the message type, every option TLV, overloaded options and any structural warnings.

parse bytes

RFC 2131 · BOOTP · options
No DHCP message decoded yet.

06Wire notes

operational details that matter
DHCP is not authenticated

The transaction ID, client hardware address, server identifier and option 82 data are all claims. Use DHCP snooping, trusted relay ports and switch-port security to limit who can answer. A valid checksum proves only that the bytes survived the path.

  • Client and server ports are fixed. Clients use UDP/68 and servers use UDP/67. The first DISCOVER is broadcast because the client does not yet have an address.
  • xid is matching, not authentication. A 32-bit transaction ID lets a client discard unrelated replies. It does not prove that a reply came from a legitimate server.
  • The broadcast flag is a workaround. A client that cannot receive unicast before its address is configured sets 0x8000 and asks the server to broadcast the reply.
  • Lease timers are relative. Option 51 is the total lease. Options 58 and 59 are renewal (T1) and rebinding (T2) times. Servers should keep T1 < T2 < lease, but clients must tolerate unusual values.
  • Option overload is legal. When option 52 is set, options may continue in file, sname, or both. Parse those areas before declaring an option missing.
  • Repeated options are concatenated. RFC 3396 permits a long option to be split across multiple TLVs. Concatenate the values in order; do not keep only the first occurrence.
  • Relay agent information is link metadata. Option 82 is added by a relay. A server must treat it as untrusted unless the relay is trusted, and the circuit-id format is deployment-specific.
  • DHCPv6 is a different protocol. DHCPv6 uses UDP/546 and UDP/547, different message types and options, and RFC 8415. Do not parse DHCPv6 with a DHCPv4 decoder.

References