Home » Linux » Tips » Linux Manual Dns

How to change DNS servers on Linux (Ubuntu/RedHat/All Distros)

Here’s a quick tutorial for a simple but important task – manually setting the DNS server on your Linux system.

The steps in this tutorial should work for all Linux distributions – both server and desktop.

Manually setting your DNS server is particularly useful if you’re setting up a Pi-Hole ad blocker.

Backup Existing DNS Configuration

If an existing manual DNS configuration exists, back it up by copying it to a new file:

sudo cp /etc/resolv.conf /etc/resolv.conf.bak

Edit Linux DNS Configuration

The nano text editor will edit or create a text file:

sudo nano /etc/resolv.conf

If no configuration is set, the editor may be empty. If there is an existing DNS configuration it will look something like this:

nameserver 8.8.8.8
nameserver 8.8.4.4

Above, the primary and secondary DNS servers are set to use Google’s DNS service. The primary DNS server is on the first line, the secondary on the second line.

You can edit these values to be whatever you want For example, if you have set up your own DNS server (for example, to so set up ad blocking with Pi-Hole) at 192.168.1.202, your configuration might look like this:

nameserver 192.168.1.202
nameserver 8.8.4.4

I’ve left the secondary DNS server as Google’s, so if my own DNS server fails, or is unable to perform a lookup, it will be used instead.

Save by pressing Ctrl+X and then Y to confirm then reboot your computer:

sudo reboot
SHARE:
Photo of author
Author
I'm Brad, and I'm nearing 20 years of experience with Linux. I've worked in just about every IT role there is before taking the leap into software development. Currently, I'm building desktop and web-based solutions with NodeJS and PHP hosted on Linux infrastructure. Visit my blog or find me on Twitter to see what I'm up to.

Leave a Comment