Changes to /etc/resolv.conf discarded when connecting to a new network
Solution 1
As per the header on /etc/resolv.conf:
# 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
Try putting your change in
/etc/resolvconf/resolv.conf.d/base and they should get added to /etc/resolv.conf when it gets re-written every 15 minutes.
Solution 2
DISCLAIMER! Following this answer may cause unexpected problems if your DNS servers are managed as a part of network manager - while this will force the usage of the DNS servers you want above the
dnsmasq
system and the DNS servers in network manager's settings, it will do this for everything. As well, certain networks and/or connections may require you to use their DNS server(s) to get out to the internet with resolving things.
Edit /etc/resolvconf/resolv.conf.d/head
and add the nameserver 1.2.3.4
record here.
This works on 14.04 even on a Desktop install. I know this because I have a locally running DNS server (via bind9
) on my laptop locally for local zone resolution (since I do a lot of virtual machine stuff), and it becomes necessary to query my local DNS first above all else.
Related videos on Youtube
sudheer
Updated on September 18, 2022Comments
-
sudheer over 1 year
I have upgraded to 12.10 from 12.04 recently and I am having issues with connecting to the Internet.
I got an IP address and am able to ping other LAN IPs in the local network but I am unable to connect to the Internet and am even unable to ping www.google.com from a terminal.
Somehow making changes in
/etc/resolv.conf
and restartingresolvconf
service and rebooting works but I need to do this every time I connect to a new network. How do I make these changes permanent?Can someone suggest a solution to this issue?
-
Blacklight Shining about 11 years@medigeek This is incredibly unhelpful. The question is about DNS configuration in Ubuntu, not some intermittent Windows issue. Please take your “restart it and see if it works” comments elsewhere.
-
Blacklight Shining almost 11 years@medigeek no offense, but I absolutely fail to see how a “stuck” network card could affect DNS resolution. Even if it did, you advise shutting down all routers and modems? Really?
-
-
jdthood over 11 yearsIt is not true that /etc/resolv.conf gets rewritten every fifteen minutes. When resolvconf is installed and /etc/resolv.conf is a symbolic link to /run/resolvconf/resolv.conf, the target of /etc/resolv.conf can get rewritten when resolvconf's nameserver information changes, generally as a result of some change in network configuration.
-
jdthood over 11 yearsPutting nameserver information in /etc/resolvconf/resolv.conf.d/base is at best a workaround for the problem. Workarounds are good but a solution to the real problem would be better.
-
Thomas Ward about 9 yearsThis is no longer the case -
dnsmasq
is what/etc/resolv.conf
looks at (127.0.1.1) in a default install (since at least 14.04) -
Sergiy Kolodyazhnyy about 9 years@jdthood It's not a workaround, it's how it's been done for years
-
jdthood about 9 yearsNameserver information (addresses, search domain names) should be added to /etc/network/interfaces if you are using ifup to configure network interfaces. Nameserver information should be entered into the NetworkManager connections editor if you are using NM to configure interfaces. The only thing that really belongs in /etc/resolvconf/resolv.conf.d/base is resolver options such as
timeout
orndots
.