My ISP's DNS server has problems resolving lots of important websites like google, github, gmail etc. As a hack I manually edited the /etc/resolv.conf file to Google's But the changed file remodifies to my ISP's DNS service when there's a network change. How do I automatically set /etc/resolv.conf to Google's DNS in the event of a network change and when I restart my computer using bash scripting.

I'm new to scripting on Linux. I'd need pointers on how to go about writing a script for this. Thanks.

  • The solution may vary based on your distro/network management setup. Could you tell us what distro you're using? – int_541 Mar 15 '20 at 8:52
  • I use an Ubuntu 18.04.4 LTS. – Emma Bashorun Mar 15 '20 at 9:01
  • 1
    Please refer to this answer on AskUbuntu: askubuntu.com/a/63163 – int_541 Mar 15 '20 at 9:02

/etc/resolv.conf file is usually managed by your network manager.

You can force your network manager to use specific DNS server.

For example, if you have Gnome, then in gnome-control-center you can do this:

enter image description here

The procedure will be similar for others network managers.

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.