Set dns in resolv.dnsmasq.conf if available and restore the original file when the service is stopped

This commit is contained in:
Julien Vaubourg
2017-08-30 14:28:45 +02:00
parent 50c3346c26
commit 33aafd1196

View File

@@ -61,7 +61,7 @@ is_serverip6route_set() {
is_dns_set() { is_dns_set() {
[ -e /etc/dhcp/dhclient-exit-hooks.d/ynh-vpnclient ]\ [ -e /etc/dhcp/dhclient-exit-hooks.d/ynh-vpnclient ]\
&& grep -q ${ynh_dns0} /etc/resolv.conf && ( grep -q ${ynh_dns0} /etc/resolv.conf || grep -q ${ynh_dns0} /etc/resolv.dnsmasq.conf )
} }
is_openvpn_running() { is_openvpn_running() {
@@ -104,9 +104,14 @@ set_serverip6route() {
} }
set_dns() { set_dns() {
resolvconf=/etc/resolv.conf
[ -e /etc/resolv.dnsmasq.conf ] && resolvconf=/etc/resolv.dnsmasq.conf
cp -fa "${resolvconf}" "${resolvconf}.ynh"
cat << EOF > /etc/dhcp/dhclient-exit-hooks.d/ynh-vpnclient cat << EOF > /etc/dhcp/dhclient-exit-hooks.d/ynh-vpnclient
echo nameserver ${ynh_dns0} > /etc/resolv.conf echo nameserver ${ynh_dns0} > ${resolvconf}
echo nameserver ${ynh_dns1} >> /etc/resolv.conf echo nameserver ${ynh_dns1} >> ${resolvconf}
EOF EOF
bash /etc/dhcp/dhclient-exit-hooks.d/ynh-vpnclient bash /etc/dhcp/dhclient-exit-hooks.d/ynh-vpnclient
@@ -177,7 +182,11 @@ unset_serverip6route() {
} }
unset_dns() { unset_dns() {
resolvconf=/etc/resolv.conf
[ -e /etc/resolv.dnsmasq.conf ] && resolvconf=/etc/resolv.dnsmasq.conf
rm -f /etc/dhcp/dhclient-exit-hooks.d/ynh-vpnclient rm -f /etc/dhcp/dhclient-exit-hooks.d/ynh-vpnclient
mv "${resolvconf}.ynh" "${resolvconf}"
} }
stop_openvpn() { stop_openvpn() {