Variable in name of file for named.conf

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Variable in name of file for named.conf

Jeff Sadowski
I have a number of slave domains that I would like a naming scheme and
not have to go to each and change the filename.

I have the following zones

zone "1.168.192.in-addr.arpa" {
        include "named.slave";
};
zone "2.168.192.in-addr.arpa" {
        include "named.slave";
};
zone "3.168.192.in-addr.arpa" {
        include "named.slave";
};
zone "4.168.192.in-addr.arpa" {
        include "named.slave";
};
zone "5.168.192.in-addr.arpa" {
        include "named.slave";
};
zone "6.168.192.in-addr.arpa" {
        include "named.slave";
};
zone "7.168.192.in-addr.arpa" {
        include "named.slave";
};
zone "8.168.192.in-addr.arpa" {
        include "named.slave";
};
zone "9.168.192.in-addr.arpa" {
        include "named.slave";
};
zone "10.168.192.in-addr.arpa" {
        include "named.slave";
};

named.slave looks as follows

type slave;
masters {192.168.1.2;};
file "data/db.@.slave";

It appears to work on my queries.

nslookup 192.168.1.2

2.1.168.192.in-addr.arpa      name = pdc.<domain>

nslookup 192.168.1.1

1.1.168.192.in-addr.arpa      name = gw1.<domain>

nslookup 192.168.2.1

1.2.168.192.in-addr.arpa      name = gw2.<domain>

the only file created in my data directory seems to be db.@.slave
with the at sign.

Do I really need to have each zone with its own file?

Is there a special syntax to get what I expect?
expected files:
data/db.1.168.192.in-addr.arpa.slave
data/db.2.168.192.in-addr.arpa.slave
data/db.3.168.192.in-addr.arpa.slave
...
data/db.10.168.192.in-addr.arpa.slave

if not I can have Make do it and build some scripts to do what I want
but if there is syntax to do what I want it would be nice.
_______________________________________________
Please visit https://lists.isc.org/mailman/listinfo/bind-users to unsubscribe from this list

bind-users mailing list
[hidden email]
https://lists.isc.org/mailman/listinfo/bind-users
Reply | Threaded
Open this post in threaded view
|

Re: Variable in name of file for named.conf

Barry Margolin
In article <[hidden email]>,
 Jeff Sadowski <[hidden email]> wrote:

> I have a number of slave domains that I would like a naming scheme and
> not have to go to each and change the filename.
>
> I have the following zones
>
> zone "1.168.192.in-addr.arpa" {
>         include "named.slave";
> };
> zone "2.168.192.in-addr.arpa" {
>         include "named.slave";
> };
> zone "3.168.192.in-addr.arpa" {
>         include "named.slave";
> };
> zone "4.168.192.in-addr.arpa" {
>         include "named.slave";
> };
> zone "5.168.192.in-addr.arpa" {
>         include "named.slave";
> };
> zone "6.168.192.in-addr.arpa" {
>         include "named.slave";
> };
> zone "7.168.192.in-addr.arpa" {
>         include "named.slave";
> };
> zone "8.168.192.in-addr.arpa" {
>         include "named.slave";
> };
> zone "9.168.192.in-addr.arpa" {
>         include "named.slave";
> };
> zone "10.168.192.in-addr.arpa" {
>         include "named.slave";
> };
>
> named.slave looks as follows
>
> type slave;
> masters {192.168.1.2;};
> file "data/db.@.slave";
>
> It appears to work on my queries.
>
> nslookup 192.168.1.2
>
> 2.1.168.192.in-addr.arpa      name = pdc.<domain>
>
> nslookup 192.168.1.1
>
> 1.1.168.192.in-addr.arpa      name = gw1.<domain>
>
> nslookup 192.168.2.1
>
> 1.2.168.192.in-addr.arpa      name = gw2.<domain>
>
> the only file created in my data directory seems to be db.@.slave
> with the at sign.

Why would you expect anything different? @ only has special meaning
inside zone files, it's not special in named.conf.

>
> Do I really need to have each zone with its own file?

Yes, you do. What's happening is that every time one of the reverse
zones is transferred, it's overwriting that file. But the files are only
used when initializing the zones when named starts up; you get the
correct answers because the in-memory versions of the zones are
distinct. But try restarting named and then see what happens when you do
those nslookups. You'll see that 192.168.1.1 and 192.168.2.1 both return
the same name.

