#!/bin/bash
yum install bind bind-utils.x86_64 -y &>/dev/null
systemctl start named
echo "服务已开启"
#修改named.conf配置文件
sed -i '/listen-on/s/127.0.0.1/any/' /etc/named.conf
sed -i '/allow-query/s/localhost/any/' /etc/named.conf
echo "named.conf修改成功"
#编写域名
cat >> /etc/named.rfc1912.zones <<OK
zone "xiaobin.com." IN {
type master;
file "xiaobin.com.zone";
allow-update { none; };
};
OK
echo "域名修改成功"
#切换到/var/named目录中
cd /var/named/
#配置解析文件
cat >> /var/named/xiaobin.com.zone <<EOF
$TTL 1D
@ IN SOA master.xiaobin.com. admin.xiaobin.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H) ; minimum
NS master
master A 192.168.37.102
IN MX 10 my.xiaobin.com.
www A 192.168.37.155
ftp A 192.168.37.201
* A 192.168.37.200
@ A 192.168.37.189
EOF
echo "解析文件配置成功"
#修改网卡,DNS和你主机一致
sed -i '/DNS3/s/8.8.8.8/192.168.37.102/' /etc/sysconfig/network-scripts/ifcfg-ens33
echo "--------正在开启网卡中------"
systemctl restart network
echo "---------网卡成功开启--------"
效果
[root@localhost data]#host xiaobin.com
xiaobin.com has address 192.168.37.189
[root@localhost named]#host www.xiaobin.com
www.xiaobin.com has address 192.168.37.155
这边记得要把防火墙和安全设置关闭,我做这个是提前关了
systemctl stop firewalld.service #关闭防火墙
setenforce 0 #临时关闭selinux