summaryrefslogtreecommitdiff
path: root/docs/services/dhcp.rst
blob: 23dbabf9ee101fdef4061b08935d231dde7b9b09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
.. _dhcp:

#############
DHCP / DHCPv6
#############

VyOS uses ISC DHCPd for both IPv4 and IPv6 address assignment.

.. _dhcp-server:

DHCP Server
===========

The network topology is declared by shared-network-name and the subnet
declarations. The DHCP service can serve multiple shared networks, with each
shared network having 1 or more subnets. Each subnet must be present on an
interface. A range can be declared inside a subnet to define a pool of dynamic
addresses. Multiple ranges can be defined and can contain holes. Static
mappings can be set to assign "static" addresses to clients based on their MAC
address.

Configuration
-------------

.. cfgcmd:: set service dhcp-server shared-network-name <name> authoritative

   This says that this device is the only DHCP server for this network. If other
   devices are trying to offer DHCP leases, this machine will send 'DHCPNAK' to
   any device trying to request an IP address that is not valid for this
   network.

.. cfgcmd:: set service dhcp-server shared-network-name <name> subnet <subnet> default-router <address>

   This is a configuration parameter for the `<subnet>`, saying that as part of
   the response, tell the client that the default gateway can be reached at
   `<address>`.

.. cfgcmd:: set service dhcp-server shared-network-name <name> subnet <subnet> dns-server <address>

   This is a configuration parameter for the subnet, saying that as part of the
   response, tell the client that the DNS server can be found at `<address>`.

   Multiple DNS servers can be defined.

.. cfgcmd:: set service dhcp-server shared-network-name <name> subnet <subnet> lease <time>

   Assign the IP address to this machine for `<time>` seconds.

   The default value is 86400 seconds which corresponds to one day.

.. cfgcmd:: set service dhcp-server shared-network-name <name> subnet <subnet> range <n> start <address>

   Create DHCP address range with a range id of `<n>`. DHCP leases are taken
   from this pool. The pool starts at address `<address>`.

.. cfgcmd:: set service dhcp-server shared-network-name <name> subnet <subnet> range <n> stop <address>

   Create DHCP address range with a range id of `<n>`. DHCP leases are taken
   from this pool. The pool stops with address `<address>`.

.. cfgcmd:: set service dhcp-server shared-network-name <name> subnet <subnet> exclude <address>

   Always exclude this address from any defined range. This address will never
   be assigned by the DHCP server.

   This option can be specified multiple times.

.. cfgcmd:: set service dhcp-server shared-network-name <name> subnet 192.0.2.0/24 domain-name <domain-name>

   The domain-name parameter should be the domain name that will be appended to
   the client's hostname to form a fully-qualified domain-name (FQDN) (DHCP
   Option 015).

.. cfgcmd:: set service dhcp-server shared-network-name <name> subnet 192.0.2.0/24 domain-search <domain-name>

   The domain-name parameter should be the domain name used when completing DNS
   request where no full FQDN is passed. This option can be given multiple times
   if you need multiple search domains (DHCP Option 119).


Failover
^^^^^^^^

VyOS provides support for DHCP failover. DHCP failover must be configured
explicitly by the following statements.

.. cfgcmd:: set service dhcp-server shared-network-name <name> subnet <subnet> failover local-address <address>

   Local IP `<address>` used when communicating to the failover peer.

.. cfgcmd:: set service dhcp-server shared-network-name <name> subnet <subnet> failover peer-address <address>

   Remote peer IP `<address>` of the second DHCP server in this failover cluster.

.. cfgcmd:: set service dhcp-server shared-network-name <name> subnet <subnet> failover name <name>

   A generic `<name>` referencing this sync service.

   .. note:: `<name>` must be identical on both sides!

.. cfgcmd:: set service dhcp-server shared-network-name <name> subnet <subnet> failover status <primary | secondary>

   The primary and secondary statements determines whether the server is primary
   or secondary.

   .. note:: In order for the primary and the secondary DHCP server to keep
      their lease tables in sync, they must be able to reach each other on TCP
      port 647. If you have firewall rules in effect, adjust them accordingly.

   .. hint:: The dialogue between failover partners is neither encrypted nor
      authenticated. Since most DHCP servers exist within an organisation's own
      secure Intranet, this would be an unnecessary overhead. However, if you have
      DHCP failover peers whose communications traverse insecure networks, then we
      recommend that you consider the use of VPN tunneling between them to ensure
      that the failover partnership is immune to disruption (accidental or
      otherwise) via third parties.


