BIND 主从配置
BIND 主从配置
环境:
master:172.31.182.144
slave:172.31.182.147
一、安装
yum install bind bind-chroot -y
(源码包:https://downloads.isc.org/isc/bind9/9.14.8/bind-9.14.8.tar.gz)
二、master配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | [root@master named] # cat /etc/named.conf |grep -Ev "//|^$" options { listen-on port 53 { 172.31.182.144; }; listen-on-v6 port 53 { ::1; }; directory "/var/named" ; dump- file "/var/named/data/cache_dump.db" ; statistics- file "/var/named/data/named_stats.txt" ; memstatistics- file "/var/named/data/named_mem_stats.txt" ; recursing- file "/var/named/data/named.recursing" ; secroots- file "/var/named/data/named.secroots" ; /* - If you are building an AUTHORITATIVE DNS server, do NOT enable recursion. - If you are building a RECURSIVE (caching) DNS server, you need to enable recursion. - If your recursive DNS server has a public IP address, you MUST enable access control to limit queries to your legitimate users . Failing to do so will cause your server to become part of large scale DNS amplification attacks. Implementing BCP38 within your network would greatly reduce such attack surface */ recursion yes ; dnssec- enable yes ; dnssec-validation yes ; /* Path to ISC DLV key */ bindkeys- file "/etc/named.iscdlv.key" ; managed-keys-directory "/var/named/dynamic" ; pid- file "/run/named/named.pid" ; session-keyfile "/run/named/session.key" ; }; logging { channel default_debug { file "data/named.run" ; severity dynamic; }; }; zone "adfile.wifi8.com" { type master; file "adfile.wifi8.com.hosts" ; allow-transfer {172.31.182.147;}; notify yes ; also-notify { 172.31.182.147; }; // 指定slave server的IP位址 }; zone "." IN { type hint; file "named.ca" ; }; include "/etc/named.rfc1912.zones" ; include "/etc/named.root.key" ; |
zone文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | [root@master named] # cat /var/named/adfile.wifi8.com.hosts $TTL 180 @ IN SOA ns1. test .com. root.adfile.wifi8.com. ( ; 22190928 ; serial 10S ; refresh 1H ; retry 1M ; expire 44H ) ; minimum IN NS ns1. test .com. IN NS ns2. test .com. ns1 IN A 172.31.182.144 ns2 IN A 172.31.182.147 adfile.wifi8.com. IN A 10.254.33.32 adfile.wifi8.com. IN A 10.254.33.34 |
各参数解析:http://dns-learning.twnic.net.tw/bind/intro6.html
启动:
systemctl restart named.service
三、slave配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | [root@node02 named] # cat /etc/named.conf |grep -Ev "//|^$" options { listen-on port 53 { 172.31.182.147; }; listen-on-v6 port 53 { ::1; }; directory "/var/named" ; dump- file "/var/named/data/cache_dump.db" ; statistics- file "/var/named/data/named_stats.txt" ; memstatistics- file "/var/named/data/named_mem_stats.txt" ; recursing- file "/var/named/data/named.recursing" ; secroots- file "/var/named/data/named.secroots" ; /* - If you are building an AUTHORITATIVE DNS server, do NOT enable recursion. - If you are building a RECURSIVE (caching) DNS server, you need to enable recursion. - If your recursive DNS server has a public IP address, you MUST enable access control to limit queries to your legitimate users . Failing to do so will cause your server to become part of large scale DNS amplification attacks. Implementing BCP38 within your network would greatly reduce such attack surface */ recursion yes ; dnssec- enable yes ; dnssec-validation yes ; /* Path to ISC DLV key */ bindkeys- file "/etc/named.iscdlv.key" ; managed-keys-directory "/var/named/dynamic" ; pid- file "/run/named/named.pid" ; session-keyfile "/run/named/session.key" ; }; logging { channel default_debug { file "data/named.run" ; severity dynamic; }; }; zone "adfile.wifi8.com" { type slave; file "adfile.wifi8.com.hosts" ; masters { 172.31.182.144; }; }; zone "." IN { type hint; file "named.ca" ; }; include "/etc/named.rfc1912.zones" ; include "/etc/named.root.key" ; |
启动后自动同步master解析配置:
systemctl restart named.service
添加域名脚本:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | #################master:################# #!/bin/bash read -p "Please enter the domain name you need to add:" DOMAIN read -p "Please enter the domain name corresponding to the IP record:" IP HOSTS_DIR= /mnt/sscp/data/named/hosts NAMED_CONFIG_DIR= /mnt/sscp/data/named/conf/named .conf #Create domain record file cat >${HOSTS_DIR}/${DOMAIN}.hosts<<EOF \$TTL 180 @ IN SOA ns1.sscp.mtr.com. root.${DOMAIN}. ( ; 0 ; serial 1D ; refresh 1H ; retry 1W ; expire 44H ) ; minimum IN NS ns1.sscp.mtr.com. IN NS ns2.sscp.mtr.com. ns1 IN A 128.164.250.26 ns2 IN A 128.164.250.27 ${DOMAIN}. IN A ${IP} EOF #Add named config cat >>${NAMED_CONFIG_DIR}<<EOF zone "${DOMAIN}" IN{ type master; file "${DOMAIN}.hosts" ; allow-transfer {128.164.250.27;}; }; EOF # Checkconf named config /mnt/sscp/app/named/sbin/named-checkconf #Restart named server /mnt/sscp/app/named/sbin/rndc -s 127.0.0.1 reload if [ $? = 0 ]; then echo "Added successfully!!" else echo "Add failed!! Please check" fi #################slave:################# #!/bin/bash read -p "Please enter the domain name you need to add:" DOMAIN HOSTS_DIR= /mnt/sscp/data/named/hosts NAMED_CONFIG_DIR= /mnt/sscp/data/named/conf/named .conf #Add named config cat >>${NAMED_CONFIG_DIR}<<EOF zone "${DOMAIN}" IN{ type slave; file "${DOMAIN}.hosts" ; masters { 128.164.250.26; }; }; EOF # Checkconf named config /mnt/sscp/app/named/sbin/named-checkconf #Restart named server /mnt/sscp/app/named/sbin/rndc -s 127.0.0.1 reload if [ $? = 0 ]; then echo "Added successfully!!" else echo "Add failed!! Please check" fi |
踩坑:
1、最后需要在主DNS服务器上的/var/named/ZONE_NAME.zone 文件里添加将该从服务的NS记录;
2、同时若想要实现主从服务器的数据同步,在修改好主服务器的/var/named/ZONE_NAME.zone 文件时,必须将该文件里的 序列号 增大才行,增大并保存退出后,主服务器会自动向从服务器推送(push)修改后的文件内容;
如对您有帮助,支持下呗!
微信

支付宝

【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· AI与.NET技术实操系列(六):基于图像分类模型对图像进行分类