Last active
October 13, 2017 21:53
-
-
Save alfredkrohmer/266b62365c772a9cd9d7ff1aca22f72b to your computer and use it in GitHub Desktop.
NetworkManager dispatcher script to add certain domains for a VPN device when using systemd-resolved (place in /etc/NetworkManager/dispatcher.d, make it executable and adapt VPN domains and connection name)
This file contains hidden or 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/bash | |
set -ex | |
# ---------------------------------------------------------------------------- | |
# Configuration: | |
case "$CONNECTION_ID" | |
in | |
"Some VPN name") # enter name of VPN connection in NetworkManager here | |
DOMAINS=( # enter domains that should be routed over the VPN here | |
some-domain.com | |
another-domain.net | |
) | |
;; | |
# repeat for more VPN connections | |
*) | |
exit 0 | |
;; | |
esac | |
# ---------------------------------------------------------------------------- | |
DBUS_PATH="/org/freedesktop/resolve1" | |
DBUS_IF="org.freedesktop.resolve1" | |
INTERFACE="$1" | |
IF_INDEX="$(cat "/sys/class/net/$INTERFACE/ifindex")" | |
if [[ $2 != "vpn-up" ]] | |
then | |
exit 0 | |
fi | |
DOMAIN_STR="" | |
FIRST=true | |
for DOMAIN in ${DOMAINS[@]} | |
do | |
if [[ $FIRST == true ]] | |
then | |
FIRST=false | |
else | |
DOMAIN_STR="${DOMAIN_STR}, " | |
fi | |
DOMAIN_STR="${DOMAIN_STR}('${DOMAIN}', true)" | |
done | |
gdbus call --system --dest $DBUS_IF --object-path $DBUS_PATH --method $DBUS_IF.Manager.SetLinkDomains $IF_INDEX "[$DOMAIN_STR]" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment