正向解析
#!/bin/bash
echo -e "----正在验证当前为仅主机还是NAT模式----"
ping -c 2 -w 2 www.baidu.com &> /dev/null
if [ $? -eq 0 ];then echo -e "检测当前为NAT模式,为您配置在线yum源"
mkdir -p /etc/yum.repos.d/repo.bak
mv -f /etc/yum.repos.d/* /etc/yum.repos.d/repo.bak &> /dev/null
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo &> /dev/null
yum clean all &> /dev/null
yum list &> /dev/null
echo -e "在线源已配置完成"
else
echo -e "检测当前为仅主机模式,为您配置本地yum源"
mount /dev/sr0 /mnt &> /dev/null
cd /etc/yum.repos.d/
mkdir -p /etc/yum.repos.d/repo.bak
mv -f /etc/yum.repos.d/* /etc/yum.repos.d/repo.bak &> /dev/null
echo '[local]
name=local
baseurl=file:///mnt
enabled=1
gpgcheck=0' > /etc/yum.repos.d/local.repo
yum clean all &> /dev/null
yum makecache &> /dev/null
df -h | grep "/mnt"
if [ $? -ne 0 ];then
echo -e "检测当前为仅主机模式,但光盘未挂载!"
else
echo -e "本地yum源已配置完成"
fi
fi
cd ~
yum -y install bind
read -p "请输入想要解析的域名,譬如(www.baidu.com): " a
b=`echo $a | awk -F '.' 'BEGIN{OFS="."}{$2=$2;print $2,$3}'`
c=`ifconfig | grep "inet" | awk 'NR==1 {print $2}'`
sed -i 's/127.0.0.1/any/' /etc/named.conf
sed -i 's/localhost/any/' /etc/named.conf
sed -i '14d' /etc/named.conf
sed -i '18,50d' /etc/named.rfc1912.zones
sed -i 's/localhost.localdomain/'$b'/' /etc/named.rfc1912.zones
sed -i 's/named.localhost/'$b'.zone/' /etc/named.rfc1912.zones
cd /var/named
cp -p named.localhost $b.zone
sed -i 's/@/'$b'./2' /var/named/$b.zone
sed -i 's/rname.invalid./admin.abc.com./' /var/named/$b.zone
sed -i '8s/@/'$b'./' /var/named/$b.zone
sed -i 's/127.0.0.1/'$c'/' /var/named/$b.zone
sed -i '10c www IN A '$c'' /var/named/$b.zone
systemctl stop firewalld
setenforce 0
systemctl start named
systemctl restart named
sed -i '2c nameserver '$c'' /etc/resolv.conf