NetworkManager/DNS

NetworkManager implements several dns clients.

default
The default method adds the DNS servers from the network connections. It gives a warning that "the libc resolver may not support more than 3 nameservers".

This can have issues with some applications (such as aerc or senpai) as the top 3 DNS servers may be inaccessible over your WiFi network.

(for example T-Mobile adds 4 DNS Servers which are only accessible on their network: https://rudism.com/solving-openvpn-dns-issues-on-android-clients/)

dnsmasq
Setting dns=dnsmasq in NetworkManager.conf by default will have issues, as NetworkManager will overwrite the /etc/resolv.conf which dnsmasq needs by default.

edit /etc/dnsmasq.conf

resolv-file=/var/run/NetworkManager/no-stub-resolv.conf

and add it to the default runlevel so openrc will autostart it.

issue: if dnsmasq crashes, network related things will totally fail to work.

With the above configuration, it's always crashing on boot... almost-certainly because /var/run/NetworkManager/no-stub-resolv.conf doesn't exist yet. To work around this, edit /etc/init.d/dnsmasq and add

supervisor=supervise-daemon respawn_delay=2
 * 1) respawn_max defaults to 10, so this effectively gives NetworkManager 20 seconds to create the file

You may want to add

strict-order

to your dnsmasq config, so that it tries every server, rather than just whichever one it wants. (This can be helpful if your carrier's servers don't resolve on non-carrier servers.

static
To prevent adding DNS servers by NetworkManager (for example, if you prefer do not use ISP's nameservers), add to /etc/NetworkManager/NetworkManager.conf

[main] dns=none

and add preferred DNS servers to /etc/resolv.conf, for example

nameserver 127.0.0.1

Manually set dns servers
First, list the connections:

In the NAME column, find the name of the connection for which you want to set the dns servers. You can set the ipv4 and ipv6 dns servers with the following command:

$ nmcli con mod $conNAME ipv4.dns "8.8.8.8 8.8.4.4" # set ipv4 to google's dns servers $ nmcli con mod $conNAME ipv4.ignore-auto-dns yes # ignore the ipv4 dns provided by the network $ nmcli con mod $conNAME ipv6.dns "2001:4860:4860::8888 2001:4860:4860::8844" # set ipv6 to google's dns servers $ nmcli con mod $conNAME ipv6.ignore-auto-dns yes # ignore the ipv6 dns provided by the network
 * 1) /etc/init.d/networkmanager restart # apply new dns settings