Configuring Bind for Name Server records to make your domain reachable from the INTERNET.

Reza Azimi
3 min readDec 5, 2020

If you have a website and you are trying to set your domain name and you are trying to do this by just Terminal and without any graphical screen, absolutely you figured out that there is nothing in the internet to help you configure your Bind9.

So In this article you will learn the way to configure step by step.

Here we are:

1.Set your hostname equal to one of your ServerNames like:

server.example.com

2.configure the interfaces in /etc/network/ like:

iface ens3 inet static
address 192.168.1.10
netmask 255.255.255.0

don’t forget to restart ‘networking’.

3.now let’s config the bind. You don’t need to edit all of the dbs just do it like bellow:

open /etc/bind/named.conf.local add this at the end of the file:

zone "example.com" IN {
type master;
file "/etc/bind/forward.example.com;
};
zone "1.168.192.in-addr.arpa" IN {
#1.168.192 is the reverse of 192.168.1 wit out the last part "10"
type maste;
file "/etc/bind/reverse.example.com";
}

cd /etc/bind

cp db.local  forward.example.com

now edit forward.example.com

;
; BIND data file for local loopback interface
;
$TTL 604800
@ IN SOA server.example.com root.server.example.com. (
2 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS server.example.com.
@ IN A xxx.xxx.xxx.xxx #your public static ip adress if you-
server IN A xxx.xxx.xxx.xxx #did you portforwards in NAT if you -
host IN A xxx.xxx.xxx.xxx #didn't import the static private ip-
client IN A xxx.xxx.xxx.xxx #address.
www IN A xxx.xxx.xxx.xxx
@ IN NS ns1.example.com.
@ IN A xxx.xxx.xxx.xxx
ns1 IN A xxx.xxx.xxx.xxx
@ IN MX 10 admin.example.com.
@ IN A xxx.xxx.xxx.xxx
admin IN A xxx.xxx.xxx.xxx
#this config contains email server configure too.

in the same directory cp forward.example.com reverse.example.com

now edit reverse zone like bellow:

;
; BIND data file for local loopback interface
;
$TTL 604800
@ IN SOA server.example.com root.server.example.com. (
2 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS server.example.com.
@ IN PTR exapmle.com.
server IN A xxx.xxx.xxx.xxx
host IN A xxx.xxx.xxx.xxx
client IN A xxx.xxx.xxx.xxx
www IN A xxx.xxx.xxx.xxx
10 IN PTR server.exapmle.com.
11 IN PTR client.exapmle.com.
@ IN NS ns1.exapmle.com.
ns1 IN A xxx.xxx.xxx.xxx
10 IN PTR ns1.exapmle.com.
@ IN MX 10 admin.exapmle.com.
admin IN A xxx.xxx.xxx.xxx
10 IN PTR admin.exapmle.com.
#the ten in above of hashtag is the end number of your ip 192.168.1.(10)
or xxx.xxx.xxx.(xxx)

forward and reverse zones are configured now.

4.Diagnostic the zones:

sudo named-checkconf -z /etc/bind/named.conf
sudo named-checkconf -z /etc/bind/named.conf.local
sudo named-checkzone forward /etc/bind/forward.example.com
sudo named-checkzone reverse /etc/bind/reverse.example.com

the outputs should show that the zones are loaded and there is no error.

now restart bind. if there was an error just use journalctl -xe and see the details more times it just a typo and mistakes like that.

5.Grantig permissions:

sudo chown -R bind:bind /etc/bind
sudo chmod -R 755 /etc/bind
sudo systemctl restart bind9
sudo systemctl enable bind9
ufw allow bind9
ufw allow 53
ufw allow 53/tcp
ufw allow 53/udp

go to /etc/network/interfaces again add this at the end of file:

dns-search example.com
dns-nameserver 192.168.1.10

after that, restart networking with sudo systemctl restart networking

nano this file : /etc/resolv.conf

add these at the end of the file:

nameserver 192.168.1.10
search example.com

restart the networking restart the NetworkManager

6. Test and debug:

now ping/nslookup/dig ns.example.com or server.example.com

NOW It’s WORKING

--

--