I've set up several network namespaces on my Linux system (kernel version 3.10), and now I want to configure each network namespace to have its own DNS settings.
resolv.conf files in each
/etc/netns/[namespace] directory, and now I want to make my system work in the following way:
In bash command line, whenever I enter the context of a particular network namespace with
nsenter --net=/run/netns/[namespace name], I want all processes launched from command line (like nslookup, ping) to run with the DNS settings that I configured with the matching
If I run my commands like this:
"ip netns exec [namespace name] [command]"
then the DNS settings of the namespace apply.
However, when running the commands without "ip netns exec", the DNS settings are taken from
/etc/resolv.conf, even though running "netns get cur" indicates that the context is set to the desired network namespace.
I tried doing
mount --bind /etc/netns/[namespace name]/resolv.conf /etc/resolv.conf in the context of the appropriate network namespace, but this applies the mount in the entire system rather then only in the context of that network namespace.
I suspected that using mount namespaces may help, so I tried reading the man page of mount namespaces, however couldn't make anything out of it in the short time that I dedicated to it.
Is there an easy and elegant way to achieve this goal?
Any help/direction toward the solution will be greatly appreciated!