DNS (Domain name Service) is a service that provides domain name to IP address resolution for computers on the Internet.
All of these computers have a public domain name assigned by the internet authority ICANN (Internet Corporation for Assigned Names and Numbers).
Records of Domain names and IP addresses are maintained on DNS servers located in many locations.
For home networks DNS services are usually provided by their ISP (internet Service provider).
Home Network Devices and DNS
Home network devices like computers don’t have a public domain name and hence don’t have, or need an entry in the global DNS database.
So how do you locate devices on your home network if , for example, you need to access a local file share or printer?
Well DNS isn’t the only name resolution option and others methods are possible, and areused. Available methods are- broadcast, hosts, wins etc see local name resolution on home networks for more details.
However with the growing use of smart devices using a local DNS server for local name resolution is becoming popular.
The DNSMasq DNS Server
DNSMasq is a free and DNS and DHCP server for small computer networks and is provided with most Linux distributions.
In my home installation it is installed on a raspberry pi 3 which I also use as an MQTT server and also runs node-red networking flows.
Understanding The DNS Name Resolution Process
When you type in a web address in your web browser the web browser will first use the DNS protocol to contact the DNS server that has been configured for that device.
The DNS server will respond to the resolution request with the IP address of the website or return a not found message.
Once the browser has the IP address of the website it can connect to it.
If the DNS process fails you get a server not found displayed in the browser.
This process is the same for all applications e.g. email, Skype etc. They all rely on DNS working in the background.
DNS Server Addresses
The addresses of the DNS servers are usually given to the client machine by a DHCP server, but can also be assigned manually.(see Static IP Address on Windows 10 tutorial for an example).
Two DNS server addresses are normally assigned for redundancy purposes.
On Windows you can view the addresses using the ipconfig command.
Setting Up and Using Your Own Local DNS Server
The process for using your own local DNS server to resolve local names is as follows:
- Install And Configure DNSMasq
- Edit the Hosts File
- Test Using Nslookup.
- Configure your clients to use it via DHCP
Before you install DNSMasq it is important that you machine has a fixed IP address.
You can do this locally by edit the dhcp.conf file or usining the network GUI utility.
However the best way is to configure it at the router level.
Almost all routers let you assign a fixed IP address to a device.
To install on Linux (e.g ubuntu, Raspberry Pi) use:
sudo apt install dnsmasq.
Like almost all Linux applications configuration is via a text file /etc/dnsmasq.
The way it is configured is that all Local DNS requests are handled directly by the DNSMasq server and others that are for external resources are forwarded to the DNS servers you normally use. This is shown in the diagram below:
Although DNSMasq can be used as a DHCP server I use simply as a DNS server and so the DHCP configuration isn’t used.
Although you can use the /etc/dnsmasq.conf file and uncomment the settings you need I prefer to use my own and copy the original file for safe keeping.
Local Network Domain Name
Although you don’t actually need one I think it best to use one. Appendix G. Private DNS Namespaces recommends these names for internal networks
Note you should not use .local as it is use by mDNS.
Example Configuration File
This is the configuration file I use on my network.
From the screen shot above you can see I use a .home domain name. So all my machines will be of the form name.home this you can see in the hosts file ( shown later).
You can speed up DNS requests for you home network by increasing the cache size using
The default is 150 records. You can even use a large number as each record is only 100 bytes but I’m not sure if you will notice the difference.
DNSMasq uses the local local host file for the machine names so you will need to edit this with the names of your local machines. Below is my current hosts file.
If you make changes to the hosts file you will need to restart DNSMasq to pick up these changes.
The following commands you will find useful:
- sudo systemctl start dnsmasq #start the program
- sudo systemctl stop dnsmasq #stop the program
- sudo systemctl restart dnsmasq #restart the program
- sudo systemctl enable dnsmasq #start dnsmasq on boot
Before you configure you clients to use it you will need to test that it works as expected.
To do this use the nslookup tool. The follwing screen shot is taken from a windows 10 machine.
The first thing I do is to choose to use the DNSMasq server which is at IP address 192.168.1.21 and the I just enter a few names that I know are configured and then test external domain names using google.
Configuring the Clients
The easiest way and recommended way is to use your DHCP server to assign the DNS address.
Because two addresses are assigned you will assign the local address and an Internet server address.
You then need to wait until the clients renew their IP address and they will pick up the DNS server.
Common Questions and Answers
Q1- Is a Local DNS server really necessary?
A1- No not for most home networks?
Q2- Will it make my Internet activity faster?
A2- Yes as many addresses will be cached locally.
Q3- Is it necessary for Home Automation?
A3 No but it will make it easier.
Q4- What happens if my local DNS server is unavailable?
A4- The clients will use the public DNS server that you configured
Q5- Why not just use MDNS?
A6 It would be ideal but not all clients support it.
Having a local DNS server is very useful when you have lots of local machines and local network activity.
It will also be important with home automation devices that use IP.
In addition it should also make Internet activity faster as it uses a local cache.
However it involves another piece of hardware to configure and is not recommended for the non technical person.
- Home Network Subnet Mask Explained
- Name Resolution and DNS on Home Networks
- Understanding DHCP on Home Networks
- Multicast DNS (MDNS) on Home Networks