This article will describe installing bind and running DNS server for private network.
Table of Contents
1 Install bind
Install bind and enable named.
$ sudo dnf install -y bind $ sudo systemctl enable named
Open port for bind.
$ sudo firewall-cmd --add-service=dns --permanent $ sudo firewall-cmd --reload
2 Configuration
Make /etc/named.conf to load zone file of private network.
$ cat <<EOF | sudo tee -a /etc/named.conf zone "hiroom2.com" in { type master; file "hiroom2.com.zone"; }; EOF
Allow query from 192.168.11.0/24.
$ sudo sed -e "s:allow-query.*:allow-query { 192.168.11.0/24; localhost; };:g" \ -e "s:listen-on port .*:listen-on port 53 { 192.168.11.0/24; 127.0.0.1; };:g" \ -i /etc/named.conf
Create zone file of private network. Append "A record" for hostname.
$ cat <<EOF | sudo tee /var/named/hiroom2.com.zone \$TTL 86400 @ IN SOA hiroom2.com root.hiroom2.com ( 2017010302 3600 900 604800 86400 ) @ IN NS server server IN A 192.168.11.79 EOF
Restart bind.
$ sudo systemctl restart named
2.1 Validation
named-checkconf validates /etc/named.conf.
$ named-checkconf
named-checkzone validates zone file.
$ named-checkzone hiroom2.com /var/lib/named/hiroom2.com.zone zone hiroom2.com/IN: loaded serial 2017010302 OK
3 Execution result
/etc/resolv.conf is as below. 192.168.11.79 is for resolving private network. 192.168.11.1 is for resolving internet.
$ cat /etc/resolv.conf <snip> search hiroom2.com nameserver 192.168.11.79 nameserver 192.168.11.1
Run ping command to "server".
$ ping -c 1 server.hiroom2.com PING server.hiroom2.com (192.168.11.79) 56(84) bytes of data. 64 bytes from 192.168.11.79: icmp_seq=1 ttl=64 time=0.224 ms --- server.hiroom2.com ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.224/0.224/0.224/0.000 ms