海阔中文网

129 views
6月 25 2021

ubuntu安装dns bind9 服务器

1 Install BIND
Install bind9 with apt.
sudo apt-get install -y bind9
2 Configuration
Private network address is 172.16.11.0/24.
Private network name is hkzww.com.
IP address of DNS server for private network is 172.16.11.70. This DNS server uses recursive query.
IP address of client is 172.16.11.250.
IP address of DNS server for internet is 172.16.11.1.
2.1 /etc/bind/named.conf.options
This is the configration file for BIND option.

Allow query from private network.
Allow recursive query.
Open 53/udp and 53/tcp if you running ufw.
options {
directory "/var/cache/bind";
listen-on port 53 { localhost; 172.16.11.0/24; };
allow-query { localhost; 172.16.11.0/24; };
forwarders { 172.16.11.1; };
recursion yes;
}
2.2 /etc/bind/named.conf.local
This configuration file for private network is included by /etc/bind/named.conf.

zone "hkzww.com" IN {
type master;
file "hkzww.com.zone";
};
2.3 /var/cache/bind/hkzww.com.zone
This is a zone file for private network.

DNS server hostname is server.
Client hostname is client.
If you need more, append A record.
$TTL 86400

@ IN SOA hkzww.com root.hkzww.com (
2021050600
3600
900
604800
86400
)

@ IN NS server
server IN A 172.16.11.70
client IN A 172.16.11.250
3 Validation
named-checkconf validates /etc/bind/named.conf and included files.

$ named-checkconf
named-checkzone validates zone file.

$ /usr/sbin/named-checkzone hkzww.com /var/cache/bind/hkzww.com.zone
zone hkzww.com/IN: loaded serial 2018050600
OK
4 Run BIND
Run BIND with systemd.

sudo systemctl enable bind9
sudo systemctl restart bind9
5 Excution result
Run nslookup on server.

$ nslookup server.hkzww.com localhost.localdomain
Server: localhost.localdomain
Address: ::1#53

Name: server.hkzww.com
Address: 172.16.11.70
Run nslookup on client.

$ nslookup client.hkzww.com 172.16.11.70
Server: 172.16.11.70
Address: 172.16.11.70#53

Name: client.hkzww.com
Address: 172.16.11.250

Written by 海阔中文网

海阔中文网真棒!


京ICP备11047313号-20