Change DNS Server in Ubuntu from the Command Line

Changing the existing Domain Name Server IP address or configuring DNS name resolution under Ubuntu Linux is fairly simple with the command line.

All you need to do is edit the /etc/resolv.conf file. You may want to change your nameserver for a number of reasons. Suppose your existing nameserver is slow or is not updating properly; you can specify a new nameserver to get rid of all those problems.

Change DNS server using /etc/resolv.conf

Simply use your favourite text editor to edit the file /etc/resolv.conf as the superuser.

To use nano text editor:

sudo nano /etc/resolv.conf

Add one or more of your preferred DNS server address to the top of the file as follows:


Take care to replace the IP address(es) above with the IP address(es) of the nameserver that you want to use. Save and close the file. Test that everything is working correctly by running:


If those commands run correctly then you can almost be certain that everything is working as it should.

We hope you found this tutorial useful.

Thank Tutorial Arena for This Tutorial.
Show your appreciation with a +1...