Wednesday, June 23, 2010

DHCPD - Classless Static Routing

Ran into an interesting situation where I needed to hand out routes to client machines on one subnet so that they could find the rest of the network.. without being able to provide routes via their gateway (the situation involves deploying dhcp on a network without having control of any devices on that network other than your own).

Luckily, even though they aren't standard (for obvious reasons) there are option codes for distributing classless routes in dhcpd. You just have to define them yourself, and if you want it to work for both unix and windows machines you have to define it twice (ms couldn't just stick to the rfc, that would have been too easy).

under the global definitions in dhcpd.conf, create the following new options:

option rfc3442-classless-static-routes code 121 = array of integer 8;
option ms-classless-static-routes code 249 = array of integer 8;

code 121 is the rfc3442 implementation for distributing static routes other than the default router, and 249 is Microsoft's version of that rfc.

Now that those options are defined we can create the routes themselves in our subnet options as arrays of integers with the pattern:
[netmask, network address byte 1, network address byte 2, network address byte 3, route byte 1, route byte 2, route byte 3, route byte 4]

for example:
option rfc3442-classless-static-routes = 24, 192, 168, 35, 10, 10, 0, 12;
option ms-classless-static-routes = 24, 192, 168, 35, 10, 10, 0, 12;

which provide dhcp clients a route to the 192.168.35.0/24 network via 10.10.0.12.

Victory.