1、安装bind9、dnsutils
apt install -y dnsutils bind9
2、修改配置文件
修改静态IP
nano /etc/network/interfaces
auto ens33
allow-hotplug ens33
iface ens33 inet static
address 192.168.200.100/24
gateway 192.168.200.254 #网关地址
重启网卡systemctl restart networking.service
nano /etc/bind/named.conf.default-zones 添加:
zone "xs.com" {
type master;
file "/etc/bind/xs.zone";
};
zone "200.168.192.in-addr.arpa" { #此处要对应自己的ip
type master;
file "/etc/bind/com.zone";
};
复制正向配置文件、反向配置文件
cd /etc/bind
cp -a db.local xs.zone
cp -a db.127 com.zone
编辑xs.zone正向解析,注意所用域名后面都有“.”
;
; BIND data file for local loopback interface
;
$TTL 604800
@ IN SOA xs.com. admin.xs.com. (
2 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS ns.xs.com.
@ IN A 192.168.200.200
ns IN A 192.168.200.200
www IN A 192.168.200.200
编辑com.zone反向解析
;
; BIND data file for local loopback interface
;
$TTL 604800
@ IN SOA xs.com. admin.xs.com. (
2 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS ns.xs.com.
100 IN PTR www.xs.com.
修改nano /etc/resolv.conf :
nameserver 192.168.200.100
search xs.com
重启服务systemctl restart bind9
查询验证
nslookup xs.com
nslookup 192.168.200.100
若是配置根域服务器,在配置文件中添加
zone "." {
type master;
file "/etc/bind/db.root";
};
并复制正反向模板,并修改。
nano db.root
;
; BIND data file for local loopback interface
;
$TTL 604800
@ IN SOA @ none. (
1 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS @
@ IN A 192.168.200.100
* IN A 192.168.200.100
重启服务,nslookup验证。