您的位置:首页 > 运维架构 > Shell

shell脚本实现DNS的自动安装与配置

2011-03-01 14:53 981 查看
#!/bin/bash

read -p "Please enter your zone:" ZONE

read -p "Please enter your IPNET,[Usage: 192.168.0.]:" NET

YOURIP=`ifconfig eth0| grep "inet addr" | sed 's/^.*addr://g' | sed 's/Bcast.*$//g'`

LAST=`echo $YOURIP | awk 'BEGIN {FS="."}{print $4}'`

FANXIANG=`echo $NET | awk 'BEGIN {FS="."}{print $3"."$2"."$1}'`

rpm -q bind &>/dev/null && rpm -q caching-nameserver &>/dev/null

let BOOL=`echo $?`

if [ $BOOL -eq 1 ]; then

yum -y install bind

yum -y install caching-nameserver

fi

rpm -q bind &>/dev/null && rpm -q caching-nameserver &>/dev/null

let BOOL2=`echo $?`

if [ $BOOL2 -eq 1 ]; then

echo "Sorry,bind is not install!"

exit

fi

#********************************************

echo "make named.conf......"

cat>>/etc/named.conf<<EOF

options {

directory "/var/named";

};

zone "." IN {

type hint;

file "named.ca";

};

zone "localhost" IN {

type master;

file "localhost.zone";

};

zone "0.0.127.in-addr.arpa" IN {

type master;

file "named.local";

};

zone "$ZONE" IN {

type master;

file "$ZONE.zone";

};

zone "$FANXIANG.in-addr.arpa" IN {

type master;

file "$NET.zone";

};

EOF

#*******************************************

echo "make $ZONE.zone....."

echo '$TTL 86400' > /var/named/$ZONE.zone

cat>>/var/named/$ZONE.zone<<EOF

@ IN SOA $ZONE. root.linna.com. (

2011021501

1H

10M

7D

1D )

IN NS ns.$ZONE.

IN MX 10 mail.$ZONE.

ns IN A $YOURIP

mail IN A $YOURIP

www IN A $YOURIP

EOF

#******************************************

echo "make $NET.zone......"

echo '$TTL 86400' > /var/named/$NET.zone

cat>>/var/named/$NET.zone<<EOF

@ IN SOA $ZONE. root.linna.com. (

2011021502

1H

10M

7D

1D )

IN NS ns.$ZONE.

$LAST IN PTR ns.$ZONE.

$LAST IN PTR mail.$ZONE.

$LAST IN PTR www.$ZONE.

EOF

#*******************************************

service named configtest

echo "Checking........."

chown :named /etc/named.conf

chown :named /var/named/*

#sed -i 's/^nameserver.*$/nameserver $YOURIP/g' /etc/resolv.conf

echo -e "search example.com \n nameserver $YOURIP " > /etc/resolv.conf

#*******************************************

echo "OK!Well Down!"

#******************************************

wait

service named start

chkconfig named on

chkconfig named --list

#*****************************************

wait

dig -x $YOURIP

dig -t A $ZONE

#****************************************
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息