Obtain IP from DHCP sever but set DNS servers statically on Debian

If you are sure you are using dhclient. You can:

1. Change dhclient setting (recommendded)

Edit the file /etc/dhcp/dhclient.conf, search for domain-name-servers, and delete it from the line:

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

2. Prevent /etc/resolv.conf from being overwritten

Running the following command as root or using sudo so that the file won't get overwritten again:

chattr +i /etc/resolv.conf

It's more or less a duplicated question to Can not set static DNS on debian. But I can't comment so I add this answer.


You can add:

supersede domain-name-servers 127.0.0.1;

to /etc/dhcp/dhclient.conf