1.\" $OpenBSD: dhcpd.8,v 1.36 2024/06/27 16:39:31 florian Exp $ 2.\" 3.\" Copyright (c) 1995, 1996 The Internet Software Consortium. 4.\" All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 3. Neither the name of The Internet Software Consortium nor the names 16.\" of its contributors may be used to endorse or promote products derived 17.\" from this software without specific prior written permission. 18.\" 19.\" THIS SOFTWARE IS PROVIDED BY THE INTERNET SOFTWARE CONSORTIUM AND 20.\" CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 21.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 22.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23.\" DISCLAIMED. IN NO EVENT SHALL THE INTERNET SOFTWARE CONSORTIUM OR 24.\" CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26.\" LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 27.\" USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 28.\" ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 30.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31.\" SUCH DAMAGE. 32.\" 33.\" This software has been written for the Internet Software Consortium 34.\" by Ted Lemon <mellon@fugue.com> in cooperation with Vixie 35.\" Enterprises. To learn more about the Internet Software Consortium, 36.\" see ``http://www.isc.org/''. To learn more about Vixie 37.\" Enterprises, see ``http://www.vix.com''. 38.\" 39.Dd $Mdocdate: June 27 2024 $ 40.Dt DHCPD 8 41.Os 42.Sh NAME 43.Nm dhcpd 44.Nd Dynamic Host Configuration Protocol (DHCP) daemon 45.Sh SYNOPSIS 46.Nm dhcpd 47.Bk -words 48.Op Fl dfnv 49.Op Fl A Ar abandoned_ip_table 50.Op Fl C Ar changed_ip_table 51.Op Fl c Ar config-file 52.Op Fl L Ar leased_ip_table 53.Op Fl l Ar lease-file 54.Op Fl u Ns Op Ar bind_address 55.Op Fl Y Ar synctarget 56.Op Fl y Ar synclisten 57.Op Ar if0 Op Ar ... ifN 58.Ek 59.Sh DESCRIPTION 60.Nm 61implements the Dynamic Host Configuration Protocol (DHCP) and the 62Internet Bootstrap Protocol (BOOTP). 63DHCP allows hosts on a TCP/IP network to request and be assigned IP addresses, 64and also to discover information about the network to which they are attached. 65BOOTP provides similar functionality, with certain restrictions. 66.Pp 67The DHCP protocol allows a host which is unknown to the network 68administrator to be automatically assigned a new IP address out of a 69pool of IP addresses for its network. 70In order for this to work, the network administrator allocates address pools 71in each subnet and enters them into the 72.Xr dhcpd.conf 5 73file. 74.Pp 75On startup, 76.Nm 77reads the 78.Pa dhcpd.conf 79file and stores a list of available addresses on each subnet in memory. 80When a client requests an address using the DHCP protocol, 81.Nm 82allocates an address for it. 83Each client is assigned a lease, which expires after an amount of time 84chosen by the administrator (by default, one day). 85When a leased IP address is assigned to a new hardware address, 86.Nm 87may delete the leased address from certain 88.Xr pf 4 89tables. 90Before leases expire, the clients to which leases are assigned are expected 91to renew them in order to continue to use the addresses. 92Once a lease has expired, the client to which that lease was assigned is no 93longer permitted to use the leased IP address. 94.Pp 95Whenever changes are made to the 96.Pa dhcpd.conf 97file, 98.Nm 99must be restarted. 100.Pp 101In order to keep track of leases across system reboots and server restarts, 102.Nm 103keeps a list of leases it has assigned in the 104.Xr dhcpd.leases 5 105file. 106Before 107.Nm 108grants a lease to a host, it records the lease in this file and makes sure 109that the contents of the file are flushed to disk. 110This ensures that even in the event of a system crash, 111.Nm 112will not forget about a lease that it has assigned. 113On startup, after reading the 114.Pa dhcpd.conf 115file, 116.Nm 117reads the 118.Pa dhcpd.leases 119file to refresh its memory about what leases have been assigned. 120.Pp 121When 122.Nm 123starts up, it 124identifies all network interfaces in all routing domains, 125eliminating non-broadcast interfaces if possible, 126and listens for DHCP broadcasts on each interface. 127The names of the network interfaces on which 128.Nm 129should listen for broadcasts may also be specified on the command line 130on systems where 131.Nm 132is unable to identify non-broadcast interfaces. 133.Pp 134.Nm 135normally runs in routing domain 0. 136In order to run in another 137.Xr rdomain 4 , 138.Nm 139needs to be started with a list of interfaces 140which share the same routing domain, 141which allows 142.Nm 143to set its own routing domain accordingly. 144.Pp 145DHCP traffic always bypasses IPsec. 146Otherwise there could be situations when a server has an IPsec SA for the 147client and sends replies over that, 148which a newly booted client would not be able to grasp. 149.Pp 150The options are as follows: 151.Bl -tag -width Ds 152.It Fl A Ar abandoned_ip_table 153When an address is abandoned for some reason, add it to the 154.Xr pf 4 155table named 156.Ar abandoned_ip_table . 157This can be used to defend against machines "camping" on an address 158without obtaining a lease. 159When an address is properly leased, 160.Nm 161will remove the address from this table. 162.It Fl C Ar changed_ip_table 163When an address is leased to a different hardware address, delete it from the 164.Xr pf 4 165table named 166.Ar changed_ip_table . 167This feature complements the overload table in a stateful 168.Xr pf 4 169rule. 170If a host appears to be misbehaving, it can be quarantined by using the 171overload feature. 172When the address is leased to a different machine, 173.Nm 174can remove the address from the overload table, thus allowing a well-behaved 175machine to reuse the address. 176.It Fl c Ar config-file 177Use an alternate configuration file, 178.Ar config-file . 179Because of the importance of using the same lease database at all times when 180running 181.Nm 182in production, this option should be used 183.Em only 184for testing database files in a non-production environment. 185.It Fl d 186Do not daemonize. 187If this option is specified, 188.Nm 189will run in the foreground and log to 190.Em stderr . 191.It Fl f 192An alias for 193.Fl d . 194.It Fl L Ar leased_ip_table 195When an address is leased, 196.Nm 197will insert it into the 198.Xr pf 4 199table named 200.Ar leased_ip_table . 201Addresses are removed from the table when the lease expires. 202Combined with the table of abandoned addresses, this can help enforce a 203requirement to use DHCP on a network, or can place DHCP users in a different 204class of service. 205Users are cautioned against placing much trust in Ethernet or IP addresses; 206.Xr ifconfig 8 207can be used to trivially change the interface's address, and on a busy DHCP 208network, IP addresses will likely be quickly recycled. 209.It Fl l Ar lease-file 210Use an alternate lease file, 211.Ar lease-file . 212Because of the importance of using the same lease database at all times when 213running 214.Nm 215in production, this option should be used 216.Em only 217for testing lease files in a non-production environment. 218.It Fl n 219Only test configuration, do not run 220.Nm . 221.It Fl u Ns Op Ar bind_address 222Use a UDP socket instead of BPF for receiving and sending packets. 223Only 224.Dv DHCPINFORM 225messages can be handled on this socket; 226other messages are discarded. 227With this option, 228.Nm 229can answer 230.Dv DHCPINFORM 231from clients on non Ethernet interfaces 232such as 233.Xr tun 4 234or 235.Xr pppx 4 . 236If 237.Ar bind_address 238is specified, 239.Nm 240will bind to that address; otherwise 241the limited broadcast address (255.255.255.255) is used as the default. 242.It Fl v 243Produce more verbose output. 244.It Fl Y Ar synctarget 245Add target 246.Ar synctarget 247to receive synchronisation messages. 248.Ar synctarget 249can be either an IPv4 address for unicast messages 250or a network interface name followed optionally by a colon and a numeric TTL 251value for multicast messages to the group 224.0.1.240. 252If the multicast TTL is not specified, a default value of 1 is used. 253This option can be specified multiple times. 254See also 255.Sx SYNCHRONISATION 256below. 257.It Fl y Ar synclisten 258Listen on 259.Ar synclisten 260for incoming synchronisation messages. 261The format for 262.Ar synclisten 263is the same as for 264.Ar synctarget , 265above. 266This option can be specified only once. 267See also 268.Sx SYNCHRONISATION 269below. 270.El 271.Sh BOOTP 272.Nm 273also provides BOOTP support. 274Unlike DHCP, the BOOTP protocol does not provide a protocol for recovering 275dynamically-assigned addresses once they are no longer needed. 276It is still possible to dynamically assign addresses to BOOTP clients, but 277some administrative process for reclaiming addresses is required. 278By default, leases are granted to BOOTP clients in perpetuity, although 279the network administrator may set an earlier cutoff date or a shorter 280lease length for BOOTP leases if that makes sense. 281.Pp 282BOOTP clients may also be served in the old standard way, which is 283simply to provide a declaration in the 284.Pa dhcpd.conf 285file for each BOOTP client, permanently assigning an address to each client. 286.Sh CONFIGURATION 287The syntax of the 288.Xr dhcpd.conf 5 289file is discussed separately. 290This section should be used as an overview of the configuration process, 291and the 292.Xr dhcpd.conf 5 293documentation should be consulted for detailed reference information. 294.Bl -tag -width 3n 295.It Subnets 296.Nm 297needs to know the subnet numbers and netmasks of all subnets for 298which it will be providing service. 299In addition, in order to dynamically allocate addresses, it must be assigned 300one or more ranges of addresses on each subnet which it can in turn assign 301to client hosts as they boot. 302Thus, a very simple configuration providing DHCP support might look like this: 303.Bd -literal -offset indent 304subnet 239.252.197.0 netmask 255.255.255.0 { 305 range 239.252.197.10 239.252.197.250; 306} 307.Ed 308.Pp 309Multiple address ranges may be specified like this: 310.Bd -literal -offset indent 311subnet 239.252.197.0 netmask 255.255.255.0 { 312 range 239.252.197.10 239.252.197.107; 313 range 239.252.197.113 239.252.197.250; 314} 315.Ed 316.Pp 317If a subnet will only be provided with BOOTP service and no dynamic 318address assignment, the range clause can be left out entirely, but the 319subnet statement must appear. 320.It Lease Lengths 321DHCP leases can be assigned almost any length from zero seconds to infinity. 322What lease length makes sense for any given subnet, or for any given 323installation, will vary depending on the kinds of hosts being served. 324.Pp 325For example, in an office environment where systems are added from 326time to time and removed from time to time, but move relatively 327infrequently, it might make sense to allow lease times of a month or more. 328In a final test environment on a manufacturing floor, it may make more sense 329to assign a maximum lease length of 30 minutes \- enough time to go through a 330simple test procedure on a network appliance before packaging it up for 331delivery. 332.Pp 333It is possible to specify two lease lengths: the default length that 334will be assigned if a client doesn't ask for any particular lease 335length, and a maximum lease length. 336These are specified as clauses to the subnet command: 337.Bd -literal -offset indent 338subnet 239.252.197.0 netmask 255.255.255.0 { 339 range 239.252.197.10 239.252.197.107; 340 default-lease-time 600; 341 max-lease-time 7200; 342} 343.Ed 344.Pp 345This particular subnet declaration specifies a default lease time of 346600 seconds (ten minutes), and a maximum lease time of 7200 seconds 347(two hours). 348Other common values would be 86400 (one day), 604800 (one week) 349and 2592000 (30 days). 350.Pp 351Each subnet need not have the same lease \- in the case of an office 352environment and a manufacturing environment served by the same DHCP 353server, it might make sense to have widely disparate values for 354default and maximum lease times on each subnet. 355.It BOOTP Support 356Each BOOTP client must be explicitly declared in the 357.Xr dhcpd.conf 5 358file. 359A very basic client declaration will specify the client network interface's 360hardware address and the IP address to assign to that client. 361If the client needs to be able to load a boot file from the server, 362that file's name must be specified. 363A simple BOOTP client declaration might look like this: 364.Bd -literal -offset indent 365host haagen { 366 hardware ethernet 08:00:2b:4c:59:23; 367 fixed-address 239.252.197.9; 368 filename "haagen.boot"; 369} 370.Ed 371.It Options 372DHCP (and also BOOTP with Vendor Extensions) provides a mechanism 373whereby the server can provide the client with information about how 374to configure its network interface (e.g., subnet mask), and also how 375the client can access various network services (e.g., DNS, IP routers, 376and so on). 377.Pp 378These options can be specified on a per-subnet basis and, for BOOTP 379clients, also on a per-client basis. 380In the event that a BOOTP client declaration specifies options that are 381also specified in its subnet declaration, the options specified in the 382client declaration take precedence. 383A reasonably complete DHCP configuration might look something like this: 384.Bd -literal -offset indent 385subnet 239.252.197.0 netmask 255.255.255.0 { 386 range 239.252.197.10 239.252.197.250; 387 default-lease-time 600; 388 max-lease-time 7200; 389 option subnet-mask 255.255.255.0; 390 option broadcast-address 239.252.197.255; 391 option routers 239.252.197.1; 392 option domain-name-servers 239.252.197.2, 239.252.197.3; 393 option domain-name "isc.org"; 394} 395.Ed 396.Pp 397A BOOTP host on that subnet that needs to be in a different domain and 398use a different name server might be declared as follows: 399.Bd -literal -offset indent 400host haagen { 401 hardware ethernet 08:00:2b:4c:59:23; 402 fixed-address 239.252.197.9; 403 filename "haagen.boot"; 404 option domain-name-servers 192.5.5.1; 405 option domain-name "vix.com"; 406} 407.Ed 408.El 409.Pp 410A more complete description of the 411.Pa dhcpd.conf 412file syntax is provided in 413.Xr dhcpd.conf 5 . 414.Sh SYNCHRONISATION 415.Nm 416supports realtime synchronisation of the lease allocations to 417a number of 418.Nm 419daemons running on multiple machines, 420using the 421.Fl Y 422and 423.Fl y 424options. 425.Pp 426The following example will accept incoming multicast and unicast 427synchronisation messages, and send outgoing multicast messages through 428the network interface 429.Ar em0 : 430.Bd -literal -offset indent 431# /usr/sbin/dhcpd -y em0 -Y em0 432.Ed 433.Pp 434The second example will increase the multicast TTL to a value of 2, 435add the unicast targets 436.Ar foo.somewhere.org 437and 438.Ar bar.somewhere.org , 439and accept incoming unicast messages sent to 440.Ar example.somewhere.org 441only. 442.Bd -literal -offset indent 443# /usr/sbin/dhcpd -y example.somewhere.org -Y em0:2 \e 444 -Y foo.somewhere.org -Y bar.somewhere.org 445.Ed 446.Pp 447If the file 448.Pa /var/db/dhcpd.key 449exists, 450.Nm 451will calculate the message-digest fingerprint (checksum) for the file 452and use it as a shared key to authenticate the synchronisation messages. 453The file itself can contain any data. 454For example, to create a secure random key: 455.Bd -literal -offset indent 456# dd if=/dev/random of=/var/db/dhcpd.key bs=2048 count=1 457.Ed 458.Pp 459The file needs to be copied to all hosts 460sending or receiving synchronisation messages. 461.Pp 462All hosts using synchronisation must use the same configuration in the 463.Pa /etc/dhcpd.conf 464file. 465.Sh FILES 466.Bl -tag -width "/var/db/dhcpd.leases~ " -compact 467.It Pa /etc/dhcpd.conf 468DHCPD configuration file. 469.It Pa /var/db/dhcpd.leases 470DHCPD lease file. 471.El 472.Sh SEE ALSO 473.Xr pf 4 , 474.Xr rdomain 4 , 475.Xr dhcpd.conf 5 , 476.Xr dhcpd.leases 5 , 477.Xr dhcpleased 8 , 478.Xr dhcrelay 8 , 479.Xr pxeboot 8 480.Sh STANDARDS 481.Rs 482.%A R. Droms 483.%D October 1993 484.%R RFC 1534 485.%T Interoperation Between DHCP and BOOTP 486.Re 487.Pp 488.Rs 489.%A R. Droms 490.%D March 1997 491.%R RFC 2131 492.%T Dynamic Host Configuration Protocol 493.Re 494.Pp 495.Rs 496.%A S. Alexander 497.%A R. Droms 498.%D March 1997 499.%R RFC 2132 500.%T DHCP Options and BOOTP Vendor Extensions 501.Re 502.Pp 503.Rs 504.%A T. Lemon 505.%A S. Cheshire 506.%D November 2002 507.%R RFC 3396 508.%T Encoding Long Options in the Dynamic Host Configuration Protocol (DHCPv4) 509.Re 510.Pp 511.Rs 512.%A T. Lemon 513.%A S. Cheshire 514.%A B. Volz 515.%D December 2002 516.%R RFC 3442 517.%T The Classless Static Route Option for Dynamic Host Configuration Protocol (DHCP) version 4 518.Re 519.Sh AUTHORS 520.An -nosplit 521.Nm 522is based on software from the Internet Software Consortium, 523written by 524.An Ted Lemon Aq Mt mellon@vix.com 525under a contract with Vixie Labs. 526The current implementation was reworked for 527.Ox 528by 529.An Henning Brauer Aq Mt henning@openbsd.org . 530.Sh BUGS 531We realize that it would be nice if one could send a 532.Dv SIGHUP 533to the server and have it reload the database. 534This is not technically impossible, but it would require a great deal of work, 535our resources are extremely limited, and they can be better spent elsewhere. 536So please don't complain about this on the mailing list unless you're prepared 537to fund a project to implement this feature, or prepared to do it yourself. 538