-
Notifications
You must be signed in to change notification settings - Fork 129
/
Copy pathupdate-systemd-resolve.sh
executable file
·49 lines (41 loc) · 1.17 KB
/
update-systemd-resolve.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
#
# Parses DHCP options from OpenVPN and calls systemd-resolved
# 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-systemd-reselve.sh
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
echo "IF_DNS_NAMESERVERS=$IF_DNS_NAMESERVERS" >&2
echo "IF_DNS_SEARCH=$IF_DNS_SEARCH" >&2
DNS=""
for dns in $IF_DNS_NAMESERVERS; do
DNS="$DNS --set-dns=$dns"
done
echo "$DNS"
DOMAIN=""
for domain in $IF_DNS_SEARCH; do
DOMAIN="$DOMAIN --set-domain=~$domain"
done
echo "$DOMAIN"
/usr/bin/systemd-resolve -i ${IFNAME} $DNS $DOMAIN
;;
esac