Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I suspect that the name server provided by my ADSL modem/router is buggy. Whenever I browse to a website for the first time in ubuntu, resolving the domain name takes at least 15 seconds.

To work around that problem, I changed the nameserver configuration in /etc/resolv.conf from 192.168.1.1 (my ADSL modem) to 8.8.8.8 (google's primary DNS). This seems to fix the problem, but unfortunately my changes to /etc/resolv.conf are overwritten by "NetworkManager" at each startup.

What is the proper way to configure the name server IP in ubuntu 10.4?

share|improve this question

9 Answers 9

up vote 18 down vote accepted

If you have typical connection setup with the network manager and DHCP, try the following:

  1. Right click on the network manager icon in the panel and choose "Edit connections..."
  2. Select your connection from the wired or wireless tab, choose "Edit"
  3. (Enter your password if the connection is set as "system-wide available")
  4. Choose IPv4 settings tab
  5. Switch method to "Automatic (DHCP) addresses only"
  6. Enter the name server you want in the box "Additional DNS servers" and press "Apply"

That should do the trick.

share|improve this answer
1  
This continues to work in Ubuntu 12.04 and later, even though NetworkManager now uses resolvconf to handle resolv.conf. –  jdthood Dec 7 '12 at 8:25
    
If you are wondering where the configuration ends up, have a look at /etc/NetworkManager/system-connections/ (you will need administrative privileges to access those configuration files). –  Lekensteyn Mar 21 at 10:02

For headless servers where there's no X and management is via ssh or whatever, a command-line solution is necessary. If resolv.conf is not overwritten, then that's the correct place to change nameservers.

If resolv.conf does get overwritten then, on 14.04LTS at least, the files to edit are:

  • /etc/resolvconf/resolv.conf.d/head
  • /etc/resolvconf/resolv.conf.d/tail

I strongly suggest putting comment strings into files like these, such that they appear in the generated file (/etc/resolve.conf) and you can find them in the future. I start and end each file with a one-line comment of the form:

  • # ====== begin /etc/resolveconf/resolv.d/tail ======
  • # ====== end /etc/resolveconf/resolv.d/tail ======

and put the relevant directives between them.

share|improve this answer

Using the Terminal

You need to edit /etc/resolv.conf file 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.

Firstly type

sudoedit /etc/resolv.conf

Append your Preferred DNS server IP address as follows:

nameserver <preferred-ip1>
nameserver <preferred-ip2>
nameserver <preferred-ip3>

taken from: http://www.cyberciti.biz/faq/ubuntu-linux-configure-dns-nameserver-ip-address/

share|improve this answer
4  
Note that if the name servers are set via DHCP, /etc/resolv.conf will get overwritten. So this approach is only appropriate for machines with manual network configurations. Technically, you could do chattr +i /etc/resolv.conf to prevent the file from being modified (I did so years ago), but the best way for most machines would be jrg's approach in his answer: askubuntu.com/a/90263/13398. –  Scott Severance Dec 25 '11 at 13:06
    
@ScottSeverance What it the system didn't have X –  Amith KK Dec 25 '11 at 13:12
    
In that case, it's probably a server with manually-configured networking, in which case your answer is perfectly appropriate. But most Ubuntu machines run X and can easily handle the other approach. If a machine isn't running X but does have a suitable GUI installed, you could also run the graphical tools over SSH using ForwardX11=yes. –  Scott Severance Dec 25 '11 at 13:15
5  
If you are going to try to manually edit the /etc/resolv.conf file, the proper way to do it (so it is not overwritten) is to install the "resolvconf" package and then edit either /etc/resolvconf/resolv.conf.d/head or /etc/resolvconf/resolv.conf.d/tail. –  Azendale Dec 25 '11 at 14:37

You can change them like this.

First, click the network manager icon in your menubar, and the click the Edit Connections... item.

enter image description here

Now, switch to the "Wired" or "Wireless" tabs, depending on what you use - I use WiFi, so I'll be using that.

Select the name of your network, and click Edit...

Switch to the IPv4 tab, and then change it from automatic DHCP to Automatic (DHCP) addresses only.

Enter in your DNS server IP address.

enter image description here

Click save, and you're done!

share|improve this answer
    
While you can change the DNS server in the network settings on any PC it is best to change them in the actual router that connects to the internet so all connected devices benefit from it. –  Mark Rooney Dec 24 '11 at 21:29
2  
What if he does not have a router per se? Or he just wants to change the DNS for this computer / user? What if its just this one time? Maybe he actually does not have router access and wants to user another DNS server... I can add reasons to this list all night long. Good tip and answer @jrg. –  Bruno Pereira Dec 25 '11 at 1:12
4  
It is a nice graphical how-to for setting dns on a single machine with network manager. I would only point out you may set more then one, comma separated. 8.8.8.8,8.8.4.4. Setting DNS for a LAN can also be helpful, if the lan is large enough I personally either use the router or dnsmask. On a LAN, it is often easier to maintain a blacklist or proxy at a single location (router/dnsmask/squid) rather then on each client or each user on each client, but that is a little beyond the question asked here. –  bodhi.zazen Dec 25 '11 at 6:02

Click on the network indicator at the top right of the screen and pick Edit Connections.... Pick the connection you want to modify (probably from the Wired or Wireless tab and click the Edit... button.

Switch to the IPv4 Settings tab of the connection window and change the method from Automatic (DHCP) to Automatic (DHCP) addresses only. You should now be able to specify a DNS server IP address.

Save the connection and you should be good to go. You may have to reset the connection by picking it in the indicator's menu after changing the settings.

share|improve this answer

The best way to set a nameserver via the CLI, without NetworkManger, with a static address, or independent of the connection is this:

Install the resolvconf package.

Run

sudo nano /etc/resolvconf/resolv.conf.d/head

(ignore the scary warning. /etc/resolv.conf is autogenerated, so the warning is there so it will get put in /etc/resolv.conf when /etc/resolv.conf is generated.) To the end of the file, add

 nameserver <ip_of_nameserver>

Press Ctrl x and answer yes to saving the file. To finish up, regenerate /etc/resolv.conf so the changes are applied right now:

 sudo resolvconf -u
share|improve this answer

Another way to do this is to edit /etc/dhcp3/dhclient.conf you can do this by typing this in to the run dialog (appears by pressing Alt + F2)

gksudo gedit /etc/dhcp3/dhclient.conf

Then find the following line

#prepend domain-name-servers 127.0.0.1;

And change it to

prepend domain-name-servers 8.8.8.8;

This will make dhclient (the DHCP client that NetworkManager uses) prepend this to your dns servers, so resolve.conf will end up looking like this

nameserver 8.8.8.8
nameserver 192.168.1.1

This solution will work everywhere and you will always get the DNS that you have chosen as the primary one.

share|improve this answer
2  
It seems to me that Network Manager writes resolv.conf without consulting dhclient.conf –  daithib8 Jun 6 '11 at 10:52
    
on ubuntu 11.10 you need to modify /etc/dhcp/dhclient.conf instead of /etc/dhcp3/dhclient.conf –  Pawel Barcik Jun 7 '12 at 12:21
    
can put in multiple ones? –  PyRulez Apr 29 at 22:50

Another solution is to change your router's configuration to use the other DNS server. Just log into its admin and as long as it's not the router causing the problem, all your client machines get better DNS.

share|improve this answer
    
+1 Agreed if this is a problem that isn't likely to be resolved soon best to fix it on the router then it will be fixed for all machines on the network. I find its best to either use Google DNS or OpenDNS. –  Mark Davidson Aug 15 '10 at 17:22
1  
I've already done that, but the router then still acts as an intermediate name server between clients and the configured name server, and it is still very slow. –  Wim Coenen Aug 15 '10 at 17:38
1  
Many ISP's lock their routers so you can't change these settings, or have to pay to do so. –  Source Lab Aug 15 '10 at 20:53
    
@Wim If your router can't provide DNS resolution within a reasonable timeframe, say 50ms on a good connection, something is seriously wrong with it. So wrong it may be handling other traffic ineffectively. It might be time for a $30/£20 upgrade. –  Oli Aug 15 '10 at 22:33
1  
@Oli: The DNS problem only shows up when using the router from a linux box: I had the same problem with debian, but no issues with windows. I'm sure it's just some subtle compatibility issue. The router works fine otherwise. –  Wim Coenen Aug 16 '10 at 10:14

I believe if you change it under the network manager its self the changes with persist.

To use eth0 for example

Network Manager -> Wired -> Auto eth0 -> ipv4 Settings.

Set your DNS server to 8.8.8.8 and apply.

share|improve this answer
    
I had trouble finding anything called "network manager". There is a "System - Administration - Network tools" but that doesn't help. Eventually I found that I needed "System - Preferences - Network Connections". –  Wim Coenen Aug 15 '10 at 17:54
    
There's an network manager icon in the panel (the one displaying your network status) that you can right click to edit the connections. –  Marcel Stimberg Aug 15 '10 at 20:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.