鹏博士上海分公司DNS搭建
项目介绍
由于现有系统已经年久失修且无精通人员,放弃原有gentoo架构,改用centos
对网内100万用户提供域名解析的后端递归服务
提供域名强制解析
项目愿景
逐步替代牙木后端的递归服务器。对递归服务器高掌控且高可靠
搭建步骤
单ip递归服务器搭建
-
最小化安装centos7
-
配置ip和更改国内yum源
-
关闭selinux
-
安装bind
[root@dubhe ~]# yum -y install bind-utils bind bind-devel bind-libs -
倒入配置
#这里用scp -r 以后可以用git配置秘钥直接从git服务器pull下来。 #chroot目录 [root@automation_and_git ~]# scp -r /chroot/ root@211.161.250.57:/ #scripts目录 [root@automation_and_git ~]# scp -r /scripts/ root@211.161.250.57:/ -
修改配置
#进入到chroot,创建启动脚本的软连接到chroot目录下 [root@dubhe chroot]# ls ansible.sh doc dump etc pdns.sh var [root@dubhe chroot]# ln -s /scripts/named_manager ./ [root@dubhe chroot]# ls ansible.sh doc dump etc named_manager pdns.sh var #找到一个named.dnsX文件改成named.conf [root@dubhe etc]# mv named.conf-dns8 named.conf #找到一个rndc.confX文件改成rndc.conf \\#改的文件名字都要是同一个。 [root@dubhe etc]# mv rndc.conf-dns8 rndc.conf #更改/chroot/var/文件夹的的所有人和所有组为named [root@dubhe chroot]# chown named:named var/ #还有一个文件也需要更改 [root@dubhe chroot]# chown named:named var/srrdata/ #运行脚本:如果出现最后一句话:“bind in /chroot already running :-)”则说明成功。 [root@dubhe chroot]# ./named_manager start /etc/acl/ck-TianJin:34: '221.239.0.101/30': address/prefix length mismatch /etc/acl/internal-telbgp:41: '10.64.104.1/28': address/prefix length mismatch /etc/acl/ck-TianJin:34: '221.239.0.101/30': address/prefix length mismatch /etc/acl/ck-TianJin:34: '221.239.0.101/30': address/prefix length mismatch /etc/acl/ck-TianJin:34: '221.239.0.101/30': address/prefix length mismatch bind in /chroot already running :-) #是否可以解析 [root@dubhe chroot]# nslookup www.baidu.com 211.161.250.57 Server: 211.161.250.57 Address: 211.161.250.57#53 Non-authoritative answer: www.baidu.com canonical name = www.a.shifen.com. Name: www.a.shifen.com Address: 112.80.248.76 Name: www.a.shifen.com Address: 112.80.248.75 -
无法解析的几种情况
未修改named.conf
[root@dubhe chroot]# nslookup www.baidu.com 211.161.250.57 1 # vim: set filetype=named.conf: 2 include "/etc/acl/acl.include_all"; 3 include "/etc/acl/internal-dns"; 4 options { 5 include "/etc/global-recursive"; ##下面这一条配置改成any或者本机ip,后面127.0.0.1 不要动。 ##ip之间用";"区分 6 listen-on port 53 { any;127.0.0.1; }; 7 # listen-on-v6 port 53 { 211.161.192.1, 211.161.192.73; }; 8 minimal-responses yes; 9 include "/etc/fixed-rrset-order"; 10 include "/etc/rrl"; 11 include "/etc/sortlist"; 12 # include "/etc/use-pdns-recursor"; 13 blackhole { 0.0.0.0/8; 46/8; 50/8; 95/8; };未配置防火墙
[root@dubhe chroot]# firewall-cmd --permanent --add-port=53/udp [root@dubhe chroot]# firewall-cmd --permanent --add-port=53/tcp [root@dubhe chroot]# firewall-cmd --reload -
配置路由
#cd到scripts,编辑脚本route-dns dubhe-dns1.com) NIC="em1";; \\把前面改成主机名 后面NIC改成本地网卡的名字 IP_19="124.14.16.19" \\自定义IP_xx="本机ip" GW_19="124.14.16.30" \\自定义IP_xx="本机网关" 4. get_my_ip() - add a match variable get_my_ip() { ip -4 addr show dev $NIC | \ awk '/^ inet / && ( \ /'$IP_dns1'\// || \ /'$IP_dns2'\// || \ /'$IP_dns3'\// || \ /'$IP_dns4'\// || \ /'$IP_dns5'\// || \ /'$IP_dns6'\// || \ /'$IP_dns7'\// || \ /'$IP_dns8'\// || \ /'$IP_ns1'\// || \ /'$IP_ns2'\// || \ /'$IP_ns5'\// || \ /'$IP_ns6'\// || \ /'$IP_ns7'\// || \ /'$IP_ns8'\// || \ /'$IP_yd1'\// || \ /'$IP_yd2'\// || \ /'$IP_yd3'\// || \ /'$IP_yd4'\// || \ /'$IP_re1'\// || \ /'$IP_re2'\// || \ /'$IP_re3'\// || \ /'$IP_re4'\// || \ /'$IP_dns19'\// || \ \\添加上面添加的IP 变量名字 注意||,不要复制最后一行$IP_test'这一行。 /'$IP_test'\// \ ) {print $2}' | \ sed -e 's/\/..$//' Determine my enviroment. case `get_my_ip` in $IP_dns1) MY_IP=$IP_dns1; MY_GW=$GW_dns1;; $IP_dns2) MY_IP=$IP_dns2; MY_GW=$GW_dns2;; $IP_dns3) MY_IP=$IP_dns3; MY_GW=$GW_dns3;; $IP_dns4) MY_IP=$IP_dns4; MY_GW=$GW_dns4;; $IP_dns5) MY_IP=$IP_dns5; MY_GW=$GW_dns5;; $IP_dns6) MY_IP=$IP_dns6; MY_GW=$GW_dns6;; $IP_dns7) MY_IP=$IP_dns7; MY_GW=$GW_dns7;; $IP_dns8) MY_IP=$IP_dns8; MY_GW=$GW_dns8;; $IP_ns1) MY_IP=$IP_ns1; MY_GW=$GW_ns1;; $IP_ns2) MY_IP=$IP_ns2; MY_GW=$GW_ns2;; $IP_ns5) MY_IP=$IP_ns5; MY_GW=$GW_ns5;; $IP_ns6) MY_IP=$IP_ns6; MY_GW=$GW_ns6;; $IP_ns7) MY_IP=$IP_ns6; MY_GW=$GW_ns6;; $IP_ns8) MY_IP=$IP_ns6; MY_GW=$GW_ns6;; $IP_yd1) MY_IP=$IP_yd1; MY_GW=$GW_yd1;; $IP_yd2) MY_IP=$IP_yd2; MY_GW=$GW_yd2;; $IP_yd3) MY_IP=$IP_yd3; MY_GW=$GW_yd3;; $IP_yd4) MY_IP=$IP_yd4; MY_GW=$GW_yd4;; $IP_re1) MY_IP=$IP_re1; MY_GW=$GW_re1;; $IP_re2) MY_IP=$IP_re2; MY_GW=$GW_re2;; $IP_re3) MY_IP=$IP_re3; MY_GW=$GW_re3;; $IP_re4) MY_IP=$IP_re4; MY_GW=$GW_re4;; $IP_dns19) MY_IP=$IP_dns19; MY_GW=$GW_dns19;; \\这里也要添加 $IP_test) MY_IP=$IP_dns19 MY_GW=$GW_dns19 # Mask DNS IPs I will use later in test enviroment. ADDRESS_LIST_ALL="$( sed \ -e '/124.14.16.30/d' \ \\添加本机ip的网段过滤 -e '/124.14./d' <<< "$ADDRESS_LIST_ALL" )"双IP递归服务器搭建