Nov 282012
 

terminal-icon

Today I had the pleasure to change 150 of our 200 DHCP pools. We had to extend it with an extra option (yea, this was quicker to make the changes by hand instead of writing/figuring out a way to do it by scripting) . When I was done I wanted to ‘quickly’ check my work for (human) errors and came up with the following “quick” check:

#
#$ FTTH XXX customers XXXX
#
subnet 77.x.x.128 netmask 255.255.255.128 {
option subnet-mask 255.255.255.128;
option broadcast-address 77.x.x.255;
option routers 77.x.x.129;
option domain-name "xxxxxxxxx.xx";
option domain-name-servers x.x.x.x, x.x.x.x;
option 6rd 17 41 0x2a02 0x80c0 0xfe00 0 0 0 0 0 x.x.x.2;
pool {
allow members of "max-lease-per-service";
max-lease-time 1810;
default-lease-time 1810;
deny dynamic bootp clients;
range 77.x.x.130 77.x.x.254;
}
}

The 6rd line is the one we added. I wanted to check if specific (networkid/17) pools we all had an 6rd line:

Normally I use grep, so i glanced at the man page and came up with:


[martin@dhcp4a.asd-nh ~]$ grep -A 6 "subnet 77.x." /etc/dhcpd/dhcpd.internet.pools.conf
subnet 77.x.x.x netmask 255.255.255.128 {
option subnet-mask 255.255.255.128;
option broadcast-address 77.x.x.255;
option routers 77.x.x.129;
option domain-name "xxxxxxxxx.xx";
option domain-name-servers x.x.x.x, x.x.x.x;
option 6rd 17 41 0x2a02 0x80c0 0xfe00 0 0 0 0 0 x.x.x.2;
--
etc etc (x 150 blocks)

Only 1/3 of lines to check on your console now. It’s a good start. I learned that grep without using a shell script is not up to this task an went to the stream line editor – sed


[martin@dhcp4a.asd-nh ~]$ sed -n '/subnet 77.x/{p;n;n;n;n;n;n;p}' /etc/dhcpd/dhcpd.internet.pools.conf
subnet 77.x.x.128 netmask 255.255.255.128 {
option 6rd 17 41 0x2a02 0x80c0 0xfe00 0 0 0 0 0 x.x.x.2;
subnet 77.x.x.x.0 netmask 255.255.255.0 {
option 6rd 17 41 0x2a02 0x80c0 0xfe00 0 0 0 0 0 x.x.x.2;
subnet 77.x.x.0 netmask 255.255.254.0 {
option 6rd 17 41 0x2a02 0x80c0 0xfe00 0 0 0 0 0 x.x.x.2;
etc etc (x 150 blocks)

Now i could quickly scroll through the lines and would notice if there was a line which started with the words “subnet” and not with the following line “option 6rd” line. Actually spotted one and fixed it. :)

x.x to protect the guilty.

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Anti-spam image