Ubuntu: How to configure DNS servers in /etc/network/interfaces correctly for resolvconf?

  • All examples I have seen of configurations (/etc/network/interfaces) showed that you configure an interface and then underneath that gave the dns-* lines such as:

    auto eth0
    iface eth0 inet static
            ...
            dns-nameservers 127.0.0.2
            dns-search example.com my.example.com
    

    Now I am aware that the DNS protocol is independent of the transport mechanism. Therefore it shouldn't be per-se wrong to add an IPv6 address on the dns-nameservers line.

    However, since I am also configuring the interface for IPv6 anyway, it made sense to add the dns-nameservers line there:

    iface eth0 inet6 static
            ...
            dns-nameservers ::2
            dns-search example.com my.example.com
    

    ... or did it? Because when resolvconf creates /etc/resolv.conf it simply ignores all the IPv6 DNS servers. It also seems to ignore dns-search and dns-domain. The only line it seems to honor is the dns-nameservers line from the IPv4 configuration for eth0.

    What is the correct method of configuring DNS servers?


    Further circumstantial evidence as to why it should be part of each respective iface stanza. Quote from man 8 resolvconf:

    The ifup(8) program can be used to configure network interfaces according to settings in /etc/network/interfaces(5). To make ifup push nameserver information to resolvconf when it configures an interface, add dns- lines to the relevant iface stanza in /etc/network/interfaces. To add nameserver addresses add a line beginning with dns-nameservers.

    If you still have this problem then please post your whole /etc/network/interfaces file and the output of /usr/share/resolvconf/dump-debug-info which is included in the resolvconf package in Ubuntu 15.04.

  • It is correct to put dns-* options in either the iface eth0 inet static stanza or the iface eth0 inet6 static stanza. The options become active when the logical interface definition to which they belong becomes active.

    I just tested this on my own Ubuntu 15.04 machine which I normally configure with DHCP. I disabled NetworkManager and edited /etc/network/interfaces so that it looks like this:

    iface eth0 inet static
            address 192.168.178.22
            netmask 255.255.255.0
            dns-nameservers 8.8.8.8
            dns-search foo
    
    iface eth0 inet6 static
            address fe80::390:f5ff:fef7:96b9/64
            dns-nameservers ::2
            dns-search bar
    

    I then did

    $ sudo ifup eth0
    

    The results:

    $ ifconfig eth0
    eth0      Link encap:Ethernet  HWaddr 00:90:f5:f7:96:b9  
          inet addr:192.168.178.22  Bcast:192.168.178.255  Mask:255.255.255.0
          inet6 addr: fe80::390:f5ff:fef7:96b9/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2114609 errors:0 dropped:1 overruns:0 frame:0
          TX packets:1757693 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:2033346950 (2.0 GB)  TX bytes:1318685445 (1.3 GB)
          Interrupt:20 Memory:f7e00000-f7e20000 
    
    $ cat /etc/resolv.conf
    # 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 ::2
    nameserver 8.8.8.8
    search bar foo
    

    Note that the addresses, dns-nameservers and dns-search options from both stanzas are now active.

    [Updated 30 May 2015]

  • On my RPi running Ubuntu 16.04.2 LTS, my findings were as follows:

    Note: I uninstalled NetworkManager and just left resolvconf to do its stuff. (This is a fixed server so things don't change much network wise.)

    IF I had the dns-search and dns-nameserver lines on only ONE interface (the primary, wired one) but not the other (wlan0) then on reboot, about 95% of the time my /etc/resolv.conf file would be empty.

    e.g. When my interfaces file looked like this:

    # The primary network interface
    auto enxb827ebbfedcf
    iface enxb827ebbfedcf inet static
        address 192.168.1.16
        netmask 255.255.255.0
        network 192.168.1.0
        broadcast 192.168.1.255
        gateway 192.168.1.1
        dns-search summer.co.uk summer.vpn
        dns-nameserver 192.168.1.16 
        dns-nameserver 192.168.1.1
    
    # end stanza with clear line+
    
    # The loopback network interface
    auto lo
    iface lo inet loopback
    
    auto wlan0 
    iface wlan0 inet static
        address 192.168.1.17
        netmask 255.255.255.0
        network 192.168.1.0
        broadcast 192.168.1.255
        gateway 192.168.1.1 
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
    

    THEN after a reboot my resolv.conf would look 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
    

    However, on one or two reboots I noticed that it DID have what I wanted, e.g.

    # 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 192.168.1.16
    nameserver 192.168.1.1
    search summer.co.uk summer.vpn
    

    Solution When I gave BOTH interfaces (wired and wlan0) the dns-search and dns-nameserver lines, it all worked fine on every reboot (so far anyway)

    i.e. the following interfaces file works for me:

    # The primary network interface
    auto enxb827ebbfedcf
    iface enxb827ebbfedcf inet static
        address 192.168.1.16
        netmask 255.255.255.0
        network 192.168.1.0
        broadcast 192.168.1.255
        gateway 192.168.1.1
        dns-search summer.co.uk summer.vpn
        dns-nameserver 192.168.1.16 
        dns-nameserver 192.168.1.1
    
    # end stanza with clear line+
    
    # The loopback network interface
    auto lo
    iface lo inet loopback
    
    auto wlan0 
    iface wlan0 inet static
        address 192.168.1.17
        netmask 255.255.255.0
        network 192.168.1.0
        broadcast 192.168.1.255
        gateway 192.168.1.1
        dns-search summer.co.uk summer.vpn
        dns-nameserver 192.168.1.16 
        dns-nameserver 192.168.1.1
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
    

    and gives me the following correct resolv.conf after every reboot (so far)

    # 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 192.168.1.16
    nameserver 192.168.1.1
    search summer.co.uk summer.vpn
    

    I assume this duplicate config is normal, if somewhat redundant.

    Conclusion: If an interface (other than lo0) lacks dns-search and dns-nameserver information, then resolvconf puts nothing in your resolv.conf file. (It's as if ifup did the wlan0 interface second and ifup wiped resolv.conf or such like.)

    I'm not sure if this is a bug or not, feels wrong to me though.

    I can confirm this behavior on a fully patched 18.04. I think it's a bug. Just seeing that your answer is already 3 years old, so it's been in this broken state for years. So that makes me sad.

  • Editing network interfaces in order to add use your custom DNS is a way ...but for permanently modifying system-wide resolv.conf with your custom dnsnameserver you need to install resolvconf package (if it not already installed by default) and populate its base configuration file with your custom DNS nameservers values. Hope this short guide will help you for further configurations concerning resolv.conf DNS entries http://www.bytelinux.com/make-permanent-changes-to-resolv-conf-file-on-ubuntu/

    Welcome to Unix & Linux! Whilst this may theoretically answer the question, it would be preferable to include more of the essential parts of that guide here, and provide the link for reference.

    @MateiCezar: could you please elaborate? I'm not sure you even read my question to the end. Package `resolvconf` *is* installed. I'd like to `/etc/network/interfaces` to configure my DNS servers for IPv4 *and* IPv6 respectively.

  • You want to use IPv6 DNS servers on /etc/network/interfaces...just put your IPv6 DNS namesers entries on the specific network interface like this:

    dns-nameservers 2001:4860:4860::8844 2001:4860:4860::8888. 
    

    For permanent adding IPv6 dnsnamesers to resolv.conf use the same link i've added below and edit resolvconf base file by populating with your own IPv6 DNS namesers :

    nameserver 2001:4860:4860::8844
    nameserver 2001:4860:4860::8888 
    

    To configure /etc/network/interfaces with IPv6 use this guide http://www.bytelinux.com/configure-permanent-static-ip-address-alias-interfaces-debian-based-systems/ and replace IPv4 with IPv6 the as it follows: auto eth0

    iface eth0 inet6 static
            address 2800:210:0:1::3
            netmask 64
            gateway 2800:210:0:1::1
            dns-nameservers 2001:4860:4860::8844 
    

    Fixed your formatting. Again, my question clearly states that this doesn't result in those DNS servers for IPv6 being added to `/etc/resolv.conf`. If this somehow works for you it'd be useful to know the exact system version.

    let me get this straight...you want to use IPv6 DNS resolvers from /etc/network/interfaces and somehow adding them in that file doesn't work for you?

    I can add them to `/etc/network/interfaces` fine. What doesn't happen is that they get transferred into `/etc/resolv.conf` as they should. And I am trying to figure out what I am doing wrong, yes.

    Still didn't get it? Those DNS entries from /etc/network/interfaces gets transfered to /etc/resolv.conf or not? Usullay those namservers entries from interfaces never get transferred or written to /etc/resolv.com, they work on their own from that NIC and are not implemented system-wide. Just the /etc/resolv.conf file DNS are used by the interfaces who lack dnsnameservers entries.

    Sorry ...but still i do not understand what you try to achieve with this DNS nameservers entries.

    The /etc/resolv.conf file is written by a series of DHCP hook scripts and has nothing to do with /etc/network/interfaces file and the interfaces nameserver values that you add there!

    To the contrary, it has all to do with the entries in `/etc/network/interfaces`. If you read the documentation, you'll notice that. Check out the other "answer": same issue, no solution. The IPv4 DNS entries get transferred into `resolv.conf`, the rest (i.e. IPv6) does not. This is the issue my question is all about.

    Could you elaborate on this part, please: *they work on their own from that NIC and are not implemented system-wide*. Is there any documentation claiming that? Because so far I haven't come across any. If there was documentation supporting that claim, it would be quite some progress.

  • Why don't you implement those IPv6 DNS nameservers directly on /etc/resolv.conf system-wide file by editing resolvconf base file as suggested in my previous answer with the link and still continue to use network interfaces file? You can add a set of DNS IPv6 nameservers in /etc/resolv.conf and if you want to use other IPv6 nameservers for a specific NIC use them only on /etc/network/interfaces.

    what you mention in your last sentence is exactly the reason why I don't want to use the resolvconf base config and it's exactly what I *am* trying. Furthermore it is exactly what is failing.

    ok..I got it! But why you want to implement things in this manner?either way you only need those DNS nameservers to be accessible system-wide,is there any reason to transfer them from network/interfaces to resolv.conf, when you could just write them in both files and you're done!?

    Not sure how many machines you administrate, but for me it's enough to try and make my life easier. Since `/etc/network/interfaces` is supposed to do the job, I am trying to figure out what I am doing wrong.

License under CC-BY-SA with attribution


Content dated before 6/26/2020 9:53 AM