Install bind in CentOS 7
bind is a DNS server. To install bind on CentOS 7, run
1 |
yum install bind bind-utils -y |
Enable bind to start on boot
1 |
systemctl enable named |
Start bind
1 |
systemctl start named |
You can see status with
1 |
systemctl status named |
Setup firewall
You need to allow DNS ports UDP/TCP 53 in firewall. On CentOS 7, you can run
1 2 |
firewall-cmd --zone=public --permanent --add-service=dns firewall-cmd --reload |
Configure bind
By default bind only listens to local IP, to make it accessable from outside, you need to edit named.conf
1 |
vi /etc/named.conf |
Find
1 2 |
listen-on port 53 { 127.0.0.1; }; listen-on-v6 port 53 { ::1; }; |
Comment out those two lines by adding # at start of the lines.
1 2 |
#listen-on port 53 { 127.0.0.1; }; #listen-on-v6 port 53 { ::1; }; |
We need our DNS server access query from anyone on internet. For this, find
1 |
allow-query { localhost; }; |
Replace with
1 |
allow-query { any; }; |
Since we only want our DNS server resolve domains hosted on our server, disable recursion.
Find
1 |
recursion yes; |
Replace with
1 |
recursion no; |
Now restart bind with
1 |
systemctl restart bind |
Adding Domain to bind
To server a domain, you need to add the domain to bind. For this edit file
1 |
vi /etc/named.conf |
at end of the file, add
1 2 3 4 5 |
zone "DOMAIN.EXTN" IN { type master; file "/var/named/DOMAIN.EXTN.zone"; allow-update { none; }; }; |
Now create zone file
1 |
vi /var/named/DOMAIN.EXTN.zone |
Add following
1 2 3 4 5 6 7 8 9 10 11 12 13 |
$TTL 86400 @ IN SOA DOMAIN.EXT. admin.DOMAIN.EXT. ( 100 ; serial 1H ; refresh 1M ; retry 1W ; expiry 1D ) ; minimum @ IN NS ns1.DOMAIN.EXT. @ IN A YOUR_IP_ADDR_HERE ns1 IN A YOUR_IP_ADDR_HERE @ IN MX 10 mail.DOMAIN.EXT. mail IN A YOUR_IP_ADDR_HERE www IN A YOUR_IP_ADDR_HERE |
Restart bind
1 |
vi /var/named/DOMAIN.EXTN.zone |
You can verify domain is resolving with command
1 |
nslookup DOMAIN.EXT SERVER_IP_HERE |
See bind