Ubuntu Linux Configure DNS Name Server IP Address ( DNS Client )

by on April 13, 2008 · 19 comments· LAST UPDATED November 11, 2008

in , ,

Q. How do I change existing name server IP address? How do I configure DNS name server IP address under Ubuntu Linux / Debian Linux? How do I configure DNS name resolution under Ubuntu Linux?

A. You need to edit /etc/resolv.conf file under Debian / Ubuntu Linux to set Name server IP address that the resolver should query. Up to 3 name server internet IP address can be defined. If there are multiple servers, the resolver library queries them in the order listed.

Ubuntu Linux Configure DNS Name resolution

Type the following command, enter:
$ sudo vi /etc/resolv.conf
Or use nano text editor:
$ sudo nano /etc/resolv.conf
Append your ISP name server or free fast dns nameservers IP address as follows:
nameserver 208.67.222.222
nameserver 208.67.220.220
nameserver 202.51.5.52

Save and close the file. Test your dns configuration by typing the following commands:
$ host yahoo.com
$ nslookup google.com
$ ping nixcraft.in

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 19 comments… read them below or add one }

1 Carl Friis-Hansen November 8, 2008 at 5:58 pm

I wonder if you are not missing something in the command:
$ sudo /etc/resolv.conf

What about:
$ sudo nano /etc/resolv.conf

or something?

Reply

2 nixCraft November 11, 2008 at 3:26 pm

Carl,

Thanks for the heads up. The faq has been updated.

Reply

3 Noah Spurrier October 19, 2009 at 11:14 pm

On Ubuntu the settings may get overwritten and will certainly get overwritten after a reboot. This is because Ubuntu dynamically generates the /etc/resolv.conf file.It generates this from file a template where it gives you convenient hooks to add in your own static nameserver definitions. Here is the more modern method.
Edit the template’s tail file:
sudo vim /etc/resolvconf/resolv.conf.d/tail
Add your nameserver lines:
nameserver 208.67.222.222
nameserver 208.67.220.220
nameserver 202.51.5.52
Save the file and then regenerate the resolv.conf file:
sudo /etc/init.d/resolvconf restart


Noah

Reply

4 Jaymes October 26, 2009 at 6:07 pm

@Noah

Default installation of Ubuntu Server 9.04 does not have this ‘feature’. /etc/resolvconf/ does not exist.

Reply

5 nixCraft October 26, 2009 at 6:41 pm

@Jaymes,

No it is available and /etc/resolv.conf file do exits for Ubuntu 9.04. It is part of default Linux C library.

@Noah, you need to setup dhclient to avoid overwriting, see:

How To: Make Sure /etc/resolv.conf Never Get Updated By DHCP Client

Reply

6 write March 28, 2011 at 5:52 am

how about restarting network? it should or not?

Reply

7 Ganixra July 24, 2011 at 7:20 pm

How to restart dns in my ubuntu system..

Reply

8 Thamizhannal August 24, 2011 at 7:38 am

Hi,
I am using ubuntu-10.04 and after, I add a new nameserver to /etc/resolv.conf. It does not seems to be updated.
Still I am getting “UnknownHostException” When a Clinet API from another node tries to communicate this machine.
Does it require any server restart? If so what is that?
Regards,
Thamizhannal

Reply

9 Satish Thakur November 14, 2011 at 6:27 am

Dear Team,

How do i can assign hostname & IP address in Ubuntu? If By using sudo? then how to install sudo…?

Thanks & Regards,
Satish.

Reply

10 kwak December 1, 2011 at 6:56 am

Hello,

It is perhaps silly question but I don’t really understand from where should I take ip addresses which should be added to /etc/resolv.conf.

I am speaking of those:

nameserver 208.67.222.222
nameserver 208.67.220.220
nameserver 202.51.5.52

Shall I ask my network provider about that or there is an easier method?

Thank you for help!

Reply

11 Ram Charan May 11, 2012 at 11:39 am

nameserver 208.67.222.222
nameserver 208.67.220.220
nameserver 202.51.5.52

Reply

12 Ram Charan May 11, 2012 at 11:41 am

nameserver 208.67.222.222
nameserver 208.67.220.220
nameserver 202.51.5.52

how to set name server in ubuntu.
pls help me………

Reply

13 Ivan Vatov June 27, 2012 at 6:30 pm

sudo nano /etc/resolvconf/resolv.conf.d/base
add your nameservers
nameserver 208.67.222.222
nameserver 208.67.220.220
nameserver 202.51.5.52
and restart resolvconf
sudo /etc/init.d/resolvconf restart
this automatically update /etc/resolv.conf file
thanks Noah Spurrier ;)

Reply

14 oserk October 2, 2012 at 11:25 am

Hi

I’m on ubuntu 12.04. and I had to edit the head part of resolv deamon

because the resolv.conf did had the first entry inside this:

nameserver 127.0.0.1

it never used the google nameservers that I defined in base or tail part… so what I did:

sudo nano /etc/resolvconf/resolv.conf.d/head
nameserver 8.8.8.8
nameserver 4.4.4.4
sudo /etc/init.d/resolvconf restart

and content of resolv.conf file did have correct order:

nameserver 8.8.8.8
nameserver 4.4.4.4

nameserver 127.0.0.1

and I finaly did have fast new domain that I registered half hour ago ready to test!

thanks to Ivan and others…

Reply

15 Jan Krojcer August 23, 2012 at 11:21 am

@Noah Spurrier: Thanks alot man, after a massive amount of research, I finally found your post. Every page that google turned up for “Setting a Static IP/DNS” involved editing the resolv.conf file… as if it didn’t get over-written. Editing the tail file works flawlessly, thanks a lot man.

Reply

16 nixCraft August 23, 2012 at 12:46 pm
17 Naveen March 4, 2013 at 12:30 pm

This no longer applies on 12.10 because /etc/resolv.conf is a symlink to /run/resolv.conf/resolv.conf. /run is a tmpfs.

$ ls -l /etc/resolv.conf
lrwxrwxrwx 1 root root 29 Nov 21 22:49 /etc/resolv.conf -> ../run/resolvconf/resolv.conf

Reply

18 shabnam November 2, 2013 at 5:20 pm

Hi,
how can i config DNS Server in ubuntu?
plz help me.

Reply

19 Ayra January 13, 2014 at 4:41 am

Hello!
I have a problem here..
On our class, we configured and created our own DNS. my DNS is cogmaharlika.com.
We changed our preferred DNS on our computer (Windows) to the IP Address of our server. I can access cogmaharlika.com but I cannot access google.com
I can ping it inside my virtualbox but in the command prompt of Windows I cannot ping it. My classmates and I have done the same thing.. Theirs is working but mine is not.
What is the problem?

Reply

Leave a Comment

Tagged as: , , , , , , , , ,

Previous Faq:

Next Faq: