Page 1 of 1

DNS stop working after 99 DNS record change per day

Posted: Tue Oct 22, 2019 6:50 pm
by pggj
(sory for bad english, not my first language, and a long day at work !)
Hello,
I leave this post because i found a 'bug'. I pose here the problem, the analysis, and the resolution. If a VestaCP developer could incorporate the modification in the source code, it would be useful for many of us!

The problem:
During massive transfer of some of my servers, I have a script that modify DNS configuration record by record on the fly. After a while, the DNS server was falling down, and I had to completely remove the DNS from the domain to recreate it.

Origin of the bug :
After analysis, I concluded that it is the 'serial' attached to the DNS record that was involved. Serial format is YYYMMDDXX where XX is a number incremented each time the DNS configuration is changed. In conclusion, you can not make more than 99 DNS change in one day on a domain.

Solution:
In order to overcome this, I made the following changes:

in file /usr/local/vesta/func/domain.sh :
in function update_domain_zone()

Replace :

Code: Select all

    if [ -z "$SERIAL" ]; then
        SERIAL=$(date +'%Y%m%d01')
    fi
By :

Code: Select all

    if [ -z "$SERIAL" ]; then
        SERIAL=$(date +'%y%m%d0001')
    fi
and replace function update_domain_serial() by this one :

Code: Select all

update_domain_serial() {
    zn_conf="$HOMEDIR/$user/conf/dns/$domain.db"
    if [ -e $zn_conf ]; then
        zn_serial=$(head $zn_conf |grep 'SOA' -A1 |tail -n 1 |sed "s/ //g")
        s_date=$(echo ${zn_serial:0:6})
        c_date=$(date +'%y%m%d')
        if [ "$s_date" == "$c_date" ]; then
            cur_value=$(echo ${zn_serial:6} )
            new_value=$(expr $cur_value + 1 )
            len_value=$(expr length $new_value)
            if [ 1 -eq "$len_value" ]; then
                new_value='000'$new_value
            fi
            if [ 2 -eq "$len_value" ]; then
                new_value='00'$new_value
            fi
            if [ 3 -eq "$len_value" ]; then
                new_value='0'$new_value
            fi
            serial="$c_date""$new_value"
        else
            serial="$(date +'%y%m%d0001')"
        fi
    else
        serial="$(date +'%y%m%d0001')"
    fi
    add_object_key "dns" 'DOMAIN' "$domain" 'SERIAL' 'RECORDS'
    update_object_value 'dns' 'DOMAIN' "$domain" '$SERIAL' "$serial"
}

You will be abe to make up to 9999 DNS change per day and per domain

Hoping it will help !

----------------------
Having issues with your server ? contact me !

Pierre-Guillaume - MathsiMo

Re: DNS stop working after 99 DNS record change per day

Posted: Thu Apr 30, 2020 4:51 am
by jkarlos
Hello!, please change this error:

Code: Select all

if [ 1 -eq "$len_value" ]; then
	new_value=000'$new_value
for:

Code: Select all

if [ 1 -eq "$len_value" ]; then
	new_value='000'$new_value
Thank you!, I really appreciate your work.

Re: DNS stop working after 99 DNS record change per day

Posted: Tue Sep 08, 2020 7:59 pm
by pggj
Thank you for this corection, I directly modified the post :)

Re: DNS stop working after 99 DNS record change per day

Posted: Mon Oct 12, 2020 10:01 am
by skamasle
Nice work, not much people make 99 changes in one domain per day but its ok

I recomend you make a pull request in github or open same issue in github