A bash script to convert human readable static routes to the format required in dhcpd.conf for Windows® clients.

I manage a few networks with Linux servers and Windows clients, as a number of the networks are interconnected through machines other than the default route I have to manage static routes on the Windows client machines. This on the surface seems easy enough with dhcp, but a couple of the routes use 21 bit masks, and a couple use 26 bit masks. This only seems to be possible with the versions of dhcpd I am using by adding a code 249 option which requires a hex encoded string for the route(s).

For example to add the route through the gateway

The following lines need to be added to the dhcpd.conf file

option new-static-routes code 249 = string;
option new-static-routes 1a:c0:a8:14:40:c0:a8:0a:3e;

(I decided to use the name "new-static-routes" for the option as when trying to figure out how to do this it was in an example listing I found on the web)

When dhcpd has reloaded it's config and a windows client that gets it's ip settings from this server with the address, has the command ipconfig /renew run there will now be the following entry it's
route listing. ( route print or netstat -r -n )

Now we come to the reason for this BASH script, I got tired of doing the conversion of the addresses from decimal to hex in my head, the line above in decimal is pretty simple: 26:192:168:20:64:192:168:10:62; but my mind isn't as agile as it used to be so I have trouble remembering that the bit size comes before the target network, and while I can do the decimal to hex conversion in my head it takes longer than it used to :(

So I created this script, simply pass it the target and gateway in the form tt.tt.tt.tt/bb gg.gg.gg.gg and it returns the hex encoded string.

Add a -v before the target and it returns the entire line needed for dhcpd.conf, add another -v and it also give the code 249 line. You can put as many routes on the line as required (I'm sure there is a limit in dhcpd or windows, but I don't know what that would be (I haven't hit it yet))

examples: (Command, Result)

$ hexroute

$ hexroute -v gw
option new-static-routes 1a:c0:a8:14:40:c0:a8:0a:3e;

$ hexroute -v -v
# New Option Type for Windows Client Static Routes
option new-static-routes code 249 = string;
option new-static-routes 1a:c0:a8:14:40:c0:a8:0a:3e;

$ hexroute -v 
option new-static-routes 1a:c0:a8:14:40:c0:a8:0a:3e:15:ac:10:50:c0:a8:0a:3e;

The script is written for the bash shell, mileage under other shells may vary.
This script can be freely distributed, but please keep the header in the shell script intact.
Download here: hexroute.tgz (teeny tiny at just over 2000 bytes)
Updated: May 10, 2007
Minor correction to script to allow addresses with '255' in them to work properly.
A very useful site if your working with various odd subnets is the Network Calulators page, it is just that, a set of network / subnet etc. calculators 
Karl McMurdo EMail:
XrX Computer Applications

Copyright © 2005-2015 Karl McMurdo