2

I have this resolv.conf even after disconnecting from VPN server (connection was established using openvpn --config <path>.ovpn):

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
# 127.0.0.53 is the systemd-resolved stub resolver.
# run "systemd-resolve --status" to see details about the actual nameservers
nameserver 10.4.X.X
nameserver 10.4.Y.Y
nameserver 127.0.0.53
search Z.ac.in

I want to get rid of search Z.ac.in and the 10.4 ns. However, I can't find them in /etc/resolvconf/resolv.conf.d/{head,base,tail}. I even did grep 10.4.X.X inside the /etc/resolvconf directory with no result. Similarly, my /etc/network/interfaces file is mostly empty:

# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback

For now I have just been restarting my pc to remove them. But how to remove them properly from the resolv.conf file?

  • Which vpn are you using? – kashish Jul 13 at 8:38
  • @kashish I am using openvpn with this command sudo openvpn --config <path>.ovpn. Version information: OpenVPN 2.4.4 x86_64-pc-linux-gnu [SSL (OpenSSL)] [LZO] [LZ4] [EPOLL] [PKCS11] [MH/PKTINFO] [AEAD] built on May 14 2019 – Gaurang Tandon Jul 13 at 12:16
  • What OS and version? – rtaft Jul 13 at 13:42
  • @rtaft Ubuntu 18.04 (Linux gt 5.3.0-62-generic #56~18.04.1-Ubuntu SMP Wed Jun 24 16:17:03 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux) – Gaurang Tandon Jul 13 at 14:01
  • Do you have directive "up" and "down" in your <path>.ovpn? If you have something like up /etc/openvpn/update-resolv-conf or up /etc/openvpn/update-systemd-resolved, make sure you have openvpn client call the script when you disconnect, with a down /etc/.... – Laurent Gosselin Jul 14 at 18:58
1
+50

Use sudo systemd-resolve --revert --interface vpn0 to reset resolv.conf after getting off the VPN.

If that works, you can run it automatically when disconnecting from the VPN by creating /etc/network/if-post-down.d/vpn0 with the following contents:

#!/bin/sh

if [ "$IFACE" = "vpn0" ]; then
    systemd-resolve --revert --interface vpn0
fi

Then chmod 755 /etc/network/if-post-down.d/vpn0 to allow it to execute.

Replace vpn0 in all above with your vpn interface.

| improve this answer | |
1

Probably, these settings are cleared when you force a network-manager restart. Try
sudo service network-manager restart

Still a rather brute solution but one level better than pc restart. If it works, it can be automated by putting a script in /etc/NetworkManager/dispatcher.d with contents:

#!/bin/sh
if [[ "$2"="vpn-down" ]]; then  
    /usr/sbin/service network-manager restart
fi

You could even diversify on the network interface by using parameter $1 in the test. Do not forget to make the script executable by :
sudo chmod +x /etc/NetworkManager/dispatcher.d/<yourscriptname>

| improve this answer | |
1

Try

sudo vi /run/resolvconf/interface/NetworkManager

You ma also use nano editor, Remove or replace nameserver and then run

sudo resolvconf -u

For more information see this or this.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.