The dns-nameservers option will only have an effect when ifup is used. I am not sure what you mean by 'restarting networking'. The lo interface is normally only ifup'ped at boot time, but you can ifdown-ifup it by hand. (Or you can reboot.)
I just tested this on my machine. I edited /etc/network/interfaces and added a line "dns-nameservers 127.0.0.1" to the "iface lo" stanza.
auto lo
iface lo inet loopback dns-nameservers 127.0.0.1
Then in a terminal I became root
sudo su
and I ifdown-ifupped the "lo" interface
ifdown lo
ifup lo
with the result that /etc/resolv.conf contained 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
The lo stanza is the appropriate stanza to put it in. Under some circumstances you can also but the dns-nameservers option in the eth0 stanza, but note that if you have
[ifupdown]
managed=true
in /etc/NetworkManager/NetworkManager.conf then NetworkManager brings up eth0 but it ignores the "dns-nameservers" option. On the other hand if you have
managed=false
then eth0 should be ifupped at boot along with lo and the dns-nameservers option should work. But I repeat that for a local caching nameserver the "iface lo" stanza is the appropriate place to put a dns-nameservers option if you really want to have one.
I want to add that normally you don't have to put a "dns-nameservers 127.0.0.1" option anywhere. Every nameserver in Ubuntu that listens by default on 127.0.0.1 tells resolvconf to add the "nameserver 127.0.0.1" line to resolv.conf when the nameserver starts and tells resolvconf to remove that line when it stops. If that is not happening on your machine then we should find out why not and fix that. (Open a new bug report for that.)
The dns-nameservers option will only have an effect when ifup is used. I am not sure what you mean by 'restarting networking'. The lo interface is normally only ifup'ped at boot time, but you can ifdown-ifup it by hand. (Or you can reboot.)
I just tested this on my machine. I edited /etc/network/ interfaces and added a line "dns-nameservers 127.0.0.1" to the "iface lo" stanza.
auto lo
dns-nameserver s 127.0.0.1
iface lo inet loopback
Then in a terminal I became root
sudo su
and I ifdown-ifupped the "lo" interface
ifdown lo
ifup lo
with the result that /etc/resolv.conf contained 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
The lo stanza is the appropriate stanza to put it in. Under some circumstances you can also but the dns-nameservers option in the eth0 stanza, but note that if you have
[ifupdown]
managed=true
in /etc/NetworkMan ager/NetworkMan ager.conf then NetworkManager brings up eth0 but it ignores the "dns-nameservers" option. On the other hand if you have
managed=false
then eth0 should be ifupped at boot along with lo and the dns-nameservers option should work. But I repeat that for a local caching nameserver the "iface lo" stanza is the appropriate place to put a dns-nameservers option if you really want to have one.
I want to add that normally you don't have to put a "dns-nameservers 127.0.0.1" option anywhere. Every nameserver in Ubuntu that listens by default on 127.0.0.1 tells resolvconf to add the "nameserver 127.0.0.1" line to resolv.conf when the nameserver starts and tells resolvconf to remove that line when it stops. If that is not happening on your machine then we should find out why not and fix that. (Open a new bug report for that.)