I want to set the system to send DNS queries with a custom port, not 53. I added DNS=127.0.0.1 9053 to /etc/systemd/resolved.conf and DNS=127.0.0.1:9053 to /etc/systemd/networkd.conf. But now DNS queries are sent via the default DNS with port 53. What can I do?
DNS is a resolved.conf only setting. systemd docs are comprehensive and help navigating what to put where, no need to throw shit at the wall and see what sticks. :)
man resolved.conf:
OPTIONS
The following options are available in the [Resolve] section:
DNS=
A space-separated list of IPv4 and IPv6 addresses to use as system DNS servers. Each address can optionally
take a port number separated with ":", a network interface name or index separated with "%", and a Server
Name Indication (SNI) separated with "#". When IPv6 address is specified with a port number, then the
address must be in the square brackets. That is, the acceptable full formats are
"111.222.333.444:9953%ifname#example.com" for IPv4 and "[1111:2222::3333]:9953%ifname#example.com" for IPv6.
DNS requests are sent to one of the listed DNS servers in parallel to suitable per-link DNS servers acquired
from systemd-networkd.service(8) or set at runtime by external applications. For compatibility reasons, if
this setting is not specified, the DNS servers listed in /etc/resolv.conf are used instead, if that file
exists and any servers are configured in it. This setting defaults to the empty list.
Added in version 213.
TL;DR:
Create a drop-in for resolved and put the DNS= line there, with colon separating the port. Reload the config of the service to activate.
Don't slap a sudo in front where it doesn't belong. Run this as root, or the shell redirection will fail.
Or just create that file with these contents in any other way you like and feel comfortable with, it's not a magic incantation you have to use verbatim, after all.