Skip Navigation

A custom port for DNS

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?

9
9 comments
  • 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.

    install -o0 -g0 -dm755 /etc/systemd/resolved.conf.d
    
    install -o0 -g0 -m644 <(cat <<EOF
    [Resolve]
    DNS=127.0.0.1:9053
    EOF
    ) /etc/systemd/resolved.conf.d/90-dns_port.conf
    
    cat /etc/systemd/resolved.conf.d/90-dns_port.conf 
    [Resolve]
    DNS=127.0.0.1:9053
    
    systemctl reload systemd-resolved
    
    • install -o0 -g0 -m644 <(cat <<EOF [Resolve] DNS=127.0.0.1:9053 EOF ) /etc/systemd/resolved.conf.d/90-dns_port.conf

      The output is an error: install: cannot stat '/dev/fd/63': No such file or directory.

      • 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.

9 comments