域名解析接口:-一站式部署------内网环境部署bind9域名解析服务 - deb https://mirrors
内网环境部署bind9域名解析服务
1、查看系统版本—配置主机名—配置DNS
查看系统版本
root@named:~# cat /etc/os-release
PRETTY_NAME="Ubuntu 24.04.3 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04.3 LTS (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=noble
LOGO=ubuntu-logo
配置主机名
2、配置镜像源
root@named:~# cat /etc/apt/sources.list
deb https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse
3、安装域名解析服务-named
更新镜像源
root@named:~# apt update
安装DNS
root@named:~# apt install bind9 bind9utils bind9-doc -y
检查软件是否正确安装
root@named:~# named -v
BIND 9.18.39-0ubuntu0.24.04.2-Ubuntu (Extended Support Version)
4、编辑named配置文件
a、正向解析
b、反向解析
主配文件:/etc/bind/named.conf.options
区域声明配置:/etc/bind/named.conf.local
正向解析文件:/etc/bind/zones/db.域名
反向解析文件:/etc/bind/zones/db.IP
主配置编辑
root@named:~# cat /etc/bind/named.conf.options
options {
directory "/var/cache/bind";
// 监听所有网络接口
listen-on { any; };
listen-on-v6 { any; };
// 允许递归查询
recursion yes;
allow-query { any; };
// 配置转发DNS(上游DNS服务器)
forwarders {
8.8.8.8;
};
// DNSSEC验证
dnssec-validation auto;
// 权限设置 // 禁止区域传输
allow-transfer { none; };
};
区域声明配置编辑
root@named:~# cat /etc/bind/named.conf.local
zone "example.com" {
type master;
file "/etc/bind/zones/db.example.com";
allow-update { none; };
};
zone "192.168.192.in-addr.arpa" {
type master;
file "/etc/bind/zones/db.192.168.192";
allow-update { none; };
};
创建区域文件目录
mkdir -p /etc/bind/zones
正向解析配置编辑
root@named:~# cat /etc/bind/zones/db.example.com
$TTL 86400
@ IN SOA ns1.example.com. admin.example.com. (
2 ; Serial
3600 ; Refresh
1800 ; Retry
604800 ; Expire
86400 ) ; Negative Cache TTL
;
@ IN NS ns1.example.com.
;@ IN A 127.0.0.1
;@ IN A 127.0.0.1
;@ IN AAAA ::1
ns1 IN A 192.168.192.210
kb IN A 192.168.192.192
反向解析配置编辑
root@named:~# cat /etc/bind/zones/db.192.168.192
$TTL 86400
@ IN SOA ns1.example.com. admin.example.com. (
1 ; Serial
3600 ; Refresh
1800 ; Retry
604800 ; Expire
86400 ) ; Negative Cache TTL
;
@ IN NS ns1.example.com.
;1.0.0 IN PTR localhost.
;1.0.0 IN PTR localhost.
210 IN PTR ns1.example.com.
192 IN PTR kb.example.com.
5、验证
检查主配置
named-checkconf
检查区域文件
named-checkzone 1.168.192.in-addr.arpa /etc/bind/zones/db.192.168.1
zone 192.168.192.in-addr.arpa/IN: loaded serial 1
OK
named-checkzone example.com /etc/bind/zones/db.example.com
zone example.com/IN: loaded serial 2
OK
root@named:/etc/bind# systemctl restart named
root@named:/etc/bind# systemctl enable named 拼多多帮助力入口
root@named:/etc/bind# systemctl status named
● named.service - BIND Domain Name Server
Loaded: loaded (/usr/lib/systemd/system/named.service; enabled; preset: enabled)
Active: active (running) since Fri 2025-11-14 15:47:19 CST; 12s ago
Docs: man:named(8)
Main PID: 86090 (named)
Status: "running"
Tasks: 10 (limit: 9377)
Memory: 24.1M (peak: 24.5M)
CPU: 844ms
CGroup: /system.slice/named.service
└─86090 /usr/sbin/named -f -u bind
开放端口,也可关闭防火墙
ufw allow 53/tcp
ufw allow 53/udp
root@named:~# netstat -anput |grep 53
tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN 86090/named
客户端配置
root@named:~# cat /etc/resolv.conf
nameserver 192.168.192.210