Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1139295
  • 博文数量: 168
  • 博客积分: 4445
  • 博客等级: 上校
  • 技术积分: 1307
  • 用 户 组: 普通用户
  • 注册时间: 2005-11-02 14:04
文章分类

全部博文(168)

文章存档

2018年(2)

2017年(5)

2016年(7)

2015年(1)

2014年(8)

2013年(1)

2012年(4)

2011年(54)

2010年(8)

2009年(19)

2008年(18)

2007年(36)

2006年(1)

2005年(4)

分类:

2008-12-20 09:40:54

 配置 DNS 主要服务器和备用服务器,将客户机添加到主服务器,等等
 
 
#!/bin/ksh
##########################################################################
##									##	
##	DNS SERVER CONFIGURATION SCRIPT FOR TEACH TCP/IP COURSES 	##
##				Write by				##
##		Mr. UDOMSAK NAKSENA ( udomsak.n@g-able.com ) 		##
##	     Sun Instructor Authorize Training Certification		##
##		Version 3 support Solaris 10 Zone			##	
##########################################################################
DBDIR=/var/named
CFGDIR=/etc

########## Information for MASTER SERVER  ########
info () {
	echo "\nConfigure path [ /etc ] : \c" 
	read CFGDIR ; CFGDIR=${CFGDIR:="/etc"}

	echo "Database path [ /var/named ] : \c"
	read DBDIR ; DBDIR=${DBDIR:="/var/named"}

	echo "Server name [ `uname -n` ] : \c"
	read name ; name=${name:=`uname -n`}

	IP=`/usr/sbin/ifconfig -a | grep inet | grep -v "127.0.0.1" | head -1 | awk '{print $2}'`
	A=`echo $IP | cut -d. -f1`
	B=`echo $IP | cut -d. -f2`
	C=`echo $IP | cut -d. -f3`
	D=`echo $IP | cut -d. -f4`

	echo "Server IP address [ $IP ] : \c"
	read ip ; ip=${ip:=$IP}

	DOMAIN="$D.com"
	echo "Domain name [ $DOMAIN ] : \c"
	read domain ; domain=${domain:=$DOMAIN}
	
	echo " "
	echo "Server name is		: $name.$domain"
	echo "Server IP is		: $ip"
	echo "configure file is	: $CFGDIR/named.conf"
	echo "Database path is 	: $DBDIR"
	echo "\n***** Old configure file will remove to $CFGDIR/named.conf.prev *****"
	echo "*****   Old database file will remove to $DBDIR/prev.d   *****"
}

##########  Infomation for slave SERVER  ########
info_slave () {
	if [ "$merge" != "y" ]
	then	
		echo "\nConfigure path [ /etc ] : \c" 
		read CFGDIR ; CFGDIR=${CFGDIR:="/etc"}

		echo "Database path [ /var/named ] : \c"
		read DBDIR ; DBDIR=${DBDIR:="/var/named"}
	fi

	echo "Primary Server name : \c"
	read name 

	echo "Primary Server IP address : \c"
	read master_ip 

	echo "Primary Domain name : \c"
	read domain 
	
	echo " "
	echo "Primary Server name is	: $name.$domain"
	echo "Primary Server IP is	: $master_ip"
	echo "configure file is	: $CFGDIR/named.conf"
	echo "Database path is 	: $DBDIR"
}

##########  BIND Configure file  ########
namedconf () {
[ -f ${CFGDIR}/named.conf ] &&  mv ${CFGDIR}/named.conf ${CFGDIR}/named.conf.prev

cat > $CFGDIR/named.conf <&-  && \
	mv $DBDIR/named.root $DBDIR/prev.d

	echo "Enter root name server and IP type Enter to finish"
	cat > $DBDIR/named.root <<-EOT
	EOT
	root="begin"
	until [ "$root" = '' ]
	do
		echo "Root server name  eg. A.root-server.net : \c"
		read rootname
		if [ "$rootname" = '' ]
			then break
		fi
		echo "Root server IP address eg. 192.168.100.253 : \c"
		read rootip
cat >> $DBDIR/named.root < $DBDIR/domain.$domain < $DBDIR/rdomain.$domain < $DBDIR/loopback < $CFGDIR/resolv.conf <&-
}

########## Add client to server ###########
client () {
	if [ -z "$domain" ]
	then
		defaultdomain="`/usr/sbin/ifconfig -a | grep inet | \
		grep -v "127.0.0.1" | head -1 | awk '{print $2}'`.com"
		echo "Domain name [ $defaultdomain ] : \c"
		read domain ; domain=${domain:=$defaultdomain}
	fi
	echo "Enter client name and IP address ENTER to finish"
	while :
	do
		echo "\nClient name : \c" ; read cname
		if [ "$cname" = '' ]
			then break
		fi
		echo "Client IP   : \c" ; read cip
		reverse_cip=`echo $cip | awk -F. '{print $4"."$3"."$2"."$1}'`

		echo "$cname 		in a	$cip"
		echo "Are you sure to add client to $domain [ y ] : \c "  
		read addnow  
		addnow=${addnow:=y}
		if [ "$addnow" = 'y' ] 
		then
		cat >> $DBDIR/domain.$domain <<-EOT 
			$cname            in a    $cip
		EOT
		
		cat >> $DBDIR/rdomain.$domain <<-EOT 
			$reverse_cip      IN PTR  $cname.$DOMAIN.
		EOT
		else 
		continue
		fi
	done
}


##########  BIND Configure file  local domain  ########
localdomain () {
cat > $CFGDIR/named.conf <> $CFGDIR/named.conf <> $CFGDIR/named.conf <&-
					mv $DBDIR/* $DBDIR/prev.d 2>&-

					info_loop info_slave
					localdomain
					slave_forward
					slave_reverse
					named_root
					loopback_domain
				fi
				continue
			fi
			[ -d $CFGDIR ] || mkdir -p $CFGDIR
			[ -d $DBDIR ] || mkdir -p $DBDIR

			info_loop info_slave
			localdomain
			slave_forward
			slave_reverse
			named_root
			loopback_domain
			;;
		3) client ;;
		4) exit 0 ;;
		*) continue ;;
	esac
done




##############################################################################
### This script is submitted to BigAdmin by a user of the BigAdmin community.
### Sun Microsystems, Inc. is not responsible for the
### contents or the code enclosed. 
###
###
### Copyright 2008 Sun Microsystems, Inc. ALL RIGHTS RESERVED
### Use of this software is authorized pursuant to the
### terms of the license found at
### 
##############################################################################


阅读(1443) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~