In a local area network (LAN), it’s often useful to have a dedicated DNS server to resolve hostnames to IP addresses for internal resources like web servers, file shares, and other devices. By setting up a DNS server within your LAN, you can avoid the need to type IP addresses manually every time you need to access a local service.
In this guide, we will walk you through setting up a DNS server using BIND (Berkeley Internet Name Domain), one of the most popular DNS software tools, on a Linux server (such as Ubuntu). This will allow you to resolve local names like netaport.lan to IP addresses within your LAN.
Prerequisites
- A Linux-based server (e.g., Ubuntu/Debian) with root or sudo access.
- A basic understanding of terminal commands.
- A LAN network set up with multiple devices that need to be resolved via DNS.
- The
bind9package installed (we’ll cover how to install it).
Step 1: Install BIND9 DNS Server
First, we need to install BIND9, which is the software we will use to run our DNS server.
Update your package list:
sudo apt update
Install BIND9:
sudo apt install bind9 bind9utils bind9-doc dnsutilsOnce installed, BIND9 should automatically start. You can verify that it’s running with:
sudo systemctl status bind9Step 2: Configure the DNS Server
Now that we have BIND9 installed, we need to configure it to resolve local domain names.
1. Configure /etc/bind/named.conf.local
Open the BIND configuration file to define your local zones.
sudo nano /etc/bind/named.conf.localAdd the following content to the file to create a zone for your local domain. For this example, we’ll use local.lan as the domain.
zone "local.lan" {
type master;
file "/etc/bind/db.local.lan";
};2. Create the Zone File
Next, create the file /etc/bind/db.local.lan that will contain your domain’s DNS records.
sudo nano /etc/bind/db.local.lan
This file will map hostnames to IP addresses on your LAN. Here’s an example of what it should look like:
$TTL 604800
@ IN SOA ns1.local.lan. root.local.lan. (
1 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS ns1.local.lan.
ns1 IN A 192.168.1.10 ; The IP address of your DNS server
server1 IN A 192.168.1.20 ; IP of server1.local.lan
server2 IN A 192.168.1.30 ; IP of server2.local.lan
- @ represents the domain name (
local.lan). - The NS record points to
ns1.local.lan, which is the DNS server (your own server). - The A records map hostnames (like
server1.local.lan,server2.local.lan) to their respective IP addresses.
3. Configure /etc/bind/named.conf.options
Edit the options file to specify where your DNS server can forward queries for external domains (i.e., the internet).
sudo nano /etc/bind/named.conf.options
Find the section marked options {} and update it with the following settings:
options {
directory "/var/cache/bind";
forwarders {
8.8.8.8; // Google DNS for external resolution
8.8.4.4; // Google DNS for external resolution
};
allow-query { any; }; // Allow queries from any IP
listen-on { any; }; // Allow DNS to listen on any interface
};
- Forwarders: Specifies external DNS servers (like Google’s DNS servers 8.8.8.8 and 8.8.4.4) for resolving external domains.
- allow-query: Allows DNS queries from any IP address on your network.
- listen-on: Specifies that the DNS server will listen for queries on all interfaces.
Step 3: Check Configuration and Restart BIND
Once you’ve made all the necessary changes, it’s time to check if the configuration files are valid.
sudo named-checkconf
sudo named-checkzone local.lan /etc/bind/db.local.lan- If there are no errors, restart the BIND9 service to apply the changes:
sudo systemctl restart bind9Step 4: Test the DNS Server
Now that the DNS server is up and running, test it from a client machine or your server itself.
Test DNS resolution using dig:
dig @192.168.1.10 server1.local.lan192.168.1.10 is the IP address of your DNS server.
This should return the IP address of server1 as defined in your db.local.lan file (e.g., 192.168.1.20).
Test on a client machine:
If you’ve configured client machines to use your DNS server, you can now resolve local hostnames like this:
ping server1.local.lan- This should return the IP address
192.168.1.20(or whatever you assigned toserver1).
- This should return the IP address
Step 5: Set DNS Server on Client Machines
For client machines on your LAN to use your DNS server, configure their network settings to point to the IP address of the DNS server (192.168.1.10 in our example).
On Linux, edit /etc/resolv.conf to include:
nameserver 192.168.1.10On Windows, go to Control Panel > Network and Sharing Center > Change Adapter Settings, right-click on your network adapter, select Properties, select Internet Protocol Version 4 (TCP/IPv4), and set the DNS server to 192.168.1.10.