resolv.conf permissions/ownership change after VPN disconnect

Solution 1:

I have the same issue. Maybe it is a bug. But I use NetworkManager. This solution does not work with it. The script does not run. I add my solution for it.

The NetworkManager has similar solution. The script must be added to the directory:

/etc/NetworkManager/dispatcher.d

I have added this file: "02-fix-resolv.conf.sh":

#!/bin/sh
if [ "$1" = "ppp0" -a "$2" = "vpn-up" ]; then
  echo "bleeeeeee je dole" > /tmp/testjenahore.txt
  chmod a+r /run/systemd/resolve/stub-resolv.conf.pppd-backup.ppp0
  chown systemd-resolve:systemd-resolve /run/systemd/resolve/stub-resolv.conf.pppd-backup.ppp0
fi

It works for me. And I finded out, that the file "/run/systemd/resolve/stub-resolv.conf.pppd-backup.ppp0" has permission and owner badly. And my script fix permission and awner, when the VPN goes UP. Then it works too if the VPN goes DOWN.

Solution 2:

For network-manager-pptp or network-manager-l2tp, the actual fix is to install the resolvconf package:

sudo apt install resolvconf

The resolvconf package makes sure NetworkManager does the /etc/resolv.conf handling, extract from /etc/ppp/ip-up.d/000resolvconf :

[ -x /sbin/resolvconf ] || exit 0

[ "$USEPEERDNS" ] || exit 0

case "$6" in
  nm-pptp-service-*|nm-l2tp-service-*|/org/freedesktop/NetworkManager/PPP/*)
    # NetworkManager handles it
    exit 0
    ;;
esac

See Ubuntu LP bug#1778946 for more details.