DNS server configuration is changed automatically

7,261

Solution 1

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.

Solution 2

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.

Solution 3

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.

Share:
7,261

Related videos on Youtube

kit.yang
Author by

kit.yang

Updated on September 17, 2022

Comments

  • kit.yang
    kit.yang over 1 year

    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!

    • bgvaughan
      bgvaughan about 13 years
      It's redundant to have config lines for both "search" and "domain", and "domain" will be ignored if "search" is set.
    • jdthood
      jdthood over 11 years
      Actually, if both "domain" and "search" are set, the last one is used. Ref: resolv.conf man page.
    • jdthood
      jdthood over 11 years
      Please note that resolv.conf handling has fundamentally changed since Ubuntu 12.04.
  • belacqua
    belacqua over 13 years
    I'm wondering if this would still work correctly with on domain-name-servers removed....
  • bgvaughan
    bgvaughan about 13 years
    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.
  • Avery Chan
    Avery Chan almost 12 years
    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.