How to change DNS on a minimal networking setup

5,368

I resolved this issue by adding the following to my network profiles under /etc/systemd/network/*.network:

[DHCP]
UseDNS=false

By default, this is true, meaning DNS servers are pulled from the DHCP network connection. If I disable this feature, and input my own static DNS (ie OpenDNS), then I can ensure that I will only be using the DNS of my choosing.

Share:
5,368

Related videos on Youtube

modulitos
Author by

modulitos

Updated on September 18, 2022

Comments

  • modulitos
    modulitos over 1 year

    How can I replace my DNS? I am not using a network manager, except for systemd-networkd and wpa_supplicant for wireless, with wpa_cli. I'm on Arch Linux, if it matters.

    Although I can add DNS to my config, systemctl restart systemd-resolved overwrites /etc/resolv.conf (sym linked to /run/systemd/resolve/resolv.conf), or a reboot, somehow add the default ISP DNS's to /etc/resolv.conf. Does anyone know why, or how to resolve this issue to only use the DNS that I configured?

    When I edit /etc/resolv.conf to only contain

    nameserver 208.67.222.222
    nameserver 208.67.220.220 
    

    and run systemctl restart systemd-resolved or do a reboot, the default ISP DNS's are overwritten, and cat /etc/resolv.conf is this:

    # This file is managed by systemd-resolved(8). Do not edit.
    #
    # Third party programs must not access this file directly, but
    # only through the symlink at /etc/resolv.conf. To manage
    # resolv.conf(5) in a different way, replace the symlink by a
    # static file or a different symlink.
    
    nameserver 75.75.75.75
    nameserver 192.168.1.1
    nameserver 208.67.222.222
    # Too many DNS servers configured, the following entries may be ignored.
    nameserver 75.75.76.76
    nameserver 208.67.220.220
    

    As described under man resolved.conf, I ensured that I only have one config file, /etc/systemd/resolved.conf.d/resolv.conf, containing

    #  This file is part of systemd.
    #
    #  systemd is free software; you can redistribute it and/or modify it
    #  under the terms of the GNU Lesser General Public License as published by
    #  the Free Software Foundation; either version 2.1 of the License, or
    #  (at your option) any later version.
    #
    # See resolved.conf(5) for details
    
    [Resolve]
    DNS=208.67.222.222 208.67.220.220
    #FallbackDNS=8.8.8.8 8.8.4.4 2001:4860:4860::8888 2001:4860:4860::8844
    #LLMNR=yes
    

    and no other files defining my DNS from all the configuration files under here:

    /etc/systemd/resolved.conf
    
    /etc/systemd/resolved.conf.d/*.conf
    
    /run/systemd/resolved.conf.d/*.conf
    
    /usr/lib/systemd/resolved.conf.d/*.conf
    

    I don't believe I am running any dhcpcd or netctl service either, and systemctl | grep dhcpcd, and systemctl | grep netctl returns nothing.