Skip to content

Instantly share code, notes, and snippets.

@manno
Last active December 13, 2015 14:35
Show Gist options
  • Save manno/ef9c076c2000b111332d to your computer and use it in GitHub Desktop.
Save manno/ef9c076c2000b111332d to your computer and use it in GitHub Desktop.
OpenVPN commandline with NetworkManager and internal DNS
#!/bin/sh
nameserver=$(env | perl -anE 'print $F[-1] if /foreign_option.*DNS/')
if [ "$nameserver" ]; then
#echo "nameserver $nameserver" | resolvconf -a $dev
nmcli con modify $dev +ipv4.dns $nameserver
fi
domain=$(env | perl -anE 'print $F[-1] if /foreign_option.*DOMAIN/')
if [ "$nameserver" ] && [ "$domain" ]; then
org_dns=$(nmcli -t -f uuid c show --active | while read uuid; do
nmcli -t -f IP4.DNS c show $uuid | cut -f2 -d:
done | tail -1
)
nmcli con modify $dev +ipv4.dns-search $domain
qdbus --system org.freedesktop.NetworkManager.dnsmasq /uk/org/thekelleys/dnsmasq SetDomainServers "(" "$org_dns" "/$domain/$nameserver" ")"
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment