Skip to page content or Skip to Accesskey List.

Work

Main Page Content

Dirty Shell Scripts Part 2 Dns Updates

Rated 3.89 (Ratings: 0)

Want more?

  • More articles in Code
 
Picture of AnthonyB

Anthony Baratta

Member info

User since: 10 Jul 1999

Articles written: 12

Daniel posted his excellent quick and dirty script for adding sites to your Apache Conf

File. Here's my quick and dirty script for adding domains to your DNS config files. (My

script does not provide the ego boost Daniel's does ;-)

Since I park quite a few domains for friends, as well as provide redirection/bounce

domains for some companies I many times need to do batches of domains. With the script and

template below, you can either pass the script one domain name, or pass it a file that has

a list of domain names. The script will then create a named.<domainname> file for

each domain and also create an add.named.conf file that you can then manually append to

your named.conf file.

For my LINUX server, named files reside in /var/named. I created a special

sub-directory called 'park' to store all my 'other' domains. I keep all my personal and my

personal business domains in /var/named, this allows for less clutter. The script assumes

that you set up your parked domains the same. You can edit it to either not do that, or

add additional functionality to branch on demand.

To use the script below, cut out the new-site.cgi

and save as a text file in /var/named/park. Verify /usr/bin/perl is your perl5 executable

and chmod the file to 700. You should be only playing with these files as root anyway. Cut

out the named.template and save as a text file in

the same directory as new-site.cgi.

For One Domain, To activate:

    root@foobar park>./new-site.cgi

    newsite.com

For More than one domain, create a text file with the list of new domains.

    e.g. newsites.file

      newsite1.com

      newsite2.com

      newsite3.com

      etc.

To activate:

    root@foobar park>./new-site.cgi -f

    newsites.file

Take the add.named.conf file and append it to your named.conf file. Restart named.

Hope this saves you some time and most of all have fun!!.

new-site.cgi

#!/usr/bin/perl -w

##

## Creates a new named file from

## named.template and appends info

## Does not restart named service!!

##

## Accepts two types of input

## -f <filename>

## or

## <domainname>

##

## -f indicates read from file a

## list of domain names to process

##

## <domainname> means just process

if ($#ARGV > -1) {

if ($ARGV[0] eq "-f") {

if (open (FILE, "<$ARGV[1]")) {

while ($ReadLine = <FILE>) {

chomp($ReadLine);

&CreateNameDFile($ReadLine);

&AddToNameDConfig($ReadLine);

} # end while (<FILE>)

close (FILE);

} else {

print "Could not open $ARGV[1]

";

exit;

} # end if (open (FILE, "<$ARGV[1]")

} else {

if ($ARGV[0] ne "" && $ARGV[0] ne "

" ) {

&CreateNameDFile($ARGV[0]);

&AddToNameDConfig($ARGV[0]);

} else {

print "no arguments given...

";

print " use -f \<filename> or

<domainname>

";

exit;

} # end if ($ARGV[0] ne "" && $ARGV[0] ne "

"

} # end if ($ARGV[0] ne "-f")

} else {

print "no arguments given...

";

print " use -f \<filename> or <domainname>

";

exit;

} # end if ($#ARGV >0)

</small>

<small>sub CreateNameDFile {

$varNewFileName = "named." . "$_[0]";

open (TEMPLATE, "<./named.template");

open (DUMP, ">./$varNewFileName");

while ($Line = <TEMPLATE>) {

$Line =~ s/replaceme/$_[0]/g;

print DUMP $Line;

} # end while (<TEMPLATE>)

close (DUMP);

close (TEMPLATE);

print "Completed new named file for $_[0]

";

} # end sub CreateNameDFile

sub AddToNameDConfig {

open (DUMP, ">>./add.named.conf");

print DUMP "zone \"$_[0]\" {

";

print DUMP " type master;

";

print DUMP " file \"park\/named." . "$_[0]" .

"\";

";

print DUMP "};

";

close (DUMP);

print "Added $_[0] info to add.named.conf file.

";

} # end sub AddToNameDConfig

exit;

named.template

;

***********************************************************

; *** Master DNS file for Your Sub-Domain ***

; ***********************************************************

;

; NOTE: This file should only contain records for

; the foo.com domain. You must set up a

; separate master file for each zone.

;

;

; ***********************************************************

;

; The $ORIGIN is added to any domain name that

; does not end in a dot (".").

;

$ORIGIN replaceme.

;

;

; ***********************************************************

;

; SOA record with recommended configuration values

;

@ IN SOA ns.replaceme. hostmaster.replaceme. (

199901173 ; Serial Number (YYYYMMDDN)

10800 ; Refresh

3600 ; Retry

3599999 ; Expire

86400 ) ; Minimum

;

;

; ***********************************************************

;

; NS record for primary name server

;

@ IN NS ns.replaceme.

;

;

; ***********************************************************

;

; Have you contacted the administrator of ns.foo.net.

; to ask if they are secondary for this zone?

; If so, uncomment this NS line for the secondary name server.

;

;@ IN NS ns.foo.net.

;

;

; ***********************************************************

;

; MX record

;

; Mail Server

@ IN MX 10 mail.replaceme.

; ***********************************************************

@ IN A 192.168.0.1

mail IN A 192.168.0.1

www IN A 192.168.0.1

ns IN A 192.168.0.1

ftp IN A 192.168.0.1

example add.named.conf file

zone "foobar.org" {

type master;

file "park/named.foobar.org";

};

zone "foo.com" {

type master;

file "park/named.foo.com";

};

Mutated into a life-size Dilbert doll, Anthony spends the days wedged into his replica of Cardinal Fang's Comfy Chair coding solutions to the most thorny of internet software problems.

The access keys for this page are: ALT (Control on a Mac) plus:

evolt.org Evolt.org is an all-volunteer resource for web developers made up of a discussion list, a browser archive, and member-submitted articles. This article is the property of its author, please do not redistribute or use elsewhere without checking with the author.