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
#****************************************
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
#****************************************
相关文章推荐
- 坚持#第272天~zabbix监控(安装、配置、shell脚本自动实现)
- CentOS6.7下使用非root用户(普通用户)编译安装与配置mysql数据库并使用shell脚本定时任务方式实现mysql数据库服务随机自动启动
- RPM包安装mysql,采用shell脚本实现自动安装、配置与卸载
- shell脚本实现自动编译安装
- 脚本自动实现DNS服务各区域配置文件
- [置顶] 编写shell脚本以及利用函数实现批量安装Linux服务配置
- Shell脚本实现自动安装zookeeper
- shell脚本实现linux下自动安装Oracle10g
- 使用shell脚本一键安装zabbix并配置客户端的自动发现选项
- 用tarball实现liferay自动安装部署12-配置脚本执行日志
- Shell脚本实现在Linux系统中自动安装JDK
- 脚本自动实现DNS服务各区域配置文件
- shell脚本实现linux下自动安装Oracle10g
- Shell小脚本:实现自动安装Asterisk和DAHDI
- Shell脚本实现Lamp自动安装
- shell脚本之dns安装配置
- Shell脚本实现在Linux系统中自动安装JDK
- [置顶] 编写shell脚本实现自动化搭建安装LNMP平台全过程配置详解
- shell脚本自动 进行配置免密登录,安装java环境,安装tomcat
- shell脚本实现自动创建模拟器、启动模拟器、自动安装apk并进行monkey测试