Static mappings
^^^^^^^^^^^^^^^

You can specify a static DHCP assignment on a per host basis. You will need the
MAC address of the station and your desired IP address. The address must be
inside the subnet definition but can be outside of the range statement.

.. cfgcmd:: set service dhcp-server shared-network-name <name> subnet <subnet> static-mapping <description> mac-address <address>

   Create a new DHCP static mapping named `<description>` which is valid for
   the host identified by its MAC `<address>`.

.. cfgcmd:: set service dhcp-server shared-network-name <name> subnet <subnet> static-mapping <description> ip-address <address>

   Static DHCP IP address assign to host identified by `<description>`. IP
   address must be inside the `<subnet>` which is defined but can be outside
   the dynamic range created with :cfgcmd:`set service dhcp-server
   shared-network-name <name> subnet <subnet> range <n>`. If no ip-address is
   specified, an IP from the dynamic pool is used.

   This is useful, for example, in combination with hostfile update.

   .. hint:: This is the equivalent of the host block in dhcpd.conf of isc-dhcpd.


Options
^^^^^^^

.. list-table::
   :header-rows: 1
   :stub-columns: 0
   :widths: 12 7 23 40 20

   * - Setting name
     - Option number
     - ISC-DHCP Option name
     - Option description
     - Multi
   * - client-prefix-length
     - 1
     - subnet-mask
     - Specifies the clients subnet mask as per RFC 950. If unset, subnet declaration is used.
     - N
   * - time-offset
     - 2
     - time-offset
     - Offset of the client's subnet in seconds from Coordinated Universal Time (UTC)
     - N
   * - default-router
     - 3
     - routers
     - IPv4 address of router on the client's subnet
     - N
   * - time-server
     - 4
     - time-servers
     - RFC 868 time server IPv4 address
     - Y
   * - dns-server
     - 6
     - domain-name-servers
     - DNS server IPv4 address
     - Y
   * - domain-name
     - 15
     - domain-name
     - Client domain name
     - Y
   * - ip-forwarding
     - 19
     - ip-forwarding
     - Enable IP forwarding on client
     - N
   * - ntp-server
     - 42
     - ntp-servers
     - IP address of NTP server
     - Y
   * - wins-server
     - 44
     - netbios-name-servers
     - NetBIOS over TCP/IP name server
     - Y
   * - server-identifier
     - 54
     - dhcp-server-identifier
     - IP address for DHCP server identifier
     - N
   * - bootfile-server
     - siaddr
     - next-server
     - IPv4 address of next bootstrap server
     - N
   * - tftp-server-name
     - 66
     - tftp-server-name
     - Name or IPv4 address of TFTP server
     - N
   * - bootfile-name
     - 67
     - bootfile-name, filename
     - Bootstrap file name
     - N
   * - smtp-server
     - 69
     - smtp-server
     - IP address of SMTP server
     - Y
   * - pop-server
     - 70
     - pop-server
     - IP address of POP3 server
     - Y
   * - domain-search
     - 119
     - domain-search
     - Client domain search
     - Y
   * - static-route
     - 121, 249
     - rfc3442-static-route, windows-static-route
     - Classless static route
     - N
   * - wpad-url
     - 252
     - wpad-url, wpad-url code 252 = text
     - Web Proxy Autodiscovery (WPAD) URL
     - N
   * - lease
     -
     - default-lease-time, max-lease-time
     - Lease timeout in seconds (default: 86400)
     - N
   * - range
     -
     - range
     - DHCP lease range
     - Y
   * - exclude
     -
     -
     - IP address to exclude from DHCP lease range
     - Y
   * - failover
     -
     -
     - DHCP failover parameters
     -
   * - static-mapping
     -
     -
     - Name of static mapping
     - Y

Multi: can be specified multiple times.


Raw Parameters
^^^^^^^^^^^^^^

Raw parameters can be passed to shared-network-name, subnet and static-mapping:

.. code-block:: none

  set service dhcp-server shared-network-name <name> shared-network-parameters
     <text>       Additional shared-network parameters for DHCP server.
  set service dhcp-server shared-network-name <name> subnet <subnet> subnet-parameters
     <text>       Additional subnet parameters for DHCP server.
  set service dhcp-server shared-network-name <name> subnet <subnet> static-mapping <description> static-mapping-parameters
     <text>       Additional static-mapping parameters for DHCP server.
                  Will be placed inside the "host" block of the mapping.

These parameters are passed as-is to isc-dhcp's dhcpd.conf under the
configuration node they are defined in. They are not validated so an error in
the raw parameters won't be caught by vyos's scripts and will cause dhcpd to
fail to start. Always verify that the parameters are correct before commiting
the configuration. Refer to isc-dhcp's dhcpd.conf manual for more information:
https://kb.isc.org/docs/isc-dhcp-44-manual-pages-dhcpdconf

Quotes can be used inside parameter values by replacing all quote characters
with the string ``&quot;``. They will be replaced with literal quote characters
when generating dhcpd.conf.


Example
^^^^^^^

Quick-Start
"""""""""""

* We are offering address space in the `192.0.2.0/24` network.
* We are using the network name `mypool`.

.. code-block:: none

  set service dhcp-server shared-network-name mypool authoritative
  set service dhcp-server shared-network-name mypool subnet 192.0.2.0/24 default-router 192.0.2.1
  set service dhcp-server shared-network-name mypool subnet 192.0.2.0/24 dns-server 192.0.2.1
  set service dhcp-server shared-network-name mypool subnet 192.0.2.0/24 lease 86400
  set service dhcp-server shared-network-name mypool subnet 192.0.2.0/24 range 0 start 192.0.2.100
  set service dhcp-server shared-network-name mypool subnet 192.0.2.0/24 range 0 stop 192.0.2.199

The generated config will look like:

.. code-block:: none

  vyos@vyos# show service dhcp-server shared-network-name mypool
  authoritative
  subnet 192.0.2.0/24 {
      default-router 192.0.2.1
      dns-server 192.0.2.1
      lease 86400
      range 0 {
          start 192.0.2.100
          stop 192.0.2.199
      }
  }


Failover
""""""""

* Setup DHCP failover for network 192.0.2.0/24
* Default gateway and DNS server is at `192.0.2.254`
* The primary DHCP server uses address `192.168.189.252`
* The secondary DHCP server uses address `192.168.189.253`
* DHCP range spans from `192.168.189.10` - `192.168.189.250`

**Primary**

.. code-block:: none

  set service dhcp-server shared-network-name NET-VYOS subnet 192.0.2.0/24 default-router '192.0.2.254'
  set service dhcp-server shared-network-name NET-VYOS subnet 192.0.2.0/24 dns-server '192.0.2.254'
  set service dhcp-server shared-network-name NET-VYOS subnet 192.0.2.0/24 domain-name 'vyos.net'
  set service dhcp-server shared-network-name NET-VYOS subnet 192.0.2.0/24 failover local-address '192.168.189.252'
  set service dhcp-server shared-network-name NET-VYOS subnet 192.0.2.0/24 failover name 'NET-VYOS'
  set service dhcp-server shared-network-name NET-VYOS subnet 192.0.2.0/24 failover peer-address '192.168.189.253'
  set service dhcp-server shared-network-name NET-VYOS subnet 192.0.2.0/24 failover status 'primary'
  set service dhcp-server shared-network-name NET-VYOS subnet 192.0.2.0/24 range 0 start '192.168.189.10'
  set service dhcp-server shared-network-name NET-VYOS subnet 192.0.2.0/24 range 0 stop '192.168.189.250'

**Secondary**

.. code-block:: none

  set service dhcp-server shared-network-name NET-VYOS subnet 192.0.2.0/24 default-router '192.0.2.254'
  set service dhcp-server shared-network-name NET-VYOS subnet 192.0.2.0/24 dns-server '192.0.2.254'
  set service dhcp-server shared-network-name NET-VYOS subnet 192.0.2.0/24 domain-name 'vyos.net'
  set service dhcp-server shared-network-name NET-VYOS subnet 192.0.2.0/24 failover local-address '192.168.189.253'
  set service dhcp-server shared-network-name NET-VYOS subnet 192.0.2.0/24 failover name 'NET-VYOS'
  set service dhcp-server shared-network-name NET-VYOS subnet 192.0.2.0/24 failover peer-address '192.168.189.252'
  set service dhcp-server shared-network-name NET-VYOS subnet 192.0.2.0/24 failover status 'primary'
  set service dhcp-server shared-network-name NET-VYOS subnet 192.0.2.0/24 range 0 start '192.168.189.10'
  set service dhcp-server shared-network-name NET-VYOS subnet 192.0.2.0/24 range 0 stop '192.168.189.250'


Raw Parameters
""""""""""""""

* Override static-mapping's dns-server with a custom one that will be sent only
  to this host.
* An option that takes a quoted string is set by replacing all quote characters
  with the string ``&quot;`` inside the static-mapping-parameters value.
  The resulting line in dhcpd.conf will be
  ``option pxelinux.configfile "pxelinux.cfg/01-00-15-17-44-2d-aa";``.


.. code-block:: none

  set service dhcp-server shared-network-name dhcpexample subnet 192.0.2.0/24 static-mapping example static-mapping-parameters "option domain-name-servers 192.0.2.11, 192.0.2.12;"
  set service dhcp-server shared-network-name dhcpexample subnet 192.0.2.0/24 static-mapping example static-mapping-parameters "option pxelinux.configfile &quot;pxelinux.cfg/01-00-15-17-44-2d-aa&quot;;"



Operation Mode
--------------

.. opcmd:: restart dhcp server

   Restart the DHCP server

.. opcmd:: show dhcp server statistics

   Show the DHCP server statistics:

.. code-block:: none

  vyos@vyos:~$ show dhcp server statistics
  Pool           Size    Leases    Available  Usage
  -----------  ------  --------  -----------  -------
  dhcpexample      99         2           97  2%

.. opcmd:: show dhcp server statistics pool <pool>

   Show the DHCP server statistics for the specified pool.

.. opcmd:: show dhcp server leases

   Show statuses of all active leases:

.. code-block:: none

  vyos@vyos:~$ show dhcp server leases
  IP address      Hardware address    State    Lease start          Lease expiration     Remaining   Pool         Hostname
  --------------  ------------------  -------  -------------------  -------------------  ----------  -----------  ---------
  192.0.2.104     aa:bb:cc:dd:ee:ff   active   2019/12/05 14:24:23  2019/12/06 02:24:23  6:05:35     dhcpexample  test1
  192.0.2.115     ab:ac:ad:ae:af:bf   active   2019/12/05 18:02:37  2019/12/06 06:02:37  9:43:49     dhcpexample  test2

.. hint:: Static mappings aren't shown. To show all states, use
   ``show dhcp server leases state all``.

.. opcmd:: show dhcp server leases pool <pool>

   Show only leases in the specified pool.

.. opcmd:: show dhcp server leases sort <key>

   Sort the output by the specified key. Possible keys: ip, hardware_address,
   state, start, end, remaining, pool, hostname (default = ip)

.. opcmd:: show dhcp server leases state <state>

   Show only leases with the specified state. Possible states: all, active,
   free, expired, released, abandoned, reset, backup (default = active)

DHCPv6 Server
=============

VyOS also provides DHCPv6 server functionality which is described in this
section.

Configuration Options
---------------------

.. cfgcmd:: set service dhcpv6-server preference <preference value>

   Clients receiving advertise messages from multiple servers choose the server
   with the highest preference value. The range for this value is ``0...255``.

.. cfgcmd:: set service dhcpv6-server shared-network-name <name> subnet <prefix> lease-time {default | maximum | minimum}

   The default lease time for DHCPv6 leases is 24 hours. This can be changed by
   supplying a ``default-time``, ``maximum-time`` and ``minimum-time``. All
   values need to be supplied in seconds.

.. cfgcmd:: set service dhcpv6-server shared-network-name <name> subnet <prefix> nis-domain <domain-name>

   A :abbr:`NIS (Network Information Service)` domain can be set to be used for
   DHCPv6 clients.

.. cfgcmd:: set service dhcpv6-server shared-network-name <name> subnet <prefix> nisplus-domain <domain-name>

   The procedure to specify a :abbr:`NIS+ (Network Information Service Plus)`
   domain is similar to the NIS domain one:

.. cfgcmd:: set service dhcpv6-server shared-network-name <name> subnet <prefix> nis-server <address>

   Specify a NIS server address for DHCPv6 clients.

.. cfgcmd:: set service dhcpv6-server shared-network-name <name> subnet <prefix> nisplus-server <address>

   Specify a NIS+ server address for DHCPv6 clients.

.. cfgcmd:: set service dhcpv6-server shared-network-name <name> subnet <prefix> sip-server-address <address>

   Specify a :abbr:`SIP (Session Initiation Protocol)` server by IPv6 address
   for all DHCPv6 clients.

.. cfgcmd:: set service dhcpv6-server shared-network-name <name> subnet <prefix> sip-server-name <fqdn>

   Specify a :abbr:`SIP (Session Initiation Protocol)` server by FQDN for all
   DHCPv6 clients.

.. cfgcmd:: set service dhcpv6-server shared-network-name <name> subnet <prefix> sntp-server-address <address>

   A SNTP server address can be specified for DHCPv6 clients.

Address pools
-------------

DHCPv6 address pools must be configured for the system to act as a DHCPv6
server. The following example describes a common scenario.

**Example:**

* A shared network named ``NET1`` serves subnet ``2001:db8::/64``
* It is connected to ``eth1``
* DNS server is located at ``2001:db8::ffff``
* Address pool shall be ``2001:db8::100`` through ``2001:db8::199``.
* Lease time will be left at the default value which is 24 hours

.. code-block:: none

  set service dhcpv6-server shared-network-name 'NET1' subnet 2001:db8::/64 address-range start 2001:db8::100 stop 2001:db8::199
  set service dhcpv6-server shared-network-name 'NET1' subnet 2001:db8::/64 name-server 2001:db8::ffff

The configuration will look as follows:

.. code-block:: none

  show service dhcpv6-server
      shared-network-name NET1 {
          subnet 2001:db8::/64 {
             address-range {
                start 2001:db8::100 {
                   stop 2001:db8::199
                }
             }
             name-server 2001:db8::ffff
          }
      }

Static mappings
^^^^^^^^^^^^^^^

In order to map specific IPv6 addresses to specific hosts static mappings can
be created. The following example explains the process.

**Example:**

* IPv6 address ``2001:db8::101`` shall be statically mapped
* Host specific mapping shall be named ``client1``

.. hint:: The identifier is the device's DUID: colon-separated hex list (as
   used by isc-dhcp option dhcpv6.client-id). If the device already has a
   dynamic lease from the DHCPv6 server, its DUID can be found with ``show
   service dhcpv6 server leases``. The DUID begins at the 5th octet (after the
   4th colon) of IAID_DUID.

.. code-block:: none

  set service dhcpv6-server shared-network-name 'NET1' subnet 2001:db8::/64 static-mapping client1 ipv6-address 2001:db8::101
  set service dhcpv6-server shared-network-name 'NET1' subnet 2001:db8::/64 static-mapping client1 identifier 00:01:00:01:12:34:56:78:aa:bb:cc:dd:ee:ff

The configuration will look as follows:

.. code-block:: none

  show service dhcp-server shared-network-name NET1
     shared-network-name NET1 {
         subnet 2001:db8::/64 {
            name-server 2001:db8:111::111
            address-range {
                start 2001:db8::100 {
                   stop 2001:db8::199 {
                }
            }
            static-mapping client1 {
               ipv6-address 2001:db8::101
               identifier 00:01:00:01:12:34:56:78:aa:bb:cc:dd:ee:ff
            }
         }
      }

Operation Mode
--------------

.. opcmd:: restart dhcpv6 server

   To restart the DHCPv6 server

.. opcmd:: show dhcpv6 server status

   To show the current status of the DHCPv6 server.

.. opcmd:: show dhcpv6 server leases

   Show statuses of all assigned leases:

.. code-block:: none

  vyos@vyos:~$ show dhcpv6 server leases
  IPv6 address   State    Last communication    Lease expiration     Remaining    Type           Pool   IAID_DUID
  -------------  -------  --------------------  -------------------  -----------  -------------  -----  --------------------------------------------
  2001:db8::101  active   2019/12/05 19:40:10   2019/12/06 07:40:10  11:45:21     non-temporary  NET1   98:76:54:32:00:01:00:01:12:34:56:78:aa:bb:cc:dd:ee:ff
  2001:db8::102  active   2019/12/05 14:01:23   2019/12/06 02:01:23  6:06:34      non-temporary  NET1   87:65:43:21:00:01:00:01:11:22:33:44:fa:fb:fc:fd:fe:ff

.. hint:: Static mappings aren't shown. To show all states, use ``show dhcp
   server leases state all``.

.. opcmd:: show dhcpv6 server leases pool <pool>

   Show only leases in the specified pool.

.. opcmd:: show dhcpv6 server leases sort <key>

   Sort the output by the specified key. Possible keys: expires, iaid_duid, ip,
   last_comm, pool, remaining, state, type (default = ip)

.. opcmd:: show dhcpv6 server leases state <state>

   Show only leases with the specified state. Possible states: abandoned,
   active, all, backup, expired, free, released, reset (default = active)

DHCP Relay
==========

If you want your router to forward DHCP requests to an external DHCP server
you can configure the system to act as a DHCP relay agent. The DHCP relay
agent works with IPv4 and IPv6 addresses.

All interfaces used for the DHCP relay must be configured. See
https://wiki.vyos.net/wiki/Network_address_setup.


Configuration
-------------

.. cfgcmd:: set service dhcp-relay interface <interface>

   Enable the DHCP relay service on the given interface.

.. cfgcmd:: set service dhcp-relay server 10.0.1.4

   Configure IP address of the DHCP server

.. cfgcmd:: set service dhcp-relay relay-options relay-agents-packets discard

   The router should discard DHCP packages already containing relay agent
   information to ensure that only requests from DHCP clients are forwarded.

Example
-------

* Use interfaces ``eth1`` and ``eth2`` for DHCP relay
* Router receives DHCP client requests on ``eth1`` and relays them through
  ``eth2``
* DHCP server is located at IPv4 address 10.0.1.4.

.. figure:: /_static/images/service_dhcp-relay01.png
   :scale: 80 %
   :alt: DHCP relay example

   DHCP relay example

The generated configuration will look like:

.. code-block:: none

  show service dhcp-relay
      interface eth1
      interface eth2
      server 10.0.1.4
      relay-options {
         relay-agents-packets discard
      }

Options
-------

.. cfgcmd:: set service dhcp-relay relay-options hop-count 'count'

   Set the maximum hop count before packets are discarded. Range 0...255,
   default 10.

.. cfgcmd:: set service dhcp-relay relay-options max-size 'size'

   Set maximum size of DHCP packets including relay agent information. If a
   DHCP packet size surpasses this value it will be forwarded without appending
   relay agent information. Range 64...1400, default 576.

.. cfgcmd:: set service dhcp-relay relay-options relay-agents-packet 'policy'

   Four policies for reforwarding DHCP packets exist:

   * **append:** The relay agent is allowed to append its own relay information
     to a received DHCP packet, disregarding relay information already present in
     the packet.

   * **discard:** Received packets which already contain relay information will
     be discarded.

   * **forward:** All packets are forwarded, relay information already present
     will be ignored.

   * **replace:** Relay information already present in a packet is stripped and
     replaced with the router's own relay information set.

Operation
---------

.. opcmd:: restart dhcp relay-agent

   Restart DHCP relay service

DHCPv6 relay
============

Configuration
-------------

.. cfgcmd:: set service dhcpv6-relay listen-interface eth1

   Set eth1 to be the listening interface for the DHCPv6 relay:

.. cfgcmd:: set service dhcpv6-relay upstream-interface eth2 address 2001:db8::4

   Set eth2 to be the upstream interface and specify the IPv6 address of
   the DHCPv6 server:

Example
^^^^^^^

* DHCPv6 requests are received by the router on `listening interface` ``eth1``
* Requests are forwarded through ``eth2`` as the `upstream interface`
* External DHCPv6 server is at 2001:db8::4

.. figure:: /_static/images/service_dhcpv6-relay01.png
   :scale: 80 %
   :alt: DHCPv6 relay example

   DHCPv6 relay example

The generated configuration will look like:

.. code-block:: none

  commit
  show service dhcpv6-relay
      listen-interface eth1 {
      }
      upstream-interface eth2 {
         address 2001:db8::4
      }

Options
-------

.. cfgcmd:: set service dhcpv6-relay max-hop-count 'count'

   Set maximum hop count before packets are discarded, default: 10

.. cfgcmd:: set service dhcpv6-relay use-interface-id-option

   If this is set the relay agent will insert the interface ID. This option is
   set automatically if more than one listening interfaces are in use.

Operation
---------

.. opcmd:: show dhcpv6 relay-agent status

   Show the current status of the DHCPv6 relay agent:

.. opcmd:: restart dhcpv6 relay-agent

   Restart DHCPv6 relay agent immediately.