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

简介:
#!/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
#****************************************









本文转自 490999122 51CTO博客,原文链接:http://blog.51cto.com/lyp0909/503605,如需转载请自行联系原作者
目录
相关文章
|
8天前
|
监控 Shell Linux
Linux的Shell脚本详解
Linux的Shell脚本详解
|
13天前
|
Shell
shell脚本
shell脚本
15 2
|
20天前
|
Ubuntu Java Linux
Linux centos7 ubuntu 一键安装Java JDK 脚本 shell 脚本
Linux centos7 ubuntu 一键安装Java JDK 脚本 shell 脚本
32 2
|
21天前
|
Shell Linux
shell linux中shell脚本编写俄罗斯方块
shell linux中shell脚本编写俄罗斯方块
19 1
|
21天前
|
Shell Linux Perl
Linux shell脚本sed使用
Linux shell脚本sed使用
15 1
|
1天前
|
Shell
Shell脚本之条件语句if总结
Shell脚本之条件语句if总结
|
20天前
|
Ubuntu Shell Linux
linux shell 后台执行脚本的方法 脚本后台运行 后台运行程
linux shell 后台执行脚本的方法 脚本后台运行 后台运行程
14 0
|
20天前
|
监控 Shell Linux
shell linux中用shell写一个占用CPU的脚本
shell linux中用shell写一个占用CPU的脚本
20 0
|
21天前
|
Shell Linux
linux shell 脚本实现:根据文件内容中的每行分隔符放入数组,根据规则打印日志并重新创建目录 备份文件
linux shell 脚本实现:根据文件内容中的每行分隔符放入数组,根据规则打印日志并重新创建目录 备份文件
20 0

相关产品

  • 云解析DNS
  • 推荐镜像

    更多