DNS data from Standalone servers to Primary DNS server

Discussion in 'Tips/Tricks/Mods' started by SamTzu, Nov 1, 2009.

  1. SamTzu

    SamTzu Active Member

    Here is a short PHP script that allows a 'master' DNS server to collect DNS data from other StandAlone ISPConfig3 servers.

    To setup a system that allows 1 (one) or more stripped down ISPConfig3/MyDNS servers to act as 'primary' DNS servers. This way clients can keep their own DNS up-to-date them selves while the Primary DNS server (in our case NS3) collects that DNS data from different ISPConfig3 (standalone) servers.

    You can also add other DNS servers to make sure the data replicated to primary NS1 and NS2 servers is 'whole.' (NS3 wipes all DNS data from it's tables before it collects the new DNS data from other stand alone servers - so using it as a NS1 is not a good idea.) This collected data can then be 'replicated' to NS1 and NS2 using simple MySQL script or 'normal' ISPConfig3 methods. You can run this script on ns3 using command php -q dns.php or by simply adding it to cron with command crontab -e

    Edit: Code edited 2010.05.29
    Script no longer stops if one of the queried servers is down but just skips that server.

    PHP DNS sync code to run in NS3:
    SQL command to run in standalone ISPConfig3 serverX and/or serverY, etc:
    Known problems:
    1. If client in serverX enters a domain that belongs to serverY client, they can possibly cause problems with the 'original' domains name resolution.
    FIXED - 2. If the serverX has not run the SQL command to enable ns3 to read it's DNS related tables the script will be unable to complete.

    Optional scripts to help run the PHP DNS sync code and keep DNS script backup and logfile:

    This is script is run hourly by crontab: (Or you can test the script manually with this command.)
    php -q /etc/dns/test-ns.php > /dev/null 1>> /var/log/dns-script.log


    Attached Files:

    Last edited: May 29, 2010
  2. Franz

    Franz Member

    First fetch data from master server then truncate and insert new data into table.

    what if you can not connect to master database.
    dns data will be deleted.
  3. SamTzu

    SamTzu Active Member

    The code has been edited so that the personally created local Zones from 0-1000 would not be overwritten by the script.
    Last edited: Nov 4, 2009
  4. Niels

    Niels New Member

    How does the script tells the server that there are now entrys in the database? When are the entry visible?
  5. SamTzu

    SamTzu Active Member

    The script does not tell anything to any server. The script can be run on ns3 every hour to check the ISPConfig3 MyDNS zones and records on serverX, serverY etc.

    The script will simply collect that DNS data to ns3 where the script is run hourly by cron.

    It seems to work quite nicely. There are some limits to how many servers can be included in the script but as it stands now every server can have up to a thousand records that can be collected from up to a thousand servers.
    (I did not calculate that my self and confirmation from someone who can code would be nice.)
    Last edited: Nov 15, 2009
  6. Niels

    Niels New Member

    So each server runs a job every hour and this job are using data form database? I would prefer if the master dns server copied data TO the other dns-servers.

    Hm.... need to learn some php again :)
  7. SamTzu

    SamTzu Active Member

    That way you would have to do ALL the work on the Zones and Records.
    Our way is much more Admin friendly. This script provides a change to collect ALL DNS data to central location AND delegate that work to the client.
    Win/Win scenario.

    PS. By definition of MASTER server I mean NS1, NS2 & NS3. Not serverX, serverY & serverZ.
  8. Niels

    Niels New Member

    Got the point... I have decided to have ns1 and ns2 as small servers (5 GB) and have an application server with phpmyadmin, webmail and ispconfig. Then I need to copy all dns data from app-server to ns1 and ns2...

Share This Page