Debian Codegraph @

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

raw
1 == Configure subnet-specific options for shared networks
2
3 In the case that shared-networks are in use, with the pool containing
4 equally-valid IP addresses from multiple subnets, it is necessary to set the
5 subnet-specific parameters such as `DHCP-Router-Address`, `DHCP-Subnet-Mask`
6 and `DHCP-Broadcast-Address` based on the IP address that has been allocated.
7
8 Consider the ISC DHCP configuration snippet:
9
10 [source,iscdhcp]
11 ----
12 option domain-name "example.org";
13
14 shared-network bigdept {
15
16 option domain-name-servers 10.10.0.2, 10.10.0.3;
17 default-lease-time 7200;
18
19 subnet 10.30.10.0 netmask 255.255.255.0 {
20 option routers 10.30.10.1;
21 }
22 subnet 10.30.20.0 netmask 255.255.255.0 {
23 option routers 10.30.20.1;
24 }
25 range 10.30.10.10 10.30.10.254;
26 range 10.30.20.10 10.30.20.254;
27
28 }
29 ----
30
31 Or the equivalent Kea configuration:
32
33 [source,kea]
34 ----
35 "Dhcp4": {
36 "option-data": [
37 { "name": "domain-name", "data": "example.org" }
38 ],
39 "shared-networks": [{
40 "name": "bigdept",
41 "option-data": [
42 { "name": "domain-name-servers", "data": "10.10.0.2, 10.10.0.3" }
43 ],
44 "valid-lifetime": 7200,
45 "subnet4": [{
46 "subnet": "10.30.10.0/24",
47 "pools": [ { "pool": "10.30.10.10 - 10.30.10.254" } ],
48 "option-data": [
49 { "name": "routers", "data": "10.30.10.1" }
50 ]
51 }],
52 "subnet4": [{
53 "subnet": "10.30.20.0/24",
54 "pools": [ { "pool": "10.30.20.10 - 10.30.20.254" } ],
55 "option-data": [
56 { "name": "routers", "data": "10.30.20.1" }
57 ]
58 }]
59 }],
60 ...
61 }
62 ----
63
64 As with the network to pool lookup, an instance of the `files` modules can be
65 employed (this time after the allocation of an IP address) to set the correct
66 reply parameters based on the subnet membership of the assigned address.
67
68 To do this, we can use this section of `<raddb>/mods-available/dhcp_files`:
69
70 [source,config]
71 ----
72 files dhcp_subnets {
73 filename = ${modconfdir}/files/dhcp
74 key = "subnet"
75 }
76 ----
77
78 Additionally, uncomment the `dhcp_subnets` policy in `<raddb>/policy.d/dhcp`.
79 This policy wraps the call to the `dhcp_subnets` files module with code that
80 "tightens" the `DHCP-Network-Subnet` attribute by setting it to the
81 just-allocated IP address.
82
83 The relevant entries in the `<raddb>/mods-config/files/dhcp` configuration
84 file might then look something like this:
85
86 [source,config]
87 ----
88 network
89 DHCP-Domain-Name := "example.org",
90 Fall-Through := yes
91
92 network DHCP-Network-Subnet < 10.30.0.0/16, Pool-Name := "bigdept"
93 DHCP-Domain-Name-Server := 10.10.0.2,
94 DHCP-Domain-Name-Server += 10.10.0.3,
95 DHCP-IP-Address-Lease-Time := 7200
96
97 subnet DHCP-Network-Subnet < 10.30.10.0/24
98 DHCP-Router-Address := 10.30.10.1
99
100 subnet DHCP-Network-Subnet < 10.30.20.0/24
101 DHCP-Router-Address := 10.30.20.1
102 ----
103
104 === Example packet processing
105
106 For our example, we consider a request arriving from a DHCP relay within
107 10.30.10.0/24. In the absence of any specific DHCP subnet selection options in
108 the request, the `DHCP-Network-Subnet` attribute is calculated to be the
109 relay's IP address, say 10.30.10.1.
110
111 The request is matched against the first "network" block, setting the domain
112 name to "example.org". By virtue of `Fall-Through` being set, the next "network"
113 block is considered.
114
115 Since the network identifier is within the specified subnet (i.e. `10.30.10.1 <
116 10.30.0.0/16`) this second "network" block is matched. This block sets the pool
117 name to "bigdept", sets some network-specific DNS resolvers and sets the lease
118 time to 7200 seconds. `Fall-Through` is not set, so we are now done with
119 deriving the pool name and network options.
120
121 When the `dhcp_sqlippool` module is called during DHCP DISCOVER processing (in
122 `<raddb>/sites-enabled/dhcp`) the `bigdept` pool will be used for IP address
123 allocation.
124
125 After IP allocation the `dhcp_subnet` policy and files instance are called.
126 Before the subnet options are looked up the `DHCP-Network-Subnet`
127 attribute is tightened to match the assigned IP address, say 10.30.20.123.
128
129 The request does not match the first subnet block since 10.30.20.123 is not
130 within 10.30.10.0/24. However, the request does match the second subnet block
131 since `10.30.20.123 < 10.30.20.0/24`. This block sets the default gateway
132 reply parameter. `Fall-Through` is not set, so we are now done with deriving
133 the pool name and network options.
134
135 The assigned IP address, network and subnet parameters will subsequently be
136 returned in the DHCP reply.
137
138 === Testing the subnet-specific options
139
140 If you have set any subnet-specific reply parameters then you should test these
141 before proceeding further.
142
143 For example, in the case that you have a single, large pool spanning two IP
144 subnets you might want to test by repeatedly allocating addresses using sample
145 packets with different MAC addresses, each time checking to ensure that the
146 DHCP parameters correspond to the IP address that has been offered.
147
148 .Example output from dhcpclient showing a response
149 ==================================================
150 dhcpclient: ...
151 ...
152 ----------------------------------------------------------------------
153 Waiting for DHCP replies for: 5.000000
154 ----------------------------------------------------------------------
155 ...
156 DHCP-Your-IP-Address = 10.0.10.50
157 DHCP-Router-Address = 10.0.10.1
158 DHCP-Broadcast-Address = 10.0.10.255
159 DHCP-Subnet-Mask = 255.255.255.255
160 ==================================================
161
162
163 .Example output from dhcpclient showing a response
164 ==================================================
165 dhcpclient: ...
166 ...
167 ----------------------------------------------------------------------
168 Waiting for DHCP replies for: 5.000000
169 ----------------------------------------------------------------------
170 ...
171 DHCP-Your-IP-Address = 10.99.99.50
172 DHCP-Router-Address = 10.99.99.1
173 DHCP-Broadcast-Address = 10.99.99.255
174 DHCP-Subnet-Mask = 255.255.255.255
175 ==================================================
176
177
178 [TIP]
179 ====
180 If the subnets are large then you might want to temporarily reduce their
181 size by setting the `status` field of the majority of the rows for each subnet
182 to "`disabled`" to cause offers to be made more readily with IP addresses in
183 different subnets.
184 ====