| 1 |
== Testing the DHCP service |
| 2 |
|
| 3 |
We can verify that FreeRADIUS is providing a DHCP service using the |
| 4 |
`dhcpclient` tool that is included with the FreeRADIUS distribution. |
| 5 |
|
| 6 |
Temporarily configure FreeRADIUS to issue a single static IP address to all |
| 7 |
clients by updating the `dhcp DHCP-Discover` section in the `dhcp` virtual |
| 8 |
server to include the following: |
| 9 |
|
| 10 |
[source,unlang] |
| 11 |
---- |
| 12 |
update reply { |
| 13 |
&DHCP-Your-IP-Address := 1.2.3.4 |
| 14 |
} |
| 15 |
---- |
| 16 |
|
| 17 |
Define a sample DHCP packet as follows: |
| 18 |
|
| 19 |
[source,shell] |
| 20 |
---- |
| 21 |
cat <<EOF > dhcp-packet.txt |
| 22 |
DHCP-Message-Type := DHCP-Discover |
| 23 |
DHCP-Client-Hardware-Address := 02:01:aa:bb:cc:dd |
| 24 |
DHCP-Client-Identifier := abc123 |
| 25 |
EOF |
| 26 |
---- |
| 27 |
|
| 28 |
We can now generate this packet by invoking one of the following commands based |
| 29 |
on the current circumstances... |
| 30 |
|
| 31 |
From the host that is running the FreeRADIUS DHCP server: |
| 32 |
|
| 33 |
[source,shell] |
| 34 |
---- |
| 35 |
dhcpclient -i lo 255.255.255.255 -f dhcp-packet.txt -x auto |
| 36 |
---- |
| 37 |
|
| 38 |
From a different host with an interface (eth0) in the same broadcast domain |
| 39 |
as the FreeRADIUS DHCP server: |
| 40 |
|
| 41 |
[source,shell] |
| 42 |
---- |
| 43 |
dhcpclient -i eth0 255.255.255.255 -f dhcp-packet.txt -x auto |
| 44 |
---- |
| 45 |
|
| 46 |
If all of the DHCP broadcast traffic in other Layer 2 networks is converted to |
| 47 |
unicast by DHCP relay agents then it is not necessary for FreeRADIUS to listen |
| 48 |
on a broadcast address. In this case you can test DHCP using a unicast request: |
| 49 |
|
| 50 |
[source,shell] |
| 51 |
---- |
| 52 |
dhcpclient 192.0.2.10 -f dhcp-packet.txt -x auto |
| 53 |
---- |
| 54 |
|
| 55 |
[NOTE] |
| 56 |
==== |
| 57 |
In order for the returned, unicast DHCP OFFER to be received it is necessary to |
| 58 |
ensure that the `DHCP-Your-IP-Address` parameter set by FreeRADIUS matches an |
| 59 |
address on the interface used by the dhcpclient tool to send the Discover |
| 60 |
packet. |
| 61 |
==== |
| 62 |
|
| 63 |
When one of the above commands is run, the tool with generate output such as |
| 64 |
the following which shows that the packet was sent and that it is now waiting |
| 65 |
for replies: |
| 66 |
|
| 67 |
.Example output from dhcpclient showing the request |
| 68 |
=================================================== |
| 69 |
dhcpclient: ... |
| 70 |
---------------------------------------------------------------------- |
| 71 |
DHCP-Opcode = 0x01 |
| 72 |
DHCP-Hardware-Type = 0x01 |
| 73 |
DHCP-Hardware-Address-Length = 0x06 |
| 74 |
DHCP-Hop-Count = 0x00 |
| 75 |
DHCP-Transaction-Id = 0x5e0bbfab |
| 76 |
DHCP-Number-of-Seconds = 0x0000 |
| 77 |
DHCP-Flags = 0x0000 |
| 78 |
DHCP-Client-IP-Address = 0x00000000 |
| 79 |
DHCP-Your-IP-Address = 0x00000000 |
| 80 |
DHCP-Server-IP-Address = 0x00000000 |
| 81 |
DHCP-Gateway-IP-Address = 0x00000000 |
| 82 |
... |
| 83 |
---------------------------------------------------------------------- |
| 84 |
Waiting for DHCP replies for: 5.000000 |
| 85 |
---------------------------------------------------------------------- |
| 86 |
=================================================== |
| 87 |
|
| 88 |
|
| 89 |
Each received DHCP response will generate output such as the following: |
| 90 |
|
| 91 |
.Example output from dhcpclient showing a response |
| 92 |
================================================== |
| 93 |
... |
| 94 |
---------------------------------------------------------------------- |
| 95 |
DHCP-Opcode = Server-Message |
| 96 |
DHCP-Hardware-Type = Ethernet |
| 97 |
DHCP-Hardware-Address-Length = 6 |
| 98 |
DHCP-Hop-Count = 0 |
| 99 |
DHCP-Transaction-Id = 1577828267 |
| 100 |
DHCP-Number-of-Seconds = 0 |
| 101 |
DHCP-Flags = 0 |
| 102 |
DHCP-Client-IP-Address = 0.0.0.0 |
| 103 |
DHCP-Your-IP-Address = 1.2.3.4 |
| 104 |
DHCP-Server-IP-Address = 192.0.2.10 |
| 105 |
DHCP-Gateway-IP-Address = 0.0.0.0 |
| 106 |
DHCP-Client-Hardware-Address = 02:42:0a:00:00:0b |
| 107 |
DHCP-Message-Type = DHCP-Offer |
| 108 |
DHCP-Client-Identifier = 0x616263313233 |
| 109 |
Waiting for additional DHCP replies for: 4.999429 |
| 110 |
... |
| 111 |
================================================== |
| 112 |
|
| 113 |
Examine the DHCP response to ensure that it has the correct message type |
| 114 |
(`DHCP-Offer`, in this case), contains the temporary IP address that you |
| 115 |
configured earlier, i.e. `DHCP-Your-IP-Address = 1.2.3.4`, and any other |
| 116 |
expected reply parameters (which we configure later). You should also carefully |
| 117 |
examine the output of a FreeRADIUS debug session (`radius -X`) to ensure that |
| 118 |
the policy is being executed in the way that you expect and that no warnings |
| 119 |
are being generated. |
| 120 |
|
| 121 |
You can now change the content of the sample DHCP request by editing the |
| 122 |
`dhcp-packet.txt` file and re-run the above command to see the server's reply. |
| 123 |
You should examine the DHCP dictionary distrubuted with FreeRADIUS (usually |
| 124 |
`/usr/share/freeradius/dictionary.dhcp`) which provides the list of all of the |
| 125 |
DHCP parameters ("attributes") understood by FreeRADIUS. |
| 126 |
|
| 127 |
[WARNING] |
| 128 |
==== |
| 129 |
When you are done **remember** to remove the temporary edit that was made to |
| 130 |
the `dhcp` virtual server that provides the static IP assignment. |
| 131 |
==== |
| 132 |
|
| 133 |
=== Testing the DHCP policy |
| 134 |
|
| 135 |
The remainder of this guide describes how to configure the IP address plan, |
| 136 |
setup the IP pools and define a DHCP policy. You should develop your policy by |
| 137 |
making small, incremental changes to the provided configuration and then test |
| 138 |
those changes with the approach described above, using `dhcpclient` and `radius -X`, |
| 139 |
modifying the sample DHCP packet as required. If you break the policy then |
| 140 |
revert the last change, attempt to understand what went wrong, and try |
| 141 |
something else. |
| 142 |
|
| 143 |
Now xref:protocols/dhcp/policy.adoc[define the DHCP policy]. |