Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Assigning DNS based on DHCP




On Jun 6, 2007, at 8:23 PM, Robert Everson wrote:

I tried searching the archives for this, because I'm sure it's been asked before, but I can't seem to find it.
How do I get my server to set domain names based on the DHCP address.  In other words, if a computer connects to the network, I want them to get an internal DNS name, like 10-1-100-3.solon.k12.ia.us.  Is this possible with OS X Server?  Or do I just need to add each valid DHCP address into the DNS records manually?


Hello,

What you're looking for isn't really an OS X Server feature, it's a BIND feature. You want a "$GENERATE" statement in your zone file, something like:

$GENERATE 2-20 dhcp$ IN A 10.0.1.$

This would create address records named dhcpN, for IP addresses 10.0.1.N, where N is expanded to the range of numbers between 2 and 20 (inclusive).

$GENERATE also works within the reverse zone file for PTR records.

$GENERATE 2-20 $ IN PTR dhcp$.937.

(In this example, my tld is "937").

For more information on this directive, see:

Unfortunately, use of the $GENERATE directive along with Server Admin's DNS module is uh... broken. Firstly, Server Admin won't be able to parse beyond the $GENERATE directive, so you may not see some existing and perfectly functional records through the GUI view. Worse, if you make a zone change via Server Admin, the zone file will be re-written without the $GENERATE directive. Be prepared to either not touch the zone file via Server Admin, or re-add the $GENERATE directive if you do. Finally, because the parsing is broken, and because SA seems to bail out as a result, you may find that your forward and reverse zone files become desynced.

If you want to retain the ability to use Server Admin to edit your DNS zones, I recommend instead that you use a small script to generate individual record statements which can then be pasted into your zone files. I've written a small sample, included below. Edit AddressPrefix, range, and tld as needed. If you want a different format than that produced by this script, edit inside the foreach loop.

----------script start----------
#!/usr/bin/perl -w
use strict;

# Place the first three octets here.
my $AddressPrefix = "10.0.1";

# Define the range of numbers, inclusive.
my $range = "2 .. 10";

# Your fqdn suffix here, e.g. "foo.com" or "k12.fl.us.gov"
my $tld = "937";

# Need a backwards representation for PTR records
my $octets = join(".", reverse(split(/\./, $AddressPrefix)));

# For our resulting address and ptr records
my @A, my @PTR = "";

foreach my $n ( eval $range ) {
  push @A, "dhcp$n IN A $AddressPrefix.$n";
  push @PTR, "$n.$octets.in-addr.arpa. IN PTR dhcp$n.$tld.";
}

print "Forward zone address records:\n";
print "$_\n" for @A;
print "\nReverse zone ptr records:";
print "$_\n" for @PTR;
----------script end----------

Example run:

{179} root@tiny [~] # ./gen.pl
Forward zone address records:
dhcp2 IN A 10.0.1.2
dhcp3 IN A 10.0.1.3
dhcp4 IN A 10.0.1.4
dhcp5 IN A 10.0.1.5
dhcp6 IN A 10.0.1.6
dhcp7 IN A 10.0.1.7
dhcp8 IN A 10.0.1.8
dhcp9 IN A 10.0.1.9
dhcp10 IN A 10.0.1.10

Reverse zone ptr records:
2.1.0.10.in-addr.arpa. IN PTR dhcp2.937.
3.1.0.10.in-addr.arpa. IN PTR dhcp3.937.
4.1.0.10.in-addr.arpa. IN PTR dhcp4.937.
5.1.0.10.in-addr.arpa. IN PTR dhcp5.937.
6.1.0.10.in-addr.arpa. IN PTR dhcp6.937.
7.1.0.10.in-addr.arpa. IN PTR dhcp7.937.
8.1.0.10.in-addr.arpa. IN PTR dhcp8.937.
9.1.0.10.in-addr.arpa. IN PTR dhcp9.937.
10.1.0.10.in-addr.arpa. IN PTR dhcp10.937.

See the following for a more complex example: http://www.perl.com/pub/a/2002/11/20/dns.html

After editing the zone file, restart named by sending it a SIGHUP, e.g. sudo killall -HUP named. Check system.log for errors.

HTH,
-Andre
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Macos-x-server mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/macos-x-server/email@hidden

This email sent to email@hidden

References: 
 >Assigning DNS based on DHCP (From: Robert Everson <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.