I want to connect to a public DNS Server (in this case Google's) by modifying the /etc/resolv.conf (which is automatically generated by NetworkManager). If I edit the content of the file via gedit /etc/resolv.conf to


(which are the IPs of Google's public DNS server), everything works fine and I do not even have DNS leaks, but if I run my Script:

echo "nameserver" > /etc/resolv.conf
echo "nameserver" >> /etc/resolv.conf

It does not work and I have no Internet-Connection at all.

  • Could you elaborate on what's showing, an error message maybe, ... also make sure your script is executable. – SYN Feb 6 '17 at 13:53
  • There is no error message, the script changes the resolv.conf like I want to the same thing I do via gedit, I just do not have an internet connection afterwards...:( – snippetry Feb 6 '17 at 13:58
  • Could you please post the output of following commands : ifconfig -a and netstat -rn – Vafa Feb 6 '17 at 14:36
  • It would be useful to edit your question to show the result of cat /etc/resolv.conf when it's working before you run your script and after your script has run (when it's broken). – Anthony Geoghegan Feb 6 '17 at 14:36
  • When you "have no Internet Connection" do you really mean that? What is then the result of running ping -c4 If you get no result please post the output of netstat -rn. But add these answers to your question; do not put them here in comments. – roaima Feb 6 '17 at 14:57

If your /etc/resolv.conf is autogenerated by NetworkManager, it will be overwritten at many network events like DHCP-Requests. This is done by the resolvconf package. See man resolvconf (head and tail files) for persistent change of the resolv.conf.

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.