Domain Name System commonly referred as DNS is a decentralized naming system that automatically translates your internet address to a numeric machine address which your system uses. It’s a simple internet phonebook used to access online information using the domain names and translates them to IP addresses so as to enable the browser to load the internet resources.

In this tutorial, you will get to know how you can change DNS settings on Raspberry Pi and use the device as a DNS server.

How to change Raspberry Pi DNS Settings

There are different methods to change Raspberry Pi DNS settings and use the device as a DNS server. However, in this guide, we will show you the easiest approach to do the operation whose step-by-step instruction are provided as under:

Step 1: Update Raspberry Pi packages

Ensures that your packages on Raspberry Pi is updated which you can confirm by executing the following command:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/Raspberry-Pi-DNS-Settings-1.png" data-lazy- height="234" src="data:image/svg xml,” width=”954″>

If some packages require upgradation, run the following command to upgrade them.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/Raspberry-Pi-DNS-Settings-2.png" data-lazy- height="548" src="data:image/svg xml,” width=”955″>

Step 2: Installing DNS Utility

Next, you will need a DNS utility to configure DNS settings on Raspberry Pi. Here, we are using DNSMasq which is lightweight and easy to configure DNS utility and is an excellent choice for small networks. To install it, issue the below-mentioned command:

$ sudo apt install dnsmasq

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/Raspberry-Pi-DNS-Settings-3.png" data-lazy- height="507" src="data:image/svg xml,” width=”951″>

Step 3: DNSMasq Configuration

After the installation, it’s now time to configure DNSMasq to ensure the best setup for the DNS server. First, open the DNSMasq configuration file through following command:

$ sudo nano /etc/dnsmasq.conf

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/Raspberry-Pi-DNS-Settings-4.png" data-lazy- height="550" src="data:image/svg xml,” width=”955″>

Locate the following variables:

  • #domain needed
  • #bogus-priv
  • #no-resolv

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/Raspberry-Pi-DNS-Settings-5.png" data-lazy- height="550" src="data:image/svg xml,” width=”955″>

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/Raspberry-Pi-DNS-Settings-6.png" data-lazy- height="551" src="data:image/svg xml,” width=”955″>

Uncomment these three variables in the file by removing the # sign.

Also, find the following line and remove it from the file.

#server=/localnet/192.168.0.1

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/Raspberry-Pi-DNS-Settings-7.png" data-lazy- height="550" src="data:image/svg xml,” width=”955″>

Add the following lines there.

server=8.8.8.8

server=8.8.4.4

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/Raspberry-Pi-DNS-Settings-8.png" data-lazy- height="550" src="data:image/svg xml,” width=”955″>

The above server setup will now use Google DNS servers.

Now, locate the below-given line in the file:

Remove # from the line to uncomment it.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/Raspberry-Pi-DNS-Settings-9.png" data-lazy- height="550" src="data:image/svg xml,” width=”956″>

Then replace the cache-size from 150 to 1000.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/Raspberry-Pi-DNS-Settings-10.png" data-lazy- height="550" src="data:image/svg xml,” width=”953″>

This increases the size of cache allowing DNSMasq cache to save a high number of DNS requests.

Save the file by using “CTRL X”, Y to confirm and enter to proceed back to the command-line terminal.

Step 4: Restart DNSMasq

After completing the above step, restart the DNSMasq through the following command to apply the changes.

$ sudo systemctl restart dnsmasq

The above command will restart the DNSMasq service.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/Raspberry-Pi-DNS-Settings-11.png" data-lazy- height="50" src="data:image/svg xml,” width=”951″>

Step 5: Check DNSMasq Status

You can check DNSMasq status using the following command to ensure the service is running fine after the changes.

$ sudo systemctl status dnsmasq

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/Raspberry-Pi-DNS-Settings-12.png" data-lazy- height="550" src="data:image/svg xml,” width=”953″>

Step 6: Test DNS server

Now, test the DNS server through dig command which needs to be installed first using the following command:

$ sudo apt-get install dnsutils

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/Raspberry-Pi-DNS-Settings-13.png" data-lazy- height="375" src="data:image/svg xml,” width=”951″>

After the installation, execute the following script with the domain of your choice:

$ dig [domain] @localhost

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/Raspberry-Pi-DNS-Settings-14.png" data-lazy- height="550" src="data:image/svg xml,” width=”954″>

Check the query time in the above output.

Now, execute the above script again.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/Raspberry-Pi-DNS-Settings-15.png" data-lazy- height="532" src="data:image/svg xml,” width=”952″>

This time the Query time is 0 msec which ensures the address is cached.

Step 7: Make Raspberry Pi DNS server

In the final step, you will need to configure other devices to utilize the Raspberry Pi device as a DNS server. First find the IP address on your Raspberry Pi using the following command:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/Raspberry-Pi-DNS-Settings-16.png" data-lazy- height="505" src="data:image/svg xml,” width=”954″>

Next, change the DNS settings on your laptop by going into the “Network and Sharing Center” and click on the “Change adapter settings”.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/Raspberry-Pi-DNS-Settings-17.png" data-lazy- height="355" src="data:image/svg xml,” width=”864″>

Right click on the WIFI option and select “Properties”.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/Raspberry-Pi-DNS-Settings-18.png" data-lazy- height="257" src="data:image/svg xml,” width=”1123″>

Double click on the IPv4 option.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/Raspberry-Pi-DNS-Settings-19.png" data-lazy- height="467" src="data:image/svg xml,” width=”363″>

Then add the IP address of your Raspberry Pi in the DNS server option.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/Raspberry-Pi-DNS-Settings-20.png" data-lazy- height="452" src="data:image/svg xml,” width=”399″>

Click on the “OK” button to allow your device to use the Raspberry Pi DNS server. After that, you can surf the Internet on your system using the Raspberry Pi as a DNS server.

Conclusion

Raspberry Pi is a handy tool that can be used as a perfect DNS server, allowing users to browse the Internet world at a faster rate and in a more secure way. The above step-by-step instructions are useful to change the DNS settings on your Raspberry Pi using the DNSMasq utility configuration file. After properly configuring the DNS setting, you will then be able to use Raspberry Pi as a DNS server on your other devices as well.

About the author

<img data-del="avatar" data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/unnamesadadsasdd-150×150.jpg628efa0906103.jpg" height="112" src="data:image/svg xml,” width=”112″>

Awais Khan

I’m an Engineer and an academic researcher by profession. My interest for Raspberry Pi, embedded systems and blogging has brought me here to share my knowledge with others.