]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
Got contributed script to turn etc hosts into unbound config.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Thu, 11 Jun 2009 18:30:53 +0000 (18:30 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Thu, 11 Jun 2009 18:30:53 +0000 (18:30 +0000)
git-svn-id: file:///svn/unbound/trunk@1649 be551aaa-1e26-0410-a405-d3ace91eadb9

contrib/README
contrib/build-unbound-localzone-from-hosts.pl [new file with mode: 0644]
doc/Changelog

index f8ff7d9b162751b711c86e51c3d1e578218f71be..1b8458f437dde98fb7aff9743cd6e1ecab87b8ff 100644 (file)
@@ -12,3 +12,5 @@ distribution but may be helpful.
 * unbound_cacti.tar.gz : setup files for cacti statistics report
 * selinux: the .fc and .te files for SElinux protection of the unbound daemon
 * unbound.plist: launchd configuration file for MacOSX.
+* build-unbound-localzone-from-hosts.pl: perl script to turn /etc/hosts into
+       a local-zone and local-data include file for unbound.conf.
diff --git a/contrib/build-unbound-localzone-from-hosts.pl b/contrib/build-unbound-localzone-from-hosts.pl
new file mode 100644 (file)
index 0000000..c11bbc3
--- /dev/null
@@ -0,0 +1,67 @@
+#!/usr/bin/perl -WT
+
+use strict;
+use warnings;
+
+my $hostsfile = '/etc/hosts';
+my $localzonefile = '/etc/unbound/localzone.conf.new';
+
+my $localzone = 'example.com';
+
+open( HOSTS,"<${hostsfile}" ) or die( "Could not open ${hostsfile}: $!" );
+open( ZONE,">${localzonefile}" ) or die( "Could not open ${localzonefile}: $!" );
+
+print ZONE "server:\n\n";
+print ZONE "local-zone: \"${localzone}\" transparent\n\n";
+
+my %ptrhash;
+
+while ( my $hostline = <HOSTS> ) {
+
+       # Skip comments
+       if ( $hostline !~ "^#" and $hostline !~ '^\s+$' ) {
+
+               my @entries = split( /\s+/, $hostline );
+
+               my $ip;
+
+               my $count = 0;
+               foreach my $entry ( @entries ) {
+                       if ( $count == 0 ) {
+                               $ip = $entry;
+                       } else {
+
+                               if ( $count == 1) {
+
+                                       # Only return localhost for 127.0.0.1 and ::1
+                                       if ( ($ip ne '127.0.0.1' and $ip ne '::1') or $entry =~ 'localhost' ) {
+                                               if ( ! defined $ptrhash{$ip} ) {
+                                                       $ptrhash{$ip} = $entry;
+                                                       print ZONE "local-data-ptr: \"$ip $entry\"\n";
+                                               }
+                                       }
+
+                               }
+
+                               # Use AAAA for IPv6 addresses
+                               my $a = 'A';
+                               if ( $ip =~ ':' ) {
+                                       $a = 'AAAA';
+                               }
+
+                               print ZONE "local-data: \"$entry ${a} $ip\"\n";
+
+                       }
+                       $count++;
+               }
+               print ZONE "\n";
+
+
+       }
+}
+
+
+
+
+__END__
+
index b8fbb207767af5a17dcffe844a4d6716b0fd2324..aa67c56910def8bb5118d32a79935ae6de55db8a 100644 (file)
@@ -5,6 +5,8 @@
          server.  This makes a stub pointing to a local server that has
          a local view of example.com signed with the same keys as are
          publicly used work.  Reported by Johan Ihren.
+       - Added build-unbound-localzone-from-hosts.pl to contrib, from
+         Dennis DeDonatis.  It converts /etc/hosts into config statements.
 
 9 June 2009: Wouter
        - openssl key files are opened apache-style, when user is root and