22

I set static DNS in /etc/resolvconf/resolv.conf.d/base file:

nameserver 8.8.8.8
nameserver 8.8.4.4

But my PC still obtains DNS from DHCP, this is my /etc/resolv.conf:

nameserver 192.168.100.2 
nameserver 8.8.8.8
nameserver 8.8.4.4

How to ignore obtained DNS from DHCP server?

cuonglm
  • 153,898
i2day
  • 576

2 Answers2

42

You can add this line to your /etc/dhcp/dhclient.conf:

supersede domain-name-servers 8.8.8.8, 8.8.4.4;

Then restart network or run dhclient to make changes.

From man dhclient.conf:

The supersede statement

       supersede [ option declaration ];

       If for some option the client should always  use  a  locally-configured
       value  or  values rather than whatever is supplied by the server, these
       values can be defined in the supersede statement.
cuonglm
  • 153,898
  • 4
    Also you can comment out in /etc/dhcp/dhclient.conf in request parameters that you don't want to request, for DNS it can be domain-name, domain-name-servers, domain-search. – Alex Nov 08 '16 at 10:20
  • 3
    @Alex I've noticed that some devices respond with options you didn't ask for. While you would think it would be ignored if not requested, the opposite appears true in practice: options returned unasked for are actually processed. Something to remember when configuring security sensitive devices... (e.g. send CIDR routes and bypasses traffic from the gateway.) – gertvdijk Aug 03 '19 at 20:13
-1

Drop a script in /etc/dhcp/dhclient-enter-hooks.d with this:

make_resolv_conf() { : ; }

Make it executable. Done. This is the only 100% sure-fire way I have found to keep dhclient from clobbering resolv.conf, apart from making resolv.conf immutable.

parzival
  • 109