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.

6 comments:

  1. Hi again (the same annonymous):
    SOLVED: The syntax must be the following:

    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;

    Thanks anyway

    ReplyDelete
  2. Hi again (the same annonymous):
    The syntax must be the following:
    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;

    Thanks anyway

    ReplyDelete
  3. In Spanish too:
    http://ignoresysprereqs.blogspot.com/2011/05/dhcpd-ruteo-estatico-sin-clase-dhcpd.html:

    ReplyDelete
  4. It's aways good to know...

    Pattern for mask 24 (255.255.255.0):
    [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]
    ex. 24, 192, 168, 35, 10, 10, 0, 12

    For a network wich uses classes other than 24, we must create:

    Pattern for mask 16 (255.255.0.0):
    [netmask, network address byte 1, network address byte 2, route byte 1, route byte 2, route byte 3, route byte 4]
    ex. 16, 192, 168, 10, 10, 0, 12

    Pattern for mask 8 (255.0.0.0):
    [netmask, network address byte 1, route byte 1, route byte 2, route byte 3, route byte 4]
    ex. 16, 192, 10, 10, 0, 12

    As I said, it's aways good to know.

    ReplyDelete
  5. I made a mistake,

    In the example above, for pattern to mask 8, the correct is:

    Pattern for mask 8 (255.0.0.0):
    [netmask, network address byte 1, route byte 1, route byte 2, route byte 3, route byte 4]
    ex. 8, 192, 10, 10, 0, 12

    Sorry for the incovenient.

    ReplyDelete
  6. Just a big thank you for saving me the hassle or having to figure this one out from scratch! THANKS!

    ReplyDelete