$dayjob uses a Microsoft server for DHCP. Not really a problem, except out of the box, the (K)Ubuntu dhcp client (dhclient3) doesn’t actually support option 249 – classless-static-routes (or ms-classless-static-routes as some sites on the net refer to it). The format that the MS DCHP server spits out is the mask, followed by the subnet, followed by the gateway, in hexidecimal, delimited with colons.

So, after a bit of digging around on the net, and not finding anything that useful, I rolled my own code to deal with it. It’s not pretty, it’s probably not efficient, but it certainly works (for me).

First off, a new file in /etc/dhcp3/dhclient-exit-hooks.d


function process_routes() {
 perl /etc/dhcp3/perl-classless.pl $1 $interface
if [ "$reason" = "BOUND" ]
 echo "ms_classless_static_routes = $new_ms_classless_static_routes"
 process_routes $new_ms_classless_static_routes

Second, a perl script


# Input line will be a long hex string, seperated by :s
# MS DHCP feeds us Class : SN : SN : SN : SN : RT : RT : RT : RT
$unit = '[dw]{1,2}';
$in = $ARGV[0];
$nic = $ARGV[1];
while ($in =~ m/($unit:$unit:$unit:$unit:$unit:$unit:$unit:$unit:$unit)/) {
 $match = $1;
 $in =~ s/$match://;
 @i = split(/:/, $match);
 $exec = sprintf("ip route add to unicast %d.%d.%d.%d/%d via %d.%d.%d.%d dev %s",
 print $exec . "n";

Presto, working Microsoft classless static routes via DHCP.

Dhclient3 and MS DHCP classless static routes
Tagged on: