Skip to content

Instantly share code, notes, and snippets.

@abn
Last active September 2, 2025 06:04
Show Gist options
  • Save abn/95301c56e4281d048ab5597d03629294 to your computer and use it in GitHub Desktop.
Save abn/95301c56e4281d048ab5597d03629294 to your computer and use it in GitHub Desktop.
NetworkManager Dispatcher: Configure systemd-resolved DNS server with custom port on connection up event
# NetworkManager connection config does not like custom ports for DNS servers
# we work around this by using a dispatcher to configure this on up events
# change these to your desired configs
CONNECTION_ID=wg0
DNS_TARGET=10.10.0.1:5300
DNS_SEARCH_DOMAIN=~testing
cat > /etc/NetworkManager/dispatcher.d/99-${CONNECTION_ID}.sh <<EOF
#!/usr/bin/env bash
[[ \${CONNECTION_ID} != "${CONNECTION_ID}" ]] || return 0
if [[ ${NM_DISPATCHER_ACTION} == "up" ]]
then
systemd-resolve --interface "${CONNECTION_ID}' --set-dns $DNS_TARGET --set-domain "$DNS_SEARCH_DOMAIN"
fi
EOF
@asg7443
Copy link

asg7443 commented Sep 2, 2025

You can specify a custom port like this:
sudo nmcli connection modify wg0 ipv4.dns dns+udp://10.10.0.1:5300 ipv4.dns-search ~testing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment