]>
git.saurik.com Git - apple/network_cmds.git/blob - unbound/contrib/build-unbound-localzone-from-hosts.pl
6 my $hostsfile = '/etc/hosts';
7 my $localzonefile = '/etc/unbound/localzone.conf.new';
9 my $localzone = 'example.com';
11 open( HOSTS
,"<${hostsfile}" ) or die( "Could not open ${hostsfile}: $!" );
12 open( ZONE
,">${localzonefile}" ) or die( "Could not open ${localzonefile}: $!" );
14 print ZONE
"server:\n\n";
15 print ZONE
"local-zone: \"${localzone}\" transparent\n\n";
19 while ( my $hostline = <HOSTS
> ) {
22 if ( $hostline !~ "^#" and $hostline !~ '^\s+$' ) {
24 my @entries = split( /\s+/, $hostline );
29 foreach my $entry ( @entries ) {
36 # Only return localhost for 127.0.0.1 and ::1
37 if ( ($ip ne '127.0.0.1' and $ip ne '::1') or $entry =~ 'localhost' ) {
38 if ( ! defined $ptrhash{$ip} ) {
39 $ptrhash{$ip} = $entry;
40 print ZONE
"local-data-ptr: \"$ip $entry\"\n";
46 # Use AAAA for IPv6 addresses
52 print ZONE
"local-data: \"$entry ${a} $ip\"\n";