Using Freebsd 9 as seconday nameserver - Update Script

Discussion in 'Tips/Tricks/Mods' started by mmidgett, Feb 17, 2014.

  1. mmidgett

    mmidgett Member

    I am changing my environment to include more FreeBSD servers. I like the ispconfig project but until Ispconfig runs on FreeBSD I am trying to create some work arounds.

    Here is the contents of a script that I run every 10 minuets to take my nameserver config from my Ubuntu 12.04 IspConfig nameserver and make it work on FreeBSD9

    Please don't make fun of me as this is really my first time doing something like this. The only complicated part is the "sed" command where it replaces the text.

    I know the scripts complains about the logout needing to be "exit" but you can't use the exit command or it stops the script. So I left it as works. If you can help me shorten this it would be cool.

    #/.This is going to be script thats a work in progress to replicate
    #the nameserver settings from the default ispconfig nameserver to the 
    #slave freebsd nameservers./
    # This is the variable section for servers names SVBL1 is the primary #nameserver so it will be localhost./
    # Even though we are only using one name I have defined it in this variable
    #This is the Variable that holds the master IP
    echo "copying /etc/bind/named.conf.local from $SVBL1 to temp folder /tmp/nservers"
    cp /etc/bind/named.conf.local /tmp/nserver/named.conf.local
    echo "Addin IN"
    #sed -i 's/" {/" IN {/g' /tmp/nserver/named.conf.local 
    echo "Changing from master to slave record"
    sed -i 's/master/slave/g' /tmp/nserver/named.conf.local
    echo "Adding Master Server IP"
    sed -i 's/";/"; masters {;; };/g' /tmp/nserver/named.conf.local
    echo " replacing /etc/bind with /etc/named/slave for freebsd config"
    sed -i 's/\/etc\/bind/\/etc\/namedb\/slave/g' /tmp/nserver/named.conf.local
    # Removing Allow Transfer and Auto Notify from /named.conf.local before transfer to seconday domain servers
    sed -i 's/allow-transfer {;;;;;};/ /g' /tmp/nserver/named.conf.local
    sed -i 's/also-notify {;;;;;};/ /g' /tmp/nserver/named.conf.local
    echo " Copying new named.conf.local to $SVBL2 at /etc/namedb named.conf.local"
    scp -r /tmp/nserver/named.conf.local $USER@$SVBL2:/etc/namedb/ 
    echo " Copying new named.conf.local to $SVBL3 at /etc/namedb"
    scp -r /tmp/nserver/named.conf.local $USER@$SVBL3:/etc/namedb/ 
    #	Doing Rsync of
    rsync -avz -e ssh --progress /etc/bind/pr* $USER@$SVBL3:/etc/namedb/slave/
    ssh  $USER@$SVBL3 /sbin/./dns-perm && logout
    rsync -avz -e ssh --progress /etc/bind/pr* $USER@$SVBL2:/etc/namedb/slave/
    ssh  $USER@$SVBL2 /sbin/./dns-perm && logout
    #scp /etc/bind/pri* $USER@$SVBL2:/etc/namedb/slave/
    #scp /etc/bind/pri* $USER@$SVBL3:/etc/namedb/slave/
    echo "Restarting Bind Service on $SVBL2"
    ssh $USER@$SVBL2  /etc/rc.d/named reload && logout
    echo "Restarting Bind Service  on $SVBL3"
    ssh $USER@$SVBL3  /etc/rc.d/named reload  && logout
    echo "End of Script"
    Also you will need to make a script in /sbin. I named mine dns-perm but you can change yours to what ever you like.
    # This scrip fixed permissions on the dns directorys that get
    # messed up from copying zone files from my primary linux nameserver
    chown -R bind:wheel /etc/namedb/slave
    chmod -R 0755 /etc/namedb/slave
    /etc/rc.d/named restart
    Last edited: Feb 17, 2014
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    The dns part of ispconfig should work on freebsd, as dns is not os specific. I havent tested this, but the following setup should work:

    1) install php, mysql and bind on the freebsd server
    2) create a new dbispconfig mysql database on the freebds server.
    3) on the master server, make a copy of the record of the primary dns server in the server table, so that it gets the next free server_id. Then set it under syszem > server services as a mirror of the primary dns server. Then add a mysql user (with phpmyadmin) on the master server that has access to the dbispconfig database from the new freebsd server.
    4) copy /usr/local/ispconfig from a ispconfig server to the freebsd server and edit the file /usr/local/ispconfig/server/lib/ and change values for the localhost mysql login, the remote mysql login and the server ID to match the values that we creatd in 1-3.
    5) get the ispconfig cronjobs with;

    crontab -l

    on a linux server and create the same ones on the freebsd server.
  3. mmidgett

    mmidgett Member

    I will test what you have shown me with another VM in a night or two. I know what I have done is more like a hack but I also don't have to run as much ram. I think my primary NS has 2Gb configured and has used about 1.5. My freebsd setup has 1G configured and us using less than 512 as the only service on the box is ssh and bind I just upgraded my ports tree and noticed that bind 10 is ready so I will be testing with it very soon.

    Instead of me calling my script with cron wouldn't it be better to add it to the tail end of the dns script that ispconfig calls when it pulls down info from the DB. That way when someone chages a dns setting the script just gets called. I also am thinking that I can modify the current ispconfig script to write our the files the way that I need them and just store them somewhere other than where the default bind is. Then its just moving the files and setting the correct permissions on them. No more sed to add or remove text. What do you think?
  4. till

    till Super Moderator Staff Member ISPConfig Developer

    instead of modifying the ispconfig bind script, just make a copy of the bind plugin and store it under a different name (and edit the class name inside to match the new name) and activate it with a symlink in plugins-enabled directory. Then edit the code so that it writes your custom config. So the original plugin will write the config as usual and your new plugin writes the config for the additional server. the benefit is that this is update save, as your second plugin will not get overwritten on updates.

    You can attach as many plugins to an event like dns_inser or dns_update as you need in ispconfig. they will all executed one after another, in alphabetic order of the plugin file names.

Share This Page