>
> Is there a special syntax to get what I expect?
> expected files:
> data/db.1.168.192.in-addr.arpa.slave
> data/db.2.168.192.in-addr.arpa.slave
> data/db.3.168.192.in-addr.arpa.slave
> ...
> data/db.10.168.192.in-addr.arpa.slave
>
> if not I can have Make do it and build some scripts to do what I want
> but if there is syntax to do what I want it would be nice.

No, there's no built-in syntax to create the filename based on the zone
name.

--
Barry Margolin
Arlington, MA
_______________________________________________
Please visit https://lists.isc.org/mailman/listinfo/bind-users to unsubscribe from this list

bind-users mailing list
[hidden email]
https://lists.isc.org/mailman/listinfo/bind-users
Reply | Threaded
Open this post in threaded view
|

Re: Variable in name of file for named.conf

Jeff Sadowski
On Wed, Apr 1, 2015 at 8:09 PM, Barry Margolin <[hidden email]> wrote:

> In article <[hidden email]>,
>  Jeff Sadowski <[hidden email]> wrote:
>
>> I have a number of slave domains that I would like a naming scheme and
>> not have to go to each and change the filename.
>>
>> I have the following zones
>>
>> zone "1.168.192.in-addr.arpa" {
>>         include "named.slave";
>> };
>> zone "2.168.192.in-addr.arpa" {
>>         include "named.slave";
>> };
>> zone "3.168.192.in-addr.arpa" {
>>         include "named.slave";
>> };
>> zone "4.168.192.in-addr.arpa" {
>>         include "named.slave";
>> };
>> zone "5.168.192.in-addr.arpa" {
>>         include "named.slave";
>> };
>> zone "6.168.192.in-addr.arpa" {
>>         include "named.slave";
>> };
>> zone "7.168.192.in-addr.arpa" {
>>         include "named.slave";
>> };
>> zone "8.168.192.in-addr.arpa" {
>>         include "named.slave";
>> };
>> zone "9.168.192.in-addr.arpa" {
>>         include "named.slave";
>> };
>> zone "10.168.192.in-addr.arpa" {
>>         include "named.slave";
>> };
>>
>> named.slave looks as follows
>>
>> type slave;
>> masters {192.168.1.2;};
>> file "data/db.@.slave";
>>
>> It appears to work on my queries.
>>
>> nslookup 192.168.1.2
>>
>> 2.1.168.192.in-addr.arpa      name = pdc.<domain>
>>
>> nslookup 192.168.1.1
>>
>> 1.1.168.192.in-addr.arpa      name = gw1.<domain>
>>
>> nslookup 192.168.2.1
>>
>> 1.2.168.192.in-addr.arpa      name = gw2.<domain>
>>
>> the only file created in my data directory seems to be db.@.slave
>> with the at sign.
>
> Why would you expect anything different? @ only has special meaning
> inside zone files, it's not special in named.conf.
>
>>
>> Do I really need to have each zone with its own file?
>
> Yes, you do. What's happening is that every time one of the reverse
> zones is transferred, it's overwriting that file. But the files are only
> used when initializing the zones when named starts up; you get the
> correct answers because the in-memory versions of the zones are
> distinct. But try restarting named and then see what happens when you do
> those nslookups. You'll see that 192.168.1.1 and 192.168.2.1 both return
> the same name.
>
>>
>> Is there a special syntax to get what I expect?
>> expected files:
>> data/db.1.168.192.in-addr.arpa.slave
>> data/db.2.168.192.in-addr.arpa.slave
>> data/db.3.168.192.in-addr.arpa.slave
>> ...
>> data/db.10.168.192.in-addr.arpa.slave
>>
>> if not I can have Make do it and build some scripts to do what I want
>> but if there is syntax to do what I want it would be nice.
>
> No, there's no built-in syntax to create the filename based on the zone
> name.
>
I wrote a php script to build my file for me

<?php
$myslave=array('type'=>'slave'
,'masters'=>array('192.168.1.2')
,'autofile'=>'data/db.@.slave');

$arpa192='.168.192.in-addr.arpa';
$domain='<domain>';
$zone['_msdcs.'.$domain]=$myslave;
$zone[$domain]=$myslave;
$slavedsubnets=range('1','10');

build_subnets($slavedsubnets
,$arpa192
,$myslave);

build_zones();

function build_subnets($subnets
,$net
,$info)
{global $zone;
 foreach($subnets as $subnet)
 {$zone[$subnet.$net]=$info;
}}

function build_zones()
{global $zone,$argv;
 $pounds=str_repeat('#',30);
 $warning=$pounds.' WARNING '.$pounds."\n";
 echo $warning. '# Do not edit this file. '.
      'It was generated using "php '.
      $argv[0]."\"\n".$warning;
 foreach($zone as $z=>$infos)
 {echo 'zone "'.$z.'" {'."\n";
  foreach($infos as $item=>$value)
  {echo "\t".$item.' ';
   if(is_array($value))
   {echo '{';
    foreach($value as $v){echo $v.';';}
    echo '}';
   }
   else
   {switch($item)
    {case 'file': echo '"'.$value.'"'; break;
     case 'autofile': echo '"'.
           str_replace('@',$z,$value).'"';
     break;
     default: echo $value; break;
   }}
   echo ";\n";
  }
  echo "};\n";
}}
?>


> --
> Barry Margolin
> Arlington, MA
> _______________________________________________
> Please visit https://lists.isc.org/mailman/listinfo/bind-users to unsubscribe from this list
>
> bind-users mailing list
> [hidden email]
> https://lists.isc.org/mailman/listinfo/bind-users
_______________________________________________
Please visit https://lists.isc.org/mailman/listinfo/bind-users to unsubscribe from this list

bind-users mailing list
[hidden email]
https://lists.isc.org/mailman/listinfo/bind-users
Reply | Threaded
Open this post in threaded view
|

Re: Variable in name of file for named.conf

Jeff Sadowski
On Thu, Apr 2, 2015 at 11:09 AM, Jeff Sadowski <[hidden email]> wrote:

> On Wed, Apr 1, 2015 at 8:09 PM, Barry Margolin <[hidden email]> wrote:
>> In article <[hidden email]>,
>>  Jeff Sadowski <[hidden email]> wrote:
>>
>>> I have a number of slave domains that I would like a naming scheme and
>>> not have to go to each and change the filename.
>>>
>>> I have the following zones
>>>
>>> zone "1.168.192.in-addr.arpa" {
>>>         include "named.slave";
>>> };
>>> zone "2.168.192.in-addr.arpa" {
>>>         include "named.slave";
>>> };
>>> zone "3.168.192.in-addr.arpa" {
>>>         include "named.slave";
>>> };
>>> zone "4.168.192.in-addr.arpa" {
>>>         include "named.slave";
>>> };
>>> zone "5.168.192.in-addr.arpa" {
>>>         include "named.slave";
>>> };
>>> zone "6.168.192.in-addr.arpa" {
>>>         include "named.slave";
>>> };
>>> zone "7.168.192.in-addr.arpa" {
>>>         include "named.slave";
>>> };
>>> zone "8.168.192.in-addr.arpa" {
>>>         include "named.slave";
>>> };
>>> zone "9.168.192.in-addr.arpa" {
>>>         include "named.slave";
>>> };
>>> zone "10.168.192.in-addr.arpa" {
>>>         include "named.slave";
>>> };
>>>
>>> named.slave looks as follows
>>>
>>> type slave;
>>> masters {192.168.1.2;};
>>> file "data/db.@.slave";
>>>
>>> It appears to work on my queries.
>>>
>>> nslookup 192.168.1.2
>>>
>>> 2.1.168.192.in-addr.arpa      name = pdc.<domain>
>>>
>>> nslookup 192.168.1.1
>>>
>>> 1.1.168.192.in-addr.arpa      name = gw1.<domain>
>>>
>>> nslookup 192.168.2.1
>>>
>>> 1.2.168.192.in-addr.arpa      name = gw2.<domain>
>>>
>>> the only file created in my data directory seems to be db.@.slave
>>> with the at sign.
>>
>> Why would you expect anything different? @ only has special meaning
>> inside zone files, it's not special in named.conf.
>>
>>>
>>> Do I really need to have each zone with its own file?
>>
>> Yes, you do. What's happening is that every time one of the reverse
>> zones is transferred, it's overwriting that file. But the files are only
>> used when initializing the zones when named starts up; you get the
>> correct answers because the in-memory versions of the zones are
>> distinct. But try restarting named and then see what happens when you do
>> those nslookups. You'll see that 192.168.1.1 and 192.168.2.1 both return
>> the same name.
>>
>>>
>>> Is there a special syntax to get what I expect?
>>> expected files:
>>> data/db.1.168.192.in-addr.arpa.slave
>>> data/db.2.168.192.in-addr.arpa.slave
>>> data/db.3.168.192.in-addr.arpa.slave
>>> ...
>>> data/db.10.168.192.in-addr.arpa.slave
>>>
>>> if not I can have Make do it and build some scripts to do what I want
>>> but if there is syntax to do what I want it would be nice.
>>
>> No, there's no built-in syntax to create the filename based on the zone
>> name.
>>
> I wrote a php script to build my file for me
>
> <?php
> $myslave=array('type'=>'slave'
> ,'masters'=>array('192.168.1.2')
> ,'autofile'=>'data/db.@.slave');
>
> $arpa192='.168.192.in-addr.arpa';
> $domain='<domain>';
> $zone['_msdcs.'.$domain]=$myslave;
> $zone[$domain]=$myslave;
> $slavedsubnets=range('1','10');
>
> build_subnets($slavedsubnets
> ,$arpa192
> ,$myslave);
>
> build_zones();
>
> function build_subnets($subnets
> ,$net
> ,$info)
> {global $zone;
>  foreach($subnets as $subnet)
>  {$zone[$subnet.$net]=$info;
> }}
>
> function build_zones()
> {global $zone,$argv;
>  $pounds=str_repeat('#',30);
>  $warning=$pounds.' WARNING '.$pounds."\n";
>  echo $warning. '# Do not edit this file. '.
>       'It was generated using "php '.
>       $argv[0]."\"\n".$warning;
>  foreach($zone as $z=>$infos)
>  {echo 'zone "'.$z.'" {'."\n";
>   foreach($infos as $item=>$value)
>   {echo "\t".$item.' ';
>    if(is_array($value))
>    {echo '{';
>     foreach($value as $v){echo $v.';';}
>     echo '}';
>    }
>    else
>    {switch($item)
>     {case 'file': echo '"'.$value.'"'; break;
>      case 'autofile': echo '"'.
>            str_replace('@',$z,$value).'"';
>      break;
>      default: echo $value; break;
>    }}
>    echo ";\n";
>   }
>   echo "};\n";
> }}
> ?>
>

correction I forgot I left autofile in there

<?php

$myslave=array('type'=>'slave'
,'masters'=>array('192.168.1.2')
,'autofile'=>'data/db.@.slave');

$arpa192='.168.192.in-addr.arpa';
$domain='<domain>';
$zone['_msdcs.'.$domain]=$myslave;
$zone[$domain]=$myslave;
$slavedsubnets=range('1','10');

build_subnets($slavedsubnets
,$arpa192
,$myslave);

build_zones();

function build_subnets($subnets
,$net
,$info)
{global $zone;
 foreach($subnets as $subnet)
 {$zone[$subnet.$net]=$info;
}}

function build_zones()
{global $zone,$argv;
 $pounds=str_repeat('#',30);
 $warning=$pounds.' WARNING '.$pounds."\n";
 echo $warning. '# Do not edit this file. '.
      'It was generated using "php '.
      $argv[0]."\"\n".$warning;
 foreach($zone as $z=>$infos)
 {echo 'zone "'.$z.'" {'."\n";
  foreach($infos as $item=>$value)
  {if(is_array($value))
   {echo "\t".$item.' ';
    echo '{';
    foreach($value as $v){echo $v.';';}
    echo '}';
   }
   else
   {switch($item)
    {case 'file': echo "\t".$item.' ';
           echo '"'.$value.'"'; break;
     case 'autofile': echo "\tfile ";
           echo '"'.str_replace('@',$z,$value).'"';
     break;
     default: echo "\t".$item.' ';
           echo $value; break;
   }}
   echo ";\n";
  }
  echo "};\n";
}}
?>



>
>> --
>> Barry Margolin
>> Arlington, MA
>> _______________________________________________
>> Please visit https://lists.isc.org/mailman/listinfo/bind-users to unsubscribe from this list
>>
>> bind-users mailing list
>> [hidden email]
>> https://lists.isc.org/mailman/listinfo/bind-users
_______________________________________________
Please visit https://lists.isc.org/mailman/listinfo/bind-users to unsubscribe from this list

bind-users mailing list
[hidden email]
https://lists.isc.org/mailman/listinfo/bind-users
Reply | Threaded
Open this post in threaded view
|

RE: Variable in name of file for named.conf

Kevin Darcy
In reply to this post by Barry Margolin
It would be a nice feature, but in lieu of that, you could always have a script manage your named.conf and incorporate the variable-substitution logic into that. If you want to go Old School, use cpp, make, sccs, some of those long-forgotten tools :-)

                                                                                        - Kevin

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Barry Margolin
Sent: Wednesday, April 01, 2015 10:09 PM
To: [hidden email]
Subject: Re: Variable in name of file for named.conf

In article <[hidden email]>,
 Jeff Sadowski <[hidden email]> wrote:

> I have a number of slave domains that I would like a naming scheme and
> not have to go to each and change the filename.
>
> I have the following zones
>
> zone "1.168.192.in-addr.arpa" {
>         include "named.slave";
> };
> zone "2.168.192.in-addr.arpa" {
>         include "named.slave";
> };
> zone "3.168.192.in-addr.arpa" {
>         include "named.slave";
> };
> zone "4.168.192.in-addr.arpa" {
>         include "named.slave";
> };
> zone "5.168.192.in-addr.arpa" {
>         include "named.slave";
> };
> zone "6.168.192.in-addr.arpa" {
>         include "named.slave";
> };
> zone "7.168.192.in-addr.arpa" {
>         include "named.slave";
> };
> zone "8.168.192.in-addr.arpa" {
>         include "named.slave";
> };
> zone "9.168.192.in-addr.arpa" {
>         include "named.slave";
> };
> zone "10.168.192.in-addr.arpa" {
>         include "named.slave";
> };
>
> named.slave looks as follows
>
> type slave;
> masters {192.168.1.2;};
> file "data/db.@.slave";
>
> It appears to work on my queries.
>
> nslookup 192.168.1.2
>
> 2.1.168.192.in-addr.arpa      name = pdc.<domain>
>
> nslookup 192.168.1.1
>
> 1.1.168.192.in-addr.arpa      name = gw1.<domain>
>
> nslookup 192.168.2.1
>
> 1.2.168.192.in-addr.arpa      name = gw2.<domain>
>
> the only file created in my data directory seems to be db.@.slave with
> the at sign.

Why would you expect anything different? @ only has special meaning inside zone files, it's not special in named.conf.

>
> Do I really need to have each zone with its own file?

Yes, you do. What's happening is that every time one of the reverse zones is transferred, it's overwriting that file. But the files are only used when initializing the zones when named starts up; you get the correct answers because the in-memory versions of the zones are distinct. But try restarting named and then see what happens when you do those nslookups. You'll see that 192.168.1.1 and 192.168.2.1 both return the same name.

>
> Is there a special syntax to get what I expect?
> expected files:
> data/db.1.168.192.in-addr.arpa.slave
> data/db.2.168.192.in-addr.arpa.slave
> data/db.3.168.192.in-addr.arpa.slave
> ...
> data/db.10.168.192.in-addr.arpa.slave
>
> if not I can have Make do it and build some scripts to do what I want
> but if there is syntax to do what I want it would be nice.

No, there's no built-in syntax to create the filename based on the zone name.

--
Barry Margolin
Arlington, MA
_______________________________________________
Please visit https://lists.isc.org/mailman/listinfo/bind-users to unsubscribe from this list

bind-users mailing list
[hidden email]
https://lists.isc.org/mailman/listinfo/bind-users
_______________________________________________
Please visit https://lists.isc.org/mailman/listinfo/bind-users to unsubscribe from this list

bind-users mailing list
[hidden email]
https://lists.isc.org/mailman/listinfo/bind-users
Reply | Threaded
Open this post in threaded view
|

Re: Variable in name of file for named.conf

Tony Finch
In reply to this post by Jeff Sadowski

> On 1 Apr 2015, at 23:30, Jeff Sadowski <[hidden email]> wrote:
>
> Do I really need to have each zone with its own file?

You can omit the file option in a slave zone and named will keep the zone in memory only. The disadvantage is it will have to retransfer all the zones in full when it starts before it can answer replies.

> if not I can have Make do it and build some scripts to do what I want

Yes, do this.

> but if there is syntax to do what I want it would be nice.

Increasingly I think programs should avoid anything like a macro processor in their config languages. Leave that job to your config management system.

Tony.
--
f.anthony.n.finch  <[hidden email]>  http://dotat.at
_______________________________________________
Please visit https://lists.isc.org/mailman/listinfo/bind-users to unsubscribe from this list

bind-users mailing list
[hidden email]
https://lists.isc.org/mailman/listinfo/bind-users
Reply | Threaded
Open this post in threaded view
|

Re: Variable in name of file for named.conf

Grant Taylor
In reply to this post by Jeff Sadowski
> It would be a nice feature, but in lieu of that, you could always
> have a script manage your named.conf and incorporate the
> variable-substitution logic into that. If you want to go Old School,
> use cpp, make, sccs, some of those long-forgotten tools :-)

I've had wonderful success with Makefile(s) and macro 4.  -  Talk about
old school.



--
Grant. . . .
unix || die
_______________________________________________
Please visit https://lists.isc.org/mailman/listinfo/bind-users to unsubscribe from this list

bind-users mailing list
[hidden email]
https://lists.isc.org/mailman/listinfo/bind-users