How to disable a specific interface (dhclient) from resolvconf?

5,602

Solution 1

It is because Vagrant gives IP address to eth0 interface and the default setting is via DHCP. So if you want to do it with some patching here is the answer. All you need to do is edit your /etc/network/interfaces file by

nano /etc/network/interfaces

and add post-up resolvconf -d eth0.dhclient line after iface eth1 inet dhcp

so your /etc/network/interfaces would look like this

`

 # This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# Source interfaces
# Please check /etc/network/interfaces.d before changing this file
# as interfaces may have been defined in /etc/network/interfaces.d
# NOTE: the primary ethernet device is defined in
# /etc/network/interfaces.d/eth0
# See LP: #1262951
source /etc/network/interfaces.d/*.cfg

#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
auto eth1
iface eth1 inet dhcp
    post-up resolvconf -d eth0.dhclient
#VAGRANT-END` 

Solution 2

You have a few options: to write protect your resolv.conf, change the dhclient code and disable auto-update on the nameservers, or disable the DNS from the eth0.

Option 1: Write protecting /etc/resolv.conf file:

$ chattr +i /etc/resolv.conf

The +i option (attribute) write protects /etc/resolv.conf file on Linux so that no one can modify it including root user.

Option 2: dhclient-script hooks

Open the "resolvconf" file in dhclient folder:

$ nano /etc/dhcp/dhclient-enter-hooks.d/resolvconf

and change the code to:

make_resolv_conf(){
    :
}

Above script will replace make_resolv_conf() with our own function. This functions does nothing.

Option 3:

Open your ifcfg file:

$ nano /etc/sysconfig/network-scripts/ifcfg-eth0

and change the PEERDNS option to No:

PEERDNS=no

Bonus: This will not override your resolv.conf file or disable the DNS update, but will overwrite your route table. When you send some DNS request no matter what is the content in your resolv.conf file it check your route table and send the request to specific address:

$ ip route add 8.8.8.8/32 via 192.168.1.1
Share:
5,602
techraf
Author by

techraf

This user really prefers to keep an air of mystery about them.

Updated on September 18, 2022

Comments

  • techraf
    techraf over 1 year

    I am using ubuntu/trusty64 Vagrant box with VirtualBox. I want to permanently disable nameserver 10.0.2.3 set by resolvconf based on Vagrant's default eth0 interface.

    I have a network defined in my Vagrantfile as follows:

    server.vm.network "private_network", type: "dhcp", virtualbox__intnet: true
    

    This creates an interface eth1 with DHCP-pulled settings. The resolv.conf looks like this:

    # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
    #     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
    nameserver 10.0.2.3
    nameserver 10.20.30.40
    search local
    
    • nameserver 10.0.2.3 and search local come from from DHCP settings on eth0
    • nameserver 10.20.30.40 comes from from DHCP settings on eth1

    I want to retain the latter (10.20.30.40), while disabling settings coming from the eth0. I can remove it temporarily using resolvconf -d eth0.dhclient, but the settings keep reappearing after reboot.

    I know I can override all DHCP DNS settings with a static one as described here, however I want to retain DHCP settings from eth1 interface and disable only eth0.

    I tried editing /etc/resolvconf/interface-order and changed eth* to eth1 to no avail.

    Is there a way without editing the /etc/dhcp/dhclient-enter-hooks.d/resolvconf script?