Step-by-Step Guide to Setting Up a Local DNS Server Using BIND on Ubuntu
DNS (Domain Name System) servers are used to resolve domain names into IP addresses, allowing users to connect to websites using human-readable names. BIND (Berkeley Internet Name Domain) is a popular DNS server software used to manage DNS records. This guide walks you through setting up a local DNS server using BIND on Ubuntu, which can be used to resolve domain names for a private network.
← BackStep 1: Install BIND on Ubuntu
First, you need to install BIND9, the most recent version of the BIND DNS server, on your system. To install it, run the following command:
sudo apt update
sudo apt install bind9 bind9utils bind9-doc dnsutils
Step 2: Configure BIND as a Local DNS Server
Once the installation is complete, you need to configure BIND to act as a local DNS server. Start by editing the main configuration file:
sudo nano /etc/bind/named.conf.local
In this file, you will define the zones for which BIND will resolve DNS requests. For example, to create a zone for the domain example.local
, add the following configuration:
zone "example.local" {
type master;
file "/etc/bind/db.example.local";
};
This configuration tells BIND to use a zone file located at /etc/bind/db.example.local
to resolve DNS queries for the domain example.local
.
Step 3: Create the Zone File
Next, create the zone file where you will define the DNS records for your local domain. Run the following command to create a new zone file:
sudo nano /etc/bind/db.example.local
Inside the zone file, add the following configuration:
$TTL 604800
@ IN SOA example.local. root.example.local. (
2 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
@ IN NS example.local.
; A Records for the domain
@ IN A 192.168.1.10
www IN A 192.168.1.10
This configuration defines the A records for example.local
and www.example.local
, both pointing to the IP address 192.168.1.10
.
Step 4: Configure BIND to Listen on the Right Interfaces
By default, BIND listens on all interfaces. However, you can configure it to listen on specific interfaces or IP addresses for better security. To do this, edit the configuration file /etc/bind/named.conf.options
:
sudo nano /etc/bind/named.conf.options
In the options
section, find the listen-on
directive and set it to your desired IP address:
options {
listen-on { 127.0.0.1; 192.168.1.10; };
listen-on-v6 { none; };
directory "/var/cache/bind";
allow-query { any; };
};
Here, BIND is configured to listen on 127.0.0.1
(localhost) and 192.168.1.10
.
Step 5: Restart BIND Service
After configuring the DNS zones and options, restart the BIND service to apply the changes:
sudo systemctl restart bind9
Step 6: Test the DNS Server
Now that BIND is running and configured, test it by querying your DNS server. Use the dig
command to query for the domain you just set up:
dig @192.168.1.10 example.local
If everything is set up correctly, you should see the IP address you assigned to example.local
in the output.
Step 7: Set Up BIND to Start Automatically on Boot
To ensure that BIND starts automatically when the system boots, enable the service with the following command:
sudo systemctl enable bind9
Conclusion
You've successfully set up a local DNS server using BIND on Ubuntu. This server can now resolve domain names within your private network, allowing you to manage your internal network's DNS resolution easily. You can add more domain names and configure additional DNS records as needed.
← Back