Last active
October 5, 2023 22:56
-
-
Save LeePorte/d08ac8d906a6dbc57d68f51ac1dcf3ef to your computer and use it in GitHub Desktop.
Updating openvpn DNS and domain options for resolvectl on Ubuntu 22.04+
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 | |
# | |
# Parses DHCP options from OpenVPN and calls resolvectl | |
# configuration file with DNS settings, so they will be used by | |
# systemd-resolved. | |
# | |
# To use set as 'up' script in your openvpn *.conf: | |
# up /etc/openvpn/update-resolvectl | |
IFNAME=$1 | |
case $script_type in | |
up) | |
for optionname in ${!foreign_option_*} ; do | |
option="${!optionname}" | |
echo $option >&2 | |
part1=$(echo "$option" | cut -d " " -f 1) | |
if [ "$part1" == "dhcp-option" ] ; then | |
part2=$(echo "$option" | cut -d " " -f 2) | |
part3=$(echo "$option" | cut -d " " -f 3) | |
if [ "$part2" == "DNS" ] ; then | |
IF_DNS_NAMESERVERS="$IF_DNS_NAMESERVERS $part3" | |
fi | |
if [[ "$part2" == "DOMAIN" || "$part2" == "DOMAIN-SEARCH" ]] ; then | |
IF_DNS_SEARCH="$IF_DNS_SEARCH $part3" | |
fi | |
fi | |
done | |
DNS="" | |
for dns in $IF_DNS_NAMESERVERS; do | |
DNS="$DNS $dns" | |
done | |
/usr/bin/resolvectl dns ${IFNAME} ${DNS} | |
DOMAIN="" | |
for domain in $IF_DNS_SEARCH; do | |
DOMAIN="$DOMAIN $domain" | |
done | |
/usr/bin/resolvectl domain ${IFNAME} ${DOMAIN} | |
;; | |
down) | |
/usr/bin/resolvectl revert ${IFNAME} | |
;; | |
esac |
Now there's a typo :-)
easc
should be
esac
@tsgsh Thanks for pointing that one out.
Works beautifully on Fedora 38. Thanks.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@redsie Thank you for pointing out my copy pasta error. I have also added a down case to make sure of a clean exit.