DNS problems

Because I'm a unique jerk and I write terribly not sloppy and ill-considered code, I managed to leave my hosting machine without access for the whole evening. The problem turned out to be trivially stupid, but who cares in time.

#!/bin/bash -x
wget http://checkip.dyndns.org/ -O /tmp/ipaddr
IPADDR=$(cat /tmp/ipaddr | grep -Eo '\<[[:digit:]]{1,3}(\.[[:digit:]]{1,3}){3}\>')
IPADDROLD=$(cat /tmp/ipaddr_old | grep -Eo '\<[[:digit:]]{1,3}(\.[[:digit:]]{1,3}){3}\>')

if [ "$IPADDR" != "$IPADDROLD"  -a "$IPADDR" != "" ]
 sed -i "s/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/$IPADDR/" /etc/bind/neo2shyalien.eu
 /etc/init.d/bind9 restart
 echo "server localhost" > /tmp/nsupdate
 echo "zone neo2shyalien.eu" >> /tmp/nsupdate
 echo "update delete ns.neo2shyalien.eu. A" >> /tmp/nsupdate
 echo "update delete ns.neo2shyalien.eu. CNAME" >> /tmp/nsupdate
 echo "update add ns.neo2shyalien.eu. 38400 A $IPADDR" >> /tmp/nsupdate
 echo "update add *.neo2shyalien.eu. 38400 CNAME ns.neo2shyalien.eu." >> /tmp/nsupdate
 echo "show" >> /tmp/nsupdate
 echo "send" >> /tmp/nsupdate
 echo "" >> /tmp/nsupdate
 /usr/bin/nsupdate -k /etc/Kns.neo2shyalien.eu.+157+59417.private -d /tmp/nsupdate
 mv /tmp/ipaddr /tmp/ipaddr_old

This is already a fixed script that will not allow an error. In a moment I will explain where the problem was, now I will explain what the script does. At least I'm on a dynamic public ip. I have run the above script to check for a change in my address if it changes to change the machine settings and send information about my domain, that there is a change. Generally a trivial script, but in it I had made a terribly stupid omission. In the part where it is checked for change of address

if [ "$IPADDR" != "$IPADDROLD"  -a "$IPADDR" != "" ]

It used to be

if [ "$IPADDR" != "$IPADDROLD"]

So the line itself does the following, takes the 2nd IP addresses and checks them if they are the same skips if they are different updates. In the previous version I had missed a very important error for some reason my script had decided that I have IP = “” (nothing) and rewrote the configuration of my bind with an empty field and on the next change it can no longer rewrite the configuration correctly which leads to a lack of connection with the nameservr. It's stupid, isn't it?


  1. Не мога да не се въздържа и да не репликирам със следния виц:
    На Иванчо са му дали 3 ябълки.
    Той е изял 2.
    Колко ябълки има Иванчо?
    Мислите си че 1?
    Ама никъде не е казано, колко ябълки е имал Иванчо преди да му дадат 3-те.
    Изводнулирайте си променливите!

    Всички сме ги правили тези грешки, аз няма да забравя, когато цяла зона ми умря заради една долна черта. Вече долнтие черти си ги заменям с тирета и си чета рфц-тата редовно.
    Важното е следващия път варианта с липсващо ай пи да ни е на ум. 🙂

    1. 😀 Дам 12 са били :)))) Ами Мисля че както промених скрипта няма да се осерат нещата. Иначе дам хубаво е човек да си вади поуки и да не пише калпаво с леви крак 😉

Leave a Reply

Your email address will not be published. Required fields are marked *

Anti SPAM *