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?

This continues to work in Ubuntu 12.04 and later, even though NetworkManager now uses resolvconf to handle resolv.conf.
–
jdthoodDec 7 '12 at 8:25

2

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).
–
LekensteynMar 21 '14 at 10:02

This only changes dns for the current connection, but is there also a way for a Global DNS change?
–
rubo77Apr 28 at 20:43

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 RooneyDec 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 PereiraDec 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.zazenDec 25 '11 at 6:02

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.

+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 DavidsonAug 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 CoenenAug 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.
–
LassePoulsenAug 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 CoenenAug 16 '10 at 10:14

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.

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 CoenenAug 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 StimbergAug 15 '10 at 20:05

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.

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 SeveranceDec 25 '11 at 13:06

@ScottSeverance What it the system didn't have X
–
Amith KKDec 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 SeveranceDec 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.
–
AzendaleDec 25 '11 at 14:37

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:

I found that adding the line dns-nameserver ip to the interfaces file, setting the wired connection ipv4 settings to Automatic (DHCP) settings only and entering the DNS server IP and domain name. Also adding the local DNS IP to the DSL router static DNS section causes NetworkManager to include this local address in the resolv.conf file that it overwrites along with other info retrieved from the router. All of these together seems to make local DNS name resolution persistent - a surprisingly difficult task it seems. My need for local DNS is for mounting a Linux client to a Samba share using mount.cifs on a DHCP served network.