it-slav.se
home
stuff
archives
programming
download
author
contact
links
guestbook
index » archives
Configurating tips and other cool stuff
Here I will share some tips that can be in handy some times.
Not fancy, but yet usefull.
Howto rewind the serial number in DNS
Or it's all about Serial Number Arithmetic.

God forbidden, sometimes someone mess up the serial number and it's need to be fixed.
First the theori.
RFC 1982 says that the serial number is counted this way.

s' = (s + n) modulo (2 ^ SERIAL_BITS)
s' = new serial
s = current serial
n = positiv integer, in range [0 .. (2^(SERIAL_BITS - 1) - 1)]
SERIAL_BITS = in most cases 32

So, we put in some numbers from real life.
Messed up serial, s = 2008032001, in mind 2007 is present year.
We calculate n as 2^(32-1)-1 = 2147483647
s' = ( 2008032001 + 2147483647) modulo (2^32)
s' = 4155515648
Before updating your master, be sure your slaves has the same serial number as the master.
If not, decrease the n value the amout that differs and recalc the new serial.
This is important, otherwise you have got an undefined result.
So, all is ok!
Jump into your DNS and update the serial with 4155515648

And, check your refresh time in the DNS SOA record and wait for at least that time.
Then update your serial with your new number, i.e 2007032101.
Homefree!
Howto to validate an ip address and prefix in bash
This is an elegant way of checking whether an ip address is correct or not.

-------------------- snippet ---------------
# initial data
network="10.1.2.3/24"
prefix=`echo $network | cut -d '/' -f2`
ip=`echo $network | cut -d '/' -f1`

oct1=`echo $ip | cut -d '.' -f1`
oct2=`echo $ip | cut -d '.' -f2`
oct3=`echo $ip | cut -d '.' -f3`
oct4=`echo $ip | cut -d '.' -f4`

# simple check of octets
if [ $oct1 -gt 255 -o $oct2 -gt 255 -o $oct3 -gt 255 -o $oct4 -gt 255 ]
then
  echo -e "Invalid octet, larger than 255"
fi

# simple check of prefix
if [ $prefix -gt 32 ]
then
  echo-e "Invalid prefix, larger than 32"
fi

#so finally it comes

# Check that prefix matches boundary. We convert to an integer and
# divide with the size, i.e. the number of addresses that the
# prefix in case. If the modulo is greater than zero it means that
# boundary is in error.
integer=`echo "$oct1 * 256 * 256 * 256 + $oct2 * 256 * 256 + $oct3 * 256 + $oct4" | bc`
size=`echo "2^(32-$prefix)" | bc`
res=`expr $integer % $size`
if [ $res -gt 0 ]
then
  echo -e "Prefix does not match address"
fi
------------------ end snippet -------------------
it's so beautiful.
Copyright © Svante Victorsson 2007; All rights reserved