Last active
August 22, 2020 18:18
-
-
Save viliampucik/caffddb1731a86518e4f393f1ebd0c0e to your computer and use it in GitHub Desktop.
Always prefer global DNS and use interface DNS (obtained via DHCP) just for routed domains
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
INTERFACE=$1 | |
ACTION=$2 | |
# DNS modification makes sense for active (up and vpn-up) interfaces only | |
[[ "${ACTION}" =~ up$ ]] || exit 0 | |
# Disable DNS default route for all interfaces to prefer global DNS | |
resolvectl default-route "${INTERFACE}" no | |
DOMAINS=$(resolvectl domain "${INTERFACE}" | cut -d: -f2) | |
# Remove "~." route domain from all interfaces to prefer global DNS | |
[[ "${DOMAINS}" =~ ~\. ]] || exit 0 | |
DOMAINS="${DOMAINS//~.}" | |
if [[ -z "${DOMAINS// }" ]]; then | |
resolvectl domain "${INTERFACE}" '' | |
else | |
# Noting (route) domains are separate arguments and should be passed without enclosing double quotes | |
resolvectl domain "${INTERFACE}" ${DOMAINS} | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The script removes "~." - the default route domain from each active interface to enforce global DNS server configured in /etc/systemd/resolved.conf.
Usage