Set Up Your Own BIND9 DNS Resolver on CentOS 8/RHEL 8

This tutorial will be showing you how to set up a local DNS resolver on CentOS 8/RHEL 8, with the widely-used BIND9 DNS software. There are many synonyms for DNS resolver, some of which are listed below. They all refer to the same thing.

  • full resolver (in contrast to stub resolver)
  • DNS recursor
  • recursive DNS server
  • recursive resolver

Also, be aware that A DNS server can also called a name server. Examples of DNS resolver are (Google public DNS server) and (Cloudflare public DNS server). The OS on your PC also has a resolver, although it’s called stub resolver due to its limited capability. A stub resolver is a small DNS client on the end user’s computer that receives DNS requests from applications such as Firefox and forwards requests to a recursive resolver. Almost every resolver can cache DNS response to improve performance, so they are also called caching DNS server.

Why Run Your Own DNS Resolver

Normally, your computer or router uses your ISP’s DNS resolver to query domain names in order to get an IP address. Running your own local DNS resolver can speed up DNS lookups, because

  1. The local DNS resolver only listens to your DNS requests and does not answer other people’s DNS requests, so you have a much higher chance of getting DNS responese directly from the cache on the resolver.
  2. The network latency between your computer and DNS resolver is eliminated (almost zero), so DNS queries can be sent to root DNS servers more quickly.

If you run a mail server and use DNS blacklists (DNSBL) to block spam, then you are advised to run a local DNS resolver to speed up DNS lookups. If you run your own VPN server on a VPS (Virtual Private Server), it’s also a good practice to install a DNS resolver on the same VPS.

You may also want to run your own DNS resolver if you don’t like your Internet browsing history being stored on a third-party server.

If you own a website and want your own DNS server to handle name resolution for your domain name instead of using your domain registrar’s DNS server, then you will need to set up an authoritative DNS server, which is different than a DNS resolver. BIND can act as an authoritative DNS server and a DNS resolver at the same time, but it’s a good practice to separate the two roles on different boxes. This tutorial shows how to set up a local DNS resolver and because it will be used on local host/local network, no encryption (DNS over TLS or DNS over HTTPS) is needed. Setting up a DoT or DoH server will be discussed in a future article.

Please note that you need to have root privilege when installing software on CentOS/RHEL. You can add sudo at the beginning of a command, or use su - command to switch to root user.

Install BIND9 on CentOS 8/RHEL 8

BIND (Berkeley Internet Name Domain) is an open-source DNS server software widely used on Unix/Linux due to it’s stability and high quality. It’s originally developed by UC Berkeley, and later in 1994 its development was moved to Internet Systems Consortium, Inc (ISC).

Run the following command to install BIND 9 on CentOS 8/RHEL 8 from the default repository. BIND 9 is the current version and BIND 10 is a dead project.

sudo dnf update
sudo dnf install bind

Check version information.

named -v

Sample output:

BIND 9.11.4-P2-RedHat-9.11.4-17.P2.el8_0.1 (Extended Support Version) <id:7107deb>

To check the version number and build options, run

named -V

centos 8 rhel 8 bind9

Now we can start BIND 9 with:

sudo systemctl start named

And enable auto start at boot time:

sudo systemctl enable named

You can check its status with:

systemctl status named

Hint: If the above command doesn’t quit immediately, press Q.

The BIND server will run as the named user, which is created during installation, and listens on TCP and UDP port 53, as can be seen by running the following command:

sudo dnf install net-tools
sudo netstat -lnptu | grep named

centos 8 rhel 8 bind dns resolver

Usually, DNS queries are sent to the UDP port 53. The TCP port 53 is for responses size larger than 512 bytes.

The BIND daemon is called named. (A daemon is a piece of software that runs in the background.) The named binary is installed by the bind package and there’s another important binary: rndc, the remote name daemon controller. The rndc binary is used to reload/stop and control other aspects of the BIND daemon. Communication is done over TCP port 953.

For example, we can check the status of the BIND name server.

sudo rndc status

centos 8 caching dns server

Configurations for a Local DNS Resolver

The named daemon on CentOS 8/RHEL 8 uses the root hints file at /var/named/ The root hints file is used by DNS resolvers to query root DNS servers. There are 13 groups of root DNS servers, from to

Out of the box, the BIND9 server on CentOS/RHEL provides recursive service for localhost only. Outside queries will be denied. Edit the BIND main configuration file /etc/named.conf.

sudo nano /etc/named.conf

In the options clause, you can find the following two lines.

listen-on port 53 {; };
listen-on-v6 port 53 { ::1; };

This makes named listen on localhost only. If you want to allow clients in the same network to query domain names, then comment out these two lines. (add double slashes at the beginning of each line)

// listen-on port 53 {; };
// listen-on-v6 port 53 { ::1; };

Find the following line.

allow-query { localhost; };

Add the network range from which clients can query domain names like below.

allow-query { localhost;;; };

The following line enables recursion service, which is fine.

recursion yes;

I also recommend adding the following directives in the options clause.

 // hide version number from clients for security reasons.
 version "not currently available";

 // enable the query log
 querylog yes;

centos 8 bind enable recursion service

Save and close the file. Then test the config file syntax.

sudo named-checkconf

If the test is successful (indicated by a silent output), then restart named.

sudo systemctl restart named

If you have a firewall running on the BIND server, then you need to open port 53 to allow LAN clients to send DNS queries.

sudo firewall-cmd --zone=public --permanent --add-rich-rule='rule family="ipv4" source address="" port protocol="udp" port="53" accept'

Reload firewall for the change to take effect.

sudo systemctl reload firewalld

This will open UDP port 53 to the private network Then from another computer in the same LAN, we can run the following command to query the A record of Replace with the IP address of your BIND resolver.

dig A @

Note: On CentOS/RHEL, you need to install the bind-utils package in order to use the dig command.

sudo dnf install bind-utils

Now on the BIND resolver, check the query log with the following command.

sudo journalctl -eu named

This will show the latest log message of the named service unit. I can find the following line in the log, which indicates that a DNS query for’s A record has been received from port 57806 of  IP address

named[1162]: client @0x7f4d2406f0f0 ( query: IN A +E(0)K (

Setting the Default DNS Resolver on CentOS 8/RHEL 8 Server

On the BIND server, we need to set as the default DNS resolver. You can check the current DNS resolver on CentOS 8/RHEL 8 with the following command.

cat /etc/resolv.conf

Sample output:

# Generated by NetworkManager

If you run the following command on the BIND server,

dig A

This DNS query can’t be found in BIND log. Instead, you need to explicitly tell dig to use BIND.

dig A @

To set BIND as the default resolver, first you need to find the name of your main network interface with the following command.

ip addr

Mine is ens3. Next, run the following command to edit the network interface configuration file. Replace ens3 with your own interface name. If the BIND resolver is running on a laptop connected using Wi-Fi, then you need to edit the ifcfg-wireless-network-name file.

sudo nano /etc/sysconfig/network-scripts/ifcfg-ens3

Find the DNS1 parameter and change its value to Note that if values for other parameters in this file are wrapped in double-quotes, then you also need to wrap with double-quotes.


If you can’t find the DNS1 parameter, then add the above line at the bottom. Save and close the file. Then restart NetworkManager for the change to take effect.

sudo systemctl restart NetworkManager

You can now check the content of /etc/resolv.conf again. As you can see, (BIND) is now the default DNS resolver on CentOS 8/RHEL 8.

change name server on centos 8

Setting Default DNS Resolver on Client Computers

Now you can configure other computes on the LAN to use the BIND server as DNS resolver. For Windows and MacOS computers, you can search on Google to find out how to set default DNS resolvers. Here I will show you how to set DNS resolver on Linux desktop computers. The following method works on any Linux distro that uses NetworkManager.

Click on the Network Manager icon on your Linux desktop to find the Edit connections. (On Some Linux distros, you need to right-click the Network Manager.)


Then select the current connection and click the cog icon to edit this connection.

dns server bind9

Select IPv4 settings tab, change method from Automatic(DHCP) to Automatic(DHCP) addresses only, which will prevent your system from getting DNS server address from your router. Then specify a DNS server. Here I enter the BIND server’s IP address in my LAN.

bind local dns server lan

Save your changes. Then restart NetworkManager for the changes to take effect.

sudo systemctl restart NetworkManager

Once you are reconnected, click the Network Manager icon again and select connection information. You can see that your Linux desktop computer is now using your BIND DNS server.

change dns server on linux

How to Disable IPv6 in BIND

If you don’t use IPv6 in your network, then it’s a good idea to turn off IPv6 in BIND, otherwise there will be a lot of errors about IPv6 in BIND log like below.

network unreachable resolving '': 2001:4178:2:1269:dead:beef:cafe:fed5#53
network unreachable resolving '': 2001:4178:2:1269:dead:beef:cafe:fed5#53
network unreachable resolving '': 2610:28:3090:3001:dead:beef:cafe:fed5#53
network unreachable resolving '': 2610:28:3090:3001:dead:beef:cafe:fed5#53

To disable IPv6 in BIND on CentOS/RHEL, simply open the /etc/sysconfig/named file

sudo nano /etc/sysconfig/named

And add the following line at the end of the file.


Save and close the file. Then restart named and you are done.

sudo systemctl restart named

Now run the following command. You can see that BIND is not listening on IPv6 address anymore.

sudo netstat -lnptu | grep named

Named Automatic Restart

If for any reason your Named process is killed, you need to run the following command to restart it.

sudo systemctl restart named

Instead of manually typing this command, we can make Named automatically restart by editing the named.service systemd service unit. To override the default systemd service configuration, we create a separate directory.

sudo mkdir -p /etc/systemd/system/named.service.d/

Then create a file under this directory.

sudo nano /etc/systemd/system/named.service.d/restart.conf

Add the following lines in the file, which will make Named automatically restart 5 seconds after a failure is detected.


Save and close the file. Then reload systemd.

sudo systemctl daemon-reload

To check if this would work, kill Named with:

sudo pkill named

Then check Named status. You will find Named automatically restarted.

systemctl status named


I hope this tutorial helped you set up a local DNS resolver on CentOS 8/RHEL 8 with BIND9. As always, if you found this post useful, then subscribe to our free newsletter to get more tips and tricks. Take care 🙂

Rate this tutorial
[Total: 3 Average: 5]

3 Responses to “Set Up Your Own BIND9 DNS Resolver on CentOS 8/RHEL 8

  • i have used this guide and installed bind9, its works like a charm 🙂
    but I need a web tool or web access for this software to maintain DNS records.
    more user friendly software for some users.
    please help me 🙂

    thanks in advance

    • This article is for running a local DNS resolver. It’s not for domain name owners to create DNS records.

      PS: I have already pointed this out in the article.

  • Piter yong
    8 months ago

    How to setup authoritive dns in centos 8

Leave a Comment

  • Comments with links are moderated by admin before published.
  • Your email address will not be published.
  • Use <pre> ... </pre> HTML tag to quote the output from your terminal/console.
  • Please use the community ( for questions unrelated to this article.
  • I don't have time to answer every question. Making a donation would incentivize me to spend more time answering questions.

The maximum upload file size: 2 MB.
You can upload: image.