Re: Neat trick to bypass /etc/resolv.conf and use your own resolv.conf for dnscache

Manvendra Bhangui <[email protected]> Thu, 11 May 2017 09:14:06 +0530
Newsgroups gmane.mail.qmail.general
Message-ID <CAOqj+1OYDpCD0OqGutSGmpiU+1p_4d05gwfUynn-OUuMhMs=yA@mail.gmail.com>
On 11 May 2017 at 03:22, Charles Cazabon
<[email protected]> wrote:
> Manvendra Bhangui <[email protected]> wrote:
>> I had a situation where I am running dnscache [...] However my resolv.conf
>> would get updated by NetworkManager or by vpn client.
> [...]
>> Here is a neat solution using unshare [...]
>
> Looks like overkill.  Why not just make resolv.conf immutable?  i.e. chattr +i
> It's always worked for me.
>

That does not work for me. The unshare command lets you have your own
private copy of your own libraries, /etc/passwd, /etc/group, your
binaries from a mounted loopback filesystem, rapid deployment for
testing a private build without modifying existing copies of running
binaries, almost like a docker image. You can have your own private
mount namespace, custom UTS namespace (hostname, domainname), IPC
namespace (message queues, IPC, semaphores) and network namespace
(independent IPV5, IPV6 stacks, ip routing tables, firewall rules),
map uids to superuser. Complicated - maybe yes, cool - definitely yes.

$ ls -l /etc/resolv.conf /var/run/NetworkManager/resolv.conf
lrwxrwxrwx. 1 root root 35 May 11 08:37 /etc/resolv.conf ->
/var/run/NetworkManager/resolv.conf
-rw-r--r--. 1 root root 97 May 11 08:37 /var/run/NetworkManager/resolv.conf

$ chattr +i /var/run/NetworkManager/resolv.conf
chattr: Inappropriate ioctl for device while reading flags on
/var/run/NetworkManager/resolv.conf

$ sudo !!
sudo chattr +i /var/run/NetworkManager/resolv.conf
chattr: Inappropriate ioctl for device while reading flags on
/var/run/NetworkManager/resolv.conf

$ cat /etc/resolv.conf
# Generated by NetworkManager
search tagrem.in indimail.in
nameserver 8.8.8.8
nameserver 8.8.4.4
$