Debian Codegraph @

doc/antora/modules/howto/pages/protocols/dhcp/policy_network_options.adoc

raw
1 == Configure network-specific options and IP pool selection
2
3 In an environment where multiple networks (often VLANs) are in use, it is
4 necessary to identify which network a client belongs to in order to assign an
5 address from the correct pool.
6
7 Consider the ISC DHCP configuration snippet:
8
9 [source,iscdhcp]
10 ----
11 option domain-name "example.org";
12
13 subnet 10.10.0.0 netmask 255.255.0.0 {
14 range 10.10.1.10 10.10.10.254;
15 range 10.10.100.10 10.10.110.254;
16 option routers 10.10.0.1;
17 option domain-name-servers 10.10.0.2, 10.10.0.3;
18 default-lease-time 7200;
19 }
20 ----
21
22 Or the equivalent Kea configuration:
23
24 [source,isckea]
25 ----
26 "Dhcp4": {
27 "option-data": [
28 { "name": "domain-name", "data": "example.org" }
29 ],
30 "subnet4": [{
31 "subnet": "10.10.0.0/16",
32 "pools": [ { "pool": "10.10.1.10 - 10.10.10.254" },
33 { "pool": "10.10.100.10 - 10.10.110.254" }
34 ],
35 "option-data": [
36 { "name": "routers", "data": "10.10.0.1" },
37 { "name": "domain-name-servers", "data": "10.10.0.2, 10.10.0.3" }
38 ],
39 "valid-lifetime": 7200
40 }],
41 ...
42 }
43 ----
44
45 These define a network consisting of a single subnet 10.10.0.0/16 containing two
46 IP address pools 10.10.1.10 - 10.10.10.254 and 10.10.100.10 - 10.10.110.254.
47 Requests that are determined to have originated from this network (e.g. because
48 their `giaddr` belongs within the subnet) will be assigned the specified DHCP
49 parameters and allocated an address from one of its ranges.
50
51 To provide equivalent functionality, FreeRADIUS must identify the correct DHCP
52 reply parameters as well as the name of the pool to be used for IP address
53 assignment, based on the originating network of the request.
54
55 The definition for this pool (the addresses contained within it, corresponding
56 to the `range` statement in ISC DHCP and Kea) is specified entirely in the
57 database: It is precisely the rows in the `dhcpippool` table with a particular
58 `pool_name`.
59
60 [TIP]
61 ====
62 As described previously, in FreeRADIUS a pool is a set of IP addresses that are
63 equally valid with respect to the network policy; therefore, unlike ISC DHCP
64 and ISC Kea, FreeRADIUS does not differentiate between the two `range`s.
65 Instead we should have previously populated a single pool containing all of the
66 IP addresses from both ranges.
67 ====
68
69 FreeRADIUS derives a request attribute called `DHCP-Network-Subnet` which
70 honours the standard DHCP process for designating the choice of network, in
71 order of preference:
72
73 1. Link Selection Suboption of Option 82
74 2. IPv4 Subnet Selection Option
75 3. Gateway IP Address ("giaddr")
76 4. Client IP Address ("ciaddr", only set for unicast packets)
77
78 If `DHCP-Network-Subnet` contains an IP address then this should be used as
79 the basis of choosing a network. When there is no address in this attribute it
80 can be assumed that the packet has been received from a client on the local
81 LAN.
82
83 The `files` module in FreeRADIUS provides a simple method to map
84 `DHCP-Network-Subnet` to the corresponding pool based on its network
85 membership, setting the appropriate options to return to clients. It can also
86 set the global options.
87
88 [TIP]
89 ====
90 In the case where an instance of the `files` module is used to get global
91 default parameters, the `dhcp_common` policy becomes redundant so the
92 statement calling the policy (by name) can be commented out in
93 `<raddb>/sites-enabled/dhcp`.
94 ====
95
96 To use the provided example `files` module instance for DHCP, symlink or copy
97 `<raddb>/mods-available/dhcp_files` into `<raddb>/mods-enabled/` and then
98 uncomment the calls to `dhcp_network` in `<raddb>/sites-enabled/dhcp`.
99
100 A template configuration file `<raddb>/mods-config/files/dhcp` is also
101 provided which should be adapted to suit your network topology.
102
103 For the configuration above you may deduce the following configuration, which
104 has been extended to include an initial default section for requests originating
105 from directly-connected clients on the local LAN (192.168.20/24):
106
107 [source,config]
108 ----
109 network Pool-Name := "local"
110 DHCP-Domain-Name := "example.org",
111 DHCP-Subnet-Mask := 255.255.255.0,
112 DHCP-Router-Address := 192.168.20.1,
113 DHCP-Domain-Name-Server := 192.168.20.2,
114 Fall-Through := yes
115
116 network DHCP-Network-Subnet < 10.10.0.0/16, Pool-Name := "remote"
117 DHCP-Subnet-Mask := 255.0.0.0,
118 DHCP-Router-Address := 10.10.0.1,
119 DHCP-Domain-Name-Server := 10.10.0.2,
120 DHCP-Domain-Name-Server += 10.10.0.3,
121 DHCP-IP-Address-Lease-Time := 7200
122 ----
123
124 Each block in the file starts with a line beginning with the key to be matched.
125 In this case the keyword of `network` (defined earlier in `dhcp_networks`
126 configuration) is used for each block, so each of the above blocks is a
127 candidate during the search.
128
129 There may be further filtering of the candidates in the form of `<Attribute>
130 <op> <Value>`. In the case of the second block we match the
131 `DHCP-Network-Subnet` to an enclosing subnet with
132 `DHCP-Network-Subnet < <subnet>`. Additional filters could be added as
133 required, comma separated.
134
135 Following the filters on the first line, attributes in the `control` list can
136 be set using the syntax of `<Attribute> := <Value>`. In this example this is
137 used to specify the `Pool-Name` for choosing the appropriate IP pool to
138 allocate an address from.
139
140 Subsequent indented lines are attribute assignments for values in the `reply`
141 list. Note that, apart from the last line, they are all terminated with a
142 comma.
143
144 The special option `Fall-Through` determines whether, following a match,
145 other records are checked for a match. All lookups will match the entry
146 with a key of `network` and no further filtering, so `Fall-Through`
147 is set on that record in order that the other records will be tested
148 to find subnet matches.
149
150 === Example packet processing
151
152 For our example, we consider a request arriving from a DHCP relay within
153 10.10.0.0/16. In the absence of any specific DHCP subnet selection options in
154 the request, the `DHCP-Network-Subnet` attribute is calculated to be the
155 relay's IP address, say 10.10.0.1.
156
157 The request is matched against the first block, setting an initial pool name to
158 "local", domain name to "example.org" and setting some additional global
159 default parameters. By virtue of `Fall-Through` being set, the next block is
160 considered.
161
162 Since the network identifier is within the specified subnet (i.e. `10.10.0.1 <
163 10.10.0.0/16`) this second block is matched. This block overrides the pool name
164 setting it to "remote", overrides some other global defaults and sets the lease
165 time to 7200 seconds. `Fall-Through` is not set, so we are now done with
166 deriving the pool name and network options.
167
168 When the `dhcp_sqlippool` module is called during DHCP DISCOVER processing (in
169 `<raddb>/sites-enabled/dhcp`) the `remote` pool will be used for IP address
170 allocation.
171
172 The assigned IP address and network parameters will subsequently be returned in
173 the DHCP reply.
174
175 === Testing the pool operation and network-specific options
176
177 Before proceeding further, you should test the operation of the IP pools and
178 ensure that any network-specific reply attributes that you have configured are
179 correctly set in replies.
180
181 For example, if you have a single, flat pool you should test using sample
182 packets for devices with different MAC addresses and/or Client Identifiers.
183
184 [source,shell]
185 ----
186 cat <<EOF > dhcp-packet-1.txt
187 DHCP-Message-Type := DHCP-Discover
188 DHCP-Client-Hardware-Address := 02:01:11:11:11:11
189 DHCP-Client-Identifier := device1
190 EOF
191 ----
192
193 [source,shell]
194 ----
195 cat <<EOF > dhcp-packet-2.txt
196 DHCP-Message-Type := DHCP-Discover
197 DHCP-Client-Hardware-Address := 02:01:22:22:22:22
198 DHCP-Client-Identifier := device2
199 EOF
200 ----
201
202 Generate these packets as show previously using the dhcpclient tool and look
203 for `DHCP-Your-IP-Address` in the DHCP responses to determine the IP address
204 that has been offered.
205
206 Ensure that the DHCP Offer responses contain unique IP addresses. Ensure that
207 when these requests are resent within the lifetime of the initial offer that
208 the reponses to the subsequent replies contain the original IP address that was
209 in the initial offer to the device.
210
211 Additionally, ensure that the DHCP Offers contain any network-specific
212 parameters that you have specified.
213
214 In the case that the policy contains multiple IP pools and network definitions
215 for clients belonging to different Layer 2 networks (or indeed belonging to the
216 same network but segregated according to some local policy) you should ensure
217 that the devices are being mapped to the correct definition.
218
219 For a typical policy that selects the IP pool and network options based on the
220 originating network for the DHCP packet, explicitly specifying a network by
221 including a `DHCP-Subnet-Selection-Option` parameter may avoid the need to test
222 from a host within each individual network:
223
224 [source,shell]
225 ----
226 cat <<EOF > dhcp-packet-network-10.10.10.0.txt
227 DHCP-Message-Type := DHCP-Discover
228 DHCP-Client-Hardware-Address := 02:01:aa:bb:cc:dd
229 DHCP-Client-Identifier := abc123
230 DHCP-Subnet-Selection-Option := 10.10.10.0
231 EOF
232 ----
233
234 For policies where the IP pool and network option selection is based on some
235 custom criteria it is necessary to include different variations for the
236 parameters on which the policy makes the decision. The testing example for the
237 class-specific options later in this document provides such an example.