View Full Version : [all variants] editing dhcpd.conf using shell or perl script

June 23rd, 2008, 10:22 AM

I have setup a network at my workplace. We have around 10 PCs in the network, the dhcp server is running on Ubuntu 8.04 - server edition.

I want to reserve the ip addresses based on the MAC addresses of clients. I have a list of hostnames and thier MAC addresses ready. We are expecting a few more machines in some time.

I dont want to spend entire day, writing the same configuration lines over and over again. (not to mention time needed for debugging to correct for a small typo :-( )

So, can someone help me out in writing a perl/shell script which can read these details from a text/csv file and modify the dhcpd.conf file, in a properly formatted fashion?

Can someone help me?

Thanks for your time..

June 26th, 2008, 09:02 PM
The general form of the part of the dhcp.conf file I think you want to look at is:

host atlantis {
hardware ethernet 00:11:22:33:44:55;

So if you had a file of the form:

A simple perl script would be like this, off the top of my head:

#/usr/bin/perl -n

@items = split /,/;
print "host $items[0] {
hardware ethernet $items[1];
fixed-address $items[2];

Understand that you would still have to set up things like logging, subnets, and ddns updates.

Hope this helps.