DHCP Server
VyOS uses ISC DHCP server for both IPv4 and IPv6 address assignment.
IPv4 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
Create DNS record per client lease, by adding clients to /etc/hosts file. Entry will have format: <shared-network-name>_<hostname>.<domain-name>
Will drop <shared-network-name>_ from client DNS record, using only the host declaration name and domain: <hostname>.<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).
This is the configuration parameter for the entire shared network definition. All subnets will inherit this configuration item if not specified locally.
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).
This is the configuration parameter for the entire shared network definition. All subnets will inherit this configuration item if not specified locally.
Inform client that the DNS server can be found at <address>.
This is the configuration parameter for the entire shared network definition. All subnets will inherit this configuration item if not specified locally.
Multiple DNS servers can be defined.
When the DHCP server is considering dynamically allocating an IP address to a client, it first sends an ICMP Echo request (a ping) to the address being assigned. It waits for a second, and if no ICMP Echo response has been heard, it assigns the address.
If a response is heard, the lease is abandoned, and the server does not respond to the client. The lease will remain abandoned for a minimum of abandon-lease-time seconds (defaults to 24 hours).
If there are no free addresses but there are abandoned IP addresses, the DHCP server will attempt to reclaim an abandoned IP address regardless of the value of abandon-lease-time.
This configuration parameter lets the DHCP server to listen for DHCP requests sent to the specified address, it is only realistically useful for a server whose only clients are reached via unicasts, such as via DHCP relay agents.
Individual Client Subnet
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.
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>.
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.
Assign the IP address to this machine for <time> seconds.
The default value is 86400 seconds which corresponds to one day.
Create DHCP address range with a range id of <n>. DHCP leases are taken from this pool. The pool starts at address <address>.
Create DHCP address range with a range id of <n>. DHCP leases are taken from this pool. The pool stops with address <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.
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).
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).
When the DHCP server is considering dynamically allocating an IP address to a client, it first sends an ICMP Echo request (a ping) to the address being assigned. It waits for a second, and if no ICMP Echo response has been heard, it assigns the address.
If a response is heard, the lease is abandoned, and the server does not respond to the client. The lease will remain abandoned for a minimum of abandon-lease-time seconds (defaults to 24 hours).
If a there are no free addresses but there are abandoned IP addresses, the DHCP server will attempt to reclaim an abandoned IP address regardless of the value of abandon-lease-time.
Failover
VyOS provides support for DHCP failover. DHCP failover must be configured explicitly by the following statements.
Local IP <address> used when communicating to the failover peer.
Remote peer IP <address> of the second DHCP server in this failover cluster.
A generic <name> referencing this sync service.
Note
<name> must be identical on both sides!
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.
Create a new DHCP static mapping named <description> which is valid for the host identified by its MAC <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 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
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 |
name-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:
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 committing 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 "
. They will be replaced with literal quote characters
when generating dhcpd.conf.
Example
Please see the DHCP/DNS quick-start configuration.
Failover
Configuration of a DHCP failover pair
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
Common configuration, valid for both primary and secondary node.
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 name-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 range 0 start '192.0.2.10'
set service dhcp-server shared-network-name NET-VYOS subnet 192.0.2.0/24 range 0 stop '192.0.2.250'
set service dhcp-server shared-network-name NET-VYOS subnet 192.0.2.0/24 enable-failover
Primary
set service dhcp-server failover source-address '192.168.189.252'
set service dhcp-server failover name 'NET-VYOS'
set service dhcp-server failover remote '192.168.189.253'
set service dhcp-server failover status 'primary'
Secondary
set service dhcp-server failover source-address '192.168.189.253'
set service dhcp-server failover name 'NET-VYOS'
set service dhcp-server failover remote '192.168.189.252'
set service dhcp-server failover status 'secondary'
Raw Parameters
Override static-mapping’s name-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
"
inside the static-mapping-parameters value. The resulting line in dhcpd.conf will beoption pxelinux.configfile "pxelinux.cfg/01-00-15-17-44-2d-aa";
.
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 "pxelinux.cfg/01-00-15-17-44-2d-aa";"
Option 43 for UniFI
These parameters need to be part of the DHCP global options. They stay unchanged.
set service dhcp-server global-parameters 'option space ubnt;'
set service dhcp-server global-parameters 'option ubnt.unifi-address code 1 = ip-address;'
set service dhcp-server global-parameters 'class "ubnt" {'
set service dhcp-server global-parameters 'match if substring (option vendor-class-identifier, 0, 4) = "ubnt";'
set service dhcp-server global-parameters 'option vendor-class-identifier "ubnt";'
set service dhcp-server global-parameters 'vendor-option-space ubnt;'
set service dhcp-server global-parameters '}'
Now we add the option to the scope, adapt to your setup
set service dhcp-server shared-network-name example-scope subnet 10.1.1.0/24 subnet-parameters 'option ubnt.unifi-address 172.16.1.10;'
Operation Mode
vyos@vyos:~$ show dhcp server statistics
Pool Size Leases Available Usage
----------- ------ -------- ----------- -------
dhcpexample 99 2 97 2%
vyos@vyos:~$ show dhcp server leases
IP address Hardware address State Lease start Lease expiration Remaining Pool Hostname
-------------- ------------------ ------- ------------------- ------------------- ---------- ----------- ---------
192.0.2.104 00:53:01: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 00:53:01: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
.
Sort the output by the specified key. Possible keys: ip, hardware_address, state, start, end, remaining, pool, hostname (default = ip)
IPv6 server
VyOS also provides DHCPv6 server functionality which is described in this section.
Configuration
Clients receiving advertise messages from multiple servers choose the server
with the highest preference value. The range for this value is 0...255
.
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.
Prefix Delegation
To hand out individual prefixes to your clients the following configuration is used:
Hand out prefixes of size <length> to clients in subnet <prefix> when they request for prefix delegation.
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 subnet2001:db8::/64
It is connected to
eth1
DNS server is located at
2001:db8::ffff
Address pool shall be
2001:db8::100
through2001:db8::199
.Lease time will be left at the default value which is 24 hours
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:
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 mappedIPv6 prefix
2001:db8:0:101::/64
shall be statically mappedHost 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.
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 ipv6-prefix 2001:db8:0:101::/64
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:
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
Show logs from specific interface DHCPv6 client process.
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
.
Sort the output by the specified key. Possible keys: expires, iaid_duid, ip, last_comm, pool, remaining, state, type (default = ip)