Skip to content

Instantly share code, notes, and snippets.

@abn
Last active May 14, 2024 12:56
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment