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