Skip to content

Instantly share code, notes, and snippets.

@gearhead
Created December 26, 2023 12:35
Show Gist options
  • Save gearhead/618c1d7252a15795d0aa1cf4fa6b346b to your computer and use it in GitHub Desktop.
Save gearhead/618c1d7252a15795d0aa1cf4fa6b346b to your computer and use it in GitHub Desktop.
how to hack wg-quick to work with systemd-resolved
Or "Make wg-quick not dependent on resolvconf"
This is a hack. No guarantees. IMO, this script should test to see if systemd-resolved is being used (if this is so
'resolvectl --version' will respond) and if not use the resolvconf command.
When this hack is done, wg-quick will work with NetworkManager cleanly as well.
No need for openresolve if you are using systemd-resolved
find this section of /usr/bin/wg-quick and find these lines:
HAVE_SET_DNS=0
set_dns() {
[[ ${#DNS[@]} -gt 0 ]] || return 0
{ printf 'nameserver %s\n' "${DNS[@]}"
[[ ${#DNS_SEARCH[@]} -eq 0 ]] || printf 'search %s\n' "${DNS_SEARCH[*]}"
} | cmd resolvconf -a "$(resolvconf_iface_prefix)$INTERFACE" -m 0 -x
HAVE_SET_DNS=1
}
unset_dns() {
[[ ${#DNS[@]} -gt 0 ]] || return 0
cmd resolvconf -d "$(resolvconf_iface_prefix)$INTERFACE" -f
}
note the 2 resolvconf commands... if you have resolved installed and running you will not
have this command. Change the section to look like this:
HAVE_SET_DNS=0
set_dns() {
[[ ${#DNS[@]} -gt 0 ]] || return 0
local nameservers=$(IFS=" "; echo "${DNS[*]}")
local searchdomains=$(IFS=","; echo "${DNS_SEARCH[*]}")
if [[ -n $searchdomains ]]; then
resolvectl dns "$INTERFACE" "$nameservers" --domain="$searchdomains"
else
resolvectl dns "$INTERFACE" "$nameservers"
fi
HAVE_SET_DNS=1
}
unset_dns() {
[[ ${#DNS[@]} -gt 0 ]] || return 0
# resolvectl reset "$INTERFACE"
# 'reset' doesn't work but commenting it out causes no problems
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment