newt lab

dhcp-scapy-server

A minimal DHCP server in one Python script, built on Scapy. Small enough to read top to bottom, for lab segments and isolated networks where ISC DHCP or dnsmasq would be overkill.

dhcp-scapy-server is a DHCP server that fits in a single Python file. It listens on an interface for DHCP DISCOVER and REQUEST messages and answers them, handing a client an address, a DNS server, and the rest of a basic lease. The repository’s own summary: a “simple scapy script that listen for DHCP discover/requests and set an IP address.”

The reason to write one rather than reach for ISC DHCP or dnsmasq is size. Sometimes a DHCP server is needed for an afternoon (a lab segment, an isolated network, an embedded board being brought up) and the production servers bring a configuration language, a service to manage, and far more behavior than the moment calls for. A Scapy script you can read from top to bottom is the right size for that moment: the DHCP handshake (DISCOVER, OFFER, REQUEST, ACK) laid out in plain sight, in about a screen of Python.

Scapy does the heavy lifting. It sniffs the DHCP packets off the chosen interface, hands the script the parsed fields (the client’s MAC address, what it is asking for) and crafts the OFFER and ACK going back. The script supplies the policy: which interface, which addresses, which DNS server.

That policy is hardcoded. To use the tool you edit the script (the interface name, the server’s MAC and IP, the address to hand out, the DNS server) and run it. The README files this under laziness; it is also a defensible choice for a single-use tool. There is no configuration format to learn because the script is the configuration, and a few lines near the top are the whole of it. The cost is reusability; the return is that the entire tool is legible at a glance, which for a lab utility is worth more.

The source is on GitHub: github.com/dukptkey/dhcp-scapy-server.

Cite this piece
dukpt (2026). "dhcp-scapy-server". newt lab research. https://newt-lab.com/en/research/dhcp-scapy-server/