How to configure secondary dns to automatically setup upon normal dns creation

Discussion in 'Installation/Configuration' started by lswebs, Jan 13, 2014.

  1. lswebs

    lswebs New Member

    Well... the title basically says it all.
    I want the secondary dns zone to be automatically set up on server 2 after making a primary dns zone on server 1.
    How can I do this?
     
  2. KoS

    KoS Member HowtoForge Supporter

    my secondary DNS server is not managed by ISPconfig so i created a simple php script that fetches the list of dns domains via the API and creates the corresponding bind files and restarts bind if needed. i can post the scripts if you are interested...
     
  3. till

    till Super Moderator Staff Member ISPConfig Developer

    If both servers are managed by ispconfig, then ispconfig can setup the zones in the secondary dns automatically. All yu have to do is that you set the secondary dns as mirror of the first dns server under System > server config. The setup with 2 mirrored dns servers is described here:

    http://www.howtoforge.com/multiserv...se-servers-on-debian-squeeze-with-ispconfig-3
     
  4. lswebs

    lswebs New Member

    Yes, I have 2 perfect ispconfig servers with everything installed.
    I don't want to mirror everything... just dns... Is this possible?
    Thanks!
     
  5. lswebs

    lswebs New Member

    It is an ispconfig managed server, But if it is not possible in the current configuration I would like to try out your script :)
     
  6. KoS

    KoS Member HowtoForge Supporter

    the first script is a shell script which uses the php script to fetch the domain list and create and bind config. as the script is run by cron regularly, it compares the created file for changes and only moves it to the final location if something has changed. (the script runs on a read-only machine, so for that the remountro/remountrw commands). at the end you find the soap_config.php file.

    have fun :)

    Code:
    #!/bin/bash
    BIND="/etc/bind/"
    DNS_OTTO="named.conf.local.otto"
    RELOAD="NO"
    
    # Get DNS zone list via ISPCONFIG API
    /etc/bind/dns_zone_get.php > /tmp/${DNS}
    exitcode=$?
    if [ $exitcode -ne 0 ] ; then
      echo "error in dns_zone_get.php ($exitcode)"
      exit $exitcode
    elif ! diff -q ${BIND}/${DNS} /tmp/${DNS} > /dev/null ; then
      RELOAD="YES"
    fi
    
    if [ "$RELOAD" == "YES" ] ; then 
    
      remountrw
      mv /tmp/${DNS_OTTO} ${BIND}/${DNS_OTTO}
      /etc/init.d/bind9 restart
      remountro
    fi
    
    rm -rf /tmp/${DNS_OTTO}
    

    Code:
    #!/usr/bin/php
    <?php
    
    require('soap_config.php');
    
    $client = new SoapClient(null, array('location' => $soap_location,
                                         'uri'      => $soap_uri,
                                         'trace' => 1,
                                         'exceptions' => 1)
                                        );
    
    try {
        if($session_id = $client->login($username,$password)) {
            // echo 'Logged successfull. Session ID:'.$session_id.'<br />';
        }
    
        //* Set the function parameters.
        $id = 1;
        $params = array ('id' => '%',
                         'active' => 'Y',
                        );
    
        $dns_record = $client->dns_zone_get($session_id, $params);
    
        foreach($dns_record as $key=>$value) {
          $domain = substr($value['origin'], 0, -1);
    printf('
    zone "%s" {
       type slave;
       file "/var/cache/bind/%s.hosts";
       masters {
          <ip-address-of-master-dns-server>;
       };
    };
    ', $domain, $domain);
    
        }
    
        if($client->logout($session_id)) {
            // echo 'Logged out.<br />';
        }
    
    
    } catch (SoapFault $e) {
        echo $client->__getLastResponse();
        echo 'SOAP Error: '.$e->getMessage();
        die(1);
    }
    
    ?>
    
    Code:
    <?php
    
    $username = 'dns-user';
    $password = 'xxxx';
    
    $soap_location = 'https://ispconfig/remote/index.php';
    $soap_uri = 'https://ispconfig/remote/';
    
    ?>
    
     
  7. lswebs

    lswebs New Member

    Thanks dude!
    However I figured it out, I just put off everything exept dns on my second server and mirrored it, had some errors but was able to resolve all dns related errors. Now just a quota problem and thats it I think :)
    Maybe you should post a tutorial on here on how to install and use your script, I read that you can earn yourself a one year howtoforge subscription ;)
     
    Last edited: Jan 15, 2014

Share This Page