Jump to content

NetworkManager/DNS: Difference between revisions

From postmarketOS Wiki
R000n (talk | contribs)
Using static DNS
Anjanmomi (talk | contribs)
add instructions to change dns
Line 51: Line 51:
<pre>
<pre>
nameserver 127.0.0.1
nameserver 127.0.0.1
</pre>
== Manually set dns servers ==
First, list the connections:
<code>
$ nmcli con
</code>
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:
<pre>
$ 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
# /etc/init.d/networkmanager restart # apply new dns settings
</pre>
</pre>

Revision as of 06:03, 8 January 2023

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
# respawn_max defaults to 10, so this effectively gives NetworkManager 20 seconds to create the file


There might also be a problem with receiving MMS when connected to wifi (e.g. if your carrier's MMS server name will only resolve on their DNS server). There's a config option that tells it to check all DNS servers (instead of the presumed fastest one) which we should probably also set to handle this case.

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:

$ nmcli con

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
# /etc/init.d/networkmanager restart # apply new dns settings