How to preserve custom /etc/resolv.conf entries with DHCP in Debian Linux

In Debian Linux, when a network interface is configured to obtain an IP address automatically, the DHCP client utility writes the values received from the server over the content of file /etc/resolv.conf. Thus, custom entries that you had saved in this file, typically domain suffixes and domain name servers, are lost. If you need DHCP but also want to keep your configuration, do this:

  1. Edit file /etc/dhcp/dhclient.conf.
  2. Add the following lines, adjusting the values to match your needs.
supersede domain-name "";
supersede domain-search "";
prepend domain-name-servers;

This example specifies as the domain suffix, overriding whatever value is sent by the DCHP server. The value of the domain-search setting is appended to hostnames to form fully-qualified domain names. For example, if you try to connect to hostname foo (without a domain name), the DNS will be queried for the FQDN

The example also sets the domain name server to take priority over domain name servers provided by a DHCP server.

Leave a comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.