Warning: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in ..../includes/class_bbcode.php on line 2958
Avahi + BIND Dynamic DNS server
Results 1 to 4 of 4
  1. #1

    Default Avahi + BIND Dynamic DNS server

    Warning: The majority of this post is unexplained code and config. The uninitiated shall enter at their own risk and I shall not be liable for any head explosions or other damages.

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    Last week, my Qwest gateway/router went out and I replaced it with an ancient D-Link that doesn't resolve local domain names. Many applications on my network depend on local DNS, so I decided to set up BIND on my HTPC. Initially, this was done using static IP addresses and a static zone file.

    This morning, after having no sleep last night (I stayed up working on a Tumblr layout), I figured out this cool thing you can do with Avahi:
    Code:
    $ avahi-browse -prt _workstation._tcp
    +;eth0;IPv4;travis\032\09148\0585b\05839\05863\05883\05891\093;Workstation;local
    +;eth0;IPv4;htpc\032\09100\05813\05872\05831\058e6\058a0\093;Workstation;local
    =;eth0;IPv4;travis\032\09148\0585b\05839\05863\05883\05891\093;Workstation;local;travis.local;192.168.0.101;9;
    =;eth0;IPv4;htpc\032\09100\05813\05872\05831\058e6\058a0\093;Workstation;local;htpc.local;192.168.0.103;9;
    So yeah, a parsable list of workstations on the network, their domain names, and their IPs. But how do we get this information to the DNS server?

    I ended up writing a cron script (in PHP, lol). The implementation is horrible due to my sleep deprivation but you can get the general idea from this:
    Code:
    #!/usr/bin/php
    
    <?php
    $avahidata = explode("\n",`avahi-browse -ptr _workstation._tcp`);
    
    $hosts="server localhost\nzone local\n";
    $pointers="server localhost\nzone 0.168.192.in-addr.arpa\n";
    
    $oldhosts="server localhost\nzone local\n";
    $oldpointers="server localhost\nzone 0.168.192.in-addr.arpa\n";
    
    for($i=0;$i<count($avahidata)-1;$i++){
            $hostInformation=explode(";",$avahidata[$i]);
            if($hostInformation[0] != "=") continue;
    
            $hostname=$hostInformation[6];
            $hostaddr=$hostInformation[7];
            $ptraddr=implode(".",array_reverse(explode(".",$hostaddr)));
    
            $hosts.="update add $hostname 2400 A $hostaddr\n";
            $pointers.="update add $ptraddr.in-addr.arpa 2400 PTR $hostname\n";
    
            $oldhosts.="update delete $hostname A\n";
            $oldpointers.="update delete $ptraddr.in-addr.arpa PTR\n";
    }
    
    $hosts.="send\n";
    $pointers.="send\n";
    
    $oldhosts.="send\n";
    $oldpointers.="send\n";
    
    echo `cat .dns_purge_hosts | nsupdate`;
    echo `cat .dns_purge_pointers | nsupdate`;
    
    echo `echo "$hosts" | nsupdate`;
    echo `echo "$pointers" | nsupdate`;
    
    file_put_contents(".dns_purge_hosts",$oldhosts);
    file_put_contents(".dns_purge_pointers",$oldpointers);
    
    ?>
    Now, of course BIND is configured to allow updates from localhost...
    Code:
    acl lan { 192.168.0/24; 127.0.0.1; };
    
    options {
            directory "/var/named";
            pid-file "/var/run/named/named.pid";
            auth-nxdomain yes;
            datasize default;
            listen-on { any; };
            forward first;
            forwarders {
                    8.8.8.8;
                    8.8.4.4;
            };
    };
    
    zone "local" {
            type master;
            file "local.zone";
            check-names ignore;
            allow-transfer { lan; };
            allow-update { lan; };
    };
    
    zone "0.168.192.in-addr.arpa" {
            type master;
            file "0.168.192.in-addr.arpa.zone";
            check-names ignore;
            allow-transfer { lan; };
            allow-update { lan; };
    };
    Now, the cron script runs every minute, which isn't really a problem since it doesn't use many resources. Everything works fine and here's some output from BIND to prove it.
    Code:
    23-Dec-2010 07:47:02.266 client 127.0.0.1#50731: updating zone 'local/IN': deleting rrset at 'travis.local' A
    23-Dec-2010 07:47:02.266 client 127.0.0.1#50731: updating zone 'local/IN': deleting rrset at 'htpc.local' A
    23-Dec-2010 07:47:02.643 client 127.0.0.1#44082: updating zone '0.168.192.in-addr.arpa/IN': deleting rrset at '101.0.168.192.in-addr.arpa' PTR
    23-Dec-2010 07:47:02.643 client 127.0.0.1#44082: updating zone '0.168.192.in-addr.arpa/IN': deleting rrset at '103.0.168.192.in-addr.arpa' PTR
    23-Dec-2010 07:47:02.731 client 127.0.0.1#61526: updating zone 'local/IN': adding an RR at 'travis.local' A
    23-Dec-2010 07:47:02.732 client 127.0.0.1#61526: updating zone 'local/IN': adding an RR at 'htpc.local' A
    23-Dec-2010 07:47:02.832 client 127.0.0.1#19283: updating zone '0.168.192.in-addr.arpa/IN': adding an RR at '101.0.168.192.in-addr.arpa' PTR
    23-Dec-2010 07:47:02.833 client 127.0.0.1#19283: updating zone '0.168.192.in-addr.arpa/IN': adding an RR at '103.0.168.192.in-addr.arpa' PTR
    And now I can successfully look up other hosts on the network.
    Code:
    $ nslookup htpc
    Server:		192.168.0.103
    Address:	192.168.0.103#53
    
    Name:	htpc.local
    Address: 192.168.0.103

  2. #2
    Join Date
    May 2006
    Location
    Eta Carinae
    Posts
    19,660
    Blog Entries
    7

    Default

    nice fix there. I usually just have an extra router lying around in case my current ones can't resolve IPs or domains and it has happened before. What you did was pretty creative. I would be lazy.
    Do not PM me regarding your problems or suggestions for the board unless you are offering me money. I will Ignore your posts and if you bother me too much, you will be banned.

    ►Easy Programming | My Youtube
    ►Naztronomy :: Astrophotography | Custom Computers

  3. #3

    Default

    Last night I modified this system to keep track of machines in MySQL so no unnecessary adds or deletes are sent to the DNS server.

  4. #4
    Join Date
    Sep 2013
    Posts
    1

    Thumbs Up

    Quote Originally Posted by leica View Post
    Last night I modified this system to keep track of machines in MySQL so no unnecessary adds or deletes are sent to the DNS server.
    howdy. this is a cool tip. just what i've been looking for.

    any chance you could share the MySQL enhancement?

    Thanks!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. My Dynamic Sig =)
    By Joshuah in forum Graphics
    Replies: 10
    Last Post: 01-27-2008, 07:10 AM
  2. EA & The Weather Channel..."Dynamic Gaming"
    By Scott in forum General Gaming
    Replies: 1
    Last Post: 08-14-2007, 03:53 PM
  3. [PHP GD] make your own dynamic Avatar =D
    By Thor Erik in forum Post Anything
    Replies: 16
    Last Post: 04-05-2007, 07:49 AM
  4. Free Dynamic Avatar
    By Thor Erik in forum General Computer Talk
    Replies: 2
    Last Post: 09-13-2006, 06:51 PM
  5. [m]: Free Dynamic Avatar
    By LiNuX in forum Websites & Advertising
    Replies: 0
    Last Post: 09-13-2006, 06:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

» Site Navigation

» Log in

User Name:

Password:

» Recent Threads

Favorite childhood game
08-01-2011 10:53 AM
by Mizel
Last Post By Keith Forsey
08-14-2017 05:46 AM
Direction Of GF
08-11-2017 07:18 AM
by Slay
Last Post By Slay
08-11-2017 07:23 AM
I guess this is a goodbye
07-08-2016 06:33 PM
Last Post By Slay
08-11-2017 06:55 AM

» Sponsors