有没有一种方法来指定每个用户resolv.conf ?
我发现的是对每个用户主机文件的可能性的模糊引用,但是我并不感兴趣,实际上我对整个resolv.conf感兴趣,因为我想设置不同的名称服务器。
如果您问为什么要在多用户环境下testingcjdns域名服务器,我不想影响系统的其他用户。
是否有可能滥用nsswitch系统?
简单的答案 – 没有….
但是,如果您要为每个用户设置不同的虚拟机,您可能有机会做你想做的事情。
似乎有点毫无意义。
本地文件系统命名空间是你的朋友,虽然他们需要root权限来设置。
sudo unshare --mount bash -s <<'EOF' mount --bind /path/to/your/resolv.conf /etc/resolv.conf sudo -u username-to-run-as command-to-run-with-alternate-resolv-conf EOF
如果你想要一个脚本,它将用更新后的resolv.conf运行一个任意的命令,请考虑:
#!/bin/bash ## usage: with-custom-resolver /path/to/resolv.conf cmd arg1 arg2 ... ## ...note that this requires root. script="" add_cmd() { local cmd_str printf -v cmd_str '%q ' "$@" script+="$cmd_str"$'\n' } resolv_conf=$1; shift [[ $EUID = 0 ]] || { echo "Must be run as root" >&2; exit 1; } [[ -e $resolv_conf ]] || { echo "No file found at: $resolv_conf" >&2; exit 1; } add_cmd mount --bind "$resolv_conf" /etc/resolv.conf add_cmd exec "$@" unshare --mount sh -e -c "$script"
因此,这可以用作:
with-custom-resolver your-resolv.conf sudo -u someuser some-command arg1
要testingDNS服务器,您不需要更改parsing器configuration。 您只需要更改host的DNS服务器, nslookup或dig命令。
host www.google.com 8.8.8.8
您还可以使用chroot环境或Linux容器(LXC)来拥有不同的resolv.conf文件。
我可能可以通过向NSS添加服务来解决这个问题。