First, /etc/resolvconf/resolv.conf.d/head
can be edited by hand. The comment in the file which says DO NOT EDIT THIS FILE BY HAND
does not apply to /etc/resolvconf/resolv.conf.d/head
itself but to /etc/resolv.conf
, to which the former is prepended.
Having said that, however, under normal circumstances you should not have to edit /etc/resolvconf/resolv.conf.d/head
.
The files /etc/resolvconf/resolv.conf.d/head
and /etc/resolvconf/resolv.conf.d/tail
are provided as a way of forcing a head and tail onto the generated resolv.conf
should that be needed under exceptional circumstances, but if you are using resolvconf properly and under normal circumstances then you do not have to do this.
You say that the file content is
nameserver 127.0.0.1
nameserver 10.255.0.101
nameserver 10.255.0.11
The presence of the line nameserver 127.0.0.1
suggests that you are running a local forwarding nameserver such as dnsmasq. The file above is not what resolvconf normally generates under these circumstances. It normally generates a file like the following.
# 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
nameserver 127.0.0.1
search foo.com
My guess is that on your system /etc/resolv.conf
is not a symbolic link to ../run/resolvconf/resolv.conf
but is a plain file which may or may not be generated by something other than resolvconf. If the file is completely static then simply edit it so that it looks the way you want it to look. If the file is generated by some tool other than resolvconf then figure out what tool is generating the file and configure that tool.
Alternatively, restore the symbolic link /etc/resolv.conf -> ../run/resolvconf/resolv.conf
and configure resolvconf properly.
How do I remove localhost nameserver from resolv.conf?
The following instructions apply only to the case where you are using resolvconf to manage /etc/resolv.conf
, i.e., /etc/resolv.conf
is a symbolic link to ../run/resolvconf/resolv.conf
.
If the line nameserver 127.0.0.1
is in one of the files in /etc/resolvconf/resolv.conf.d/
then remove it from there.
Otherwise that line is coming from some locally running nameserver. Either de-install that nameserver or configure that nameserver not to register the address 127.0.0.1 with resolvconf. In particular, if you are running BIND 9 named locally, either remove it or set RESOLVCONF=no
in /etc/default/bind9
.
Ref: https://bugs.launchpad.net/debian/+source/bind9/+bug/933723
Best Answer
It replaces the nameserver (DNS) used on your machine by the Google Public DNS service. If running that command helps you out, you're having DNS issues in the default settings provided by your network probably (DHCP). While it would be better to resolve the root cause of the issue, this is a general answer to your question.
Explanation of the command
sudo
elevates privileges to be root in this case.echo
just outputs the arguments following to the standard output (in this case it outputsnameserver 8.8.8.8
)>
redirects standard output to a file (overwrites it) in a regular Unix shell./etc/resolv.conf
is the file where the output is written to.nameserver 8.8.8.8
in/etc/resolv.conf
makes the system using the nameserver having IP address8.8.8.8
for resolving domain names to IP addresses. (very short version of what actually happens)8.8.8.8
is one of the addresses published by Google as to where their public DNS services are listening on.sudo
mistakeWhile this explanation sounds plausible, this won't work, because of an error you'll get:
Why? The output redirection is handled by your shell (here: Bash) and is not taken into account for the command used for
sudo
. Similar to how multiplying in maths has precedence over adding. So, it's justecho
that has got elevated privileges, but your shell hasn't! To solve this, one should run this command likeor, by using a pipe and
tee
to output it to a file:Ubuntu and Network Manager
On Ubuntu this is only a temporary change, as Network Manager "manages" the
/etc/resolv.conf
file. Local modifications will be overwritten. That's why you should configure this in Network Manager to have it persistent.Configuration using Network Manager
I would recommend configuring your PC properly using Network Manager. I'm assuming you're using DHCP on your network here (most common). Then do this to perform the same as equivalent to the command you were using:
Open Edit connections:
Edit the connection profile you're using.
On the IPv4 Settings tab:
Method: Automatic (DHCP) addresses only
This setting makes it doing a regular DHCP request for IP address configuration of your host, but it will ignore other non-mandatory options like DNS servers suggested.
8.8.8.8
Done.
Important notes
In a local or corporate network the local DNS server might be used for local hosts. You'll loose this functionality by directly asking Google's servers to resolve names for you. So, if for example the local DNS server would know what "printer" is, then you'll loose using your printer by that name.
So, please, fix your local DNS server instead. If it's just a simple forwarder to a broken DNS server of your ISP and you can't change that (ISP-managed all-in-one-router for example), then this
8.8.8.8
solution might be your only option.