3

The default DNS server was running too slowly, so I changed the configuration by adding a nameserver.

/etc/resolv.conf :

nameserver 202.102.192.68
nameserver 210.45.240.99
domain ***edu.cn
search ***edu.cn

But the file will is changed back to the default automatically after a while.
Is there any method to solve this problem?
Thanks!

belacqua
  • 23,120
kit.yang
  • 2,142
  • It's redundant to have config lines for both "search" and "domain", and "domain" will be ignored if "search" is set. – bgvaughan May 31 '11 at 01:18
  • Actually, if both "domain" and "search" are set, the last one is used. Ref: resolv.conf man page. – jdthood Oct 30 '12 at 08:14
  • Please note that resolv.conf handling has fundamentally changed since Ubuntu 12.04. – jdthood Dec 07 '12 at 08:18

3 Answers3

3

In a full ubuntu these files are rewritten by network-manager, It's better to manage these changes by using the GUI in System > Settings > Network Connections.

Without desktop I think this is controlled by a serie of entries in dbus / gconf. So if the network is reliable I think its better uninstall network manager and roll your own manual configuration.

Also there's something called nmcli which is a sort of command line tool for network-manager.

theist
  • 842
  • You can pre-empt network-manager by configuring network connections in /etc/network/interfaces. See "man 5 interfaces". If this is a desktop, not a laptop, and you use the same network configuration all the time, than you may prefer to use this approach, and to uninstall network-manager. – bgvaughan May 31 '11 at 01:24
3

The easiest way is probably to install the resolvconf package and then add whatever configuration you want to /etc/resolvconf/resolv.conf.d/head (you can ignore the scary warning, it's only there so that it ends up in the generated /etc/resolv.conf);    then run resolvconf -u to update /etc/resolv.conf.

Azendale
  • 11,891
  • This is the right answer. thiest's answer only applies to the desktop version of Ubuntu. kit.yang's answer removes some functionality for dhcp clients. This answer puts your DNS server choices up front but allows for some helpful fallbacks if those aren't reachable. – Son of the Wai-Pan Jun 22 '12 at 06:19
2

I found a method effective after trying some ways.
Modify the resolv.conf firstly.
Edit the configuration file of DHCP client.(location:/etc/dhcp3/dhclient.conf)
Change

    request subnet-mask, broadcast-address, time-offset, routers,
    domain-name, domain-name-servers, domain-search,host-name, 
    netbios-name-servers, netbios-scope, interface-mtu,
    rfc3442-classless-static-routes, ntp-servers;

Into

    request subnet-mask, broadcast-address, time-offset, routers, 
    host-name,netbios-name-servers, netbios-scope, interface-mtu,
    rfc3442-classless-static-routes, ntp-servers;

Delete domain-name, domain-name-servers, domain-search options.

kit.yang
  • 2,142
  • I'm wondering if this would still work correctly with on domain-name-servers removed.... – belacqua Feb 22 '11 at 09:06
  • @jgbelacqua It can get the IP address by DHCP.But the file(/etc/ resolv.conf )still be changed by network-manager if you click the option auto ethernet.Uninstall network-manager may be a good choice. – kit.yang Feb 22 '11 at 10:44