【问题标题】:Linux shell temporary DNSLinux shell 临时 DNS
【发布时间】:2017-06-05 07:52:55
【问题描述】:

在 linux shell 脚本中,我想临时更改 dns 地址。 为此,我可以在 shell 运行后立即将临时 dns 地址插入到 resolv.conf 中,并在脚本结束之前将其删除。就是这样。

但问题是,所有其他脚本在脚本运行时也会命中该地址。 这不是我所期望的。 难道没有另一种方法可以在shell中临时更改dns而不影响其他人吗?

【问题讨论】:

标签: linux shell dynamic dns


【解决方案1】:

Unshare 可以帮助您。 Unshare 帮助运行带有一些与父级未共享的命名空间的程序。使用 unshare,您可以将自定义 resolv.conf 限制在脚本会话中,并且不会影响其他系统用户和查询。

  sudo unshare --mount bash -s <<'EOF'  
  mount --bind custom_resolv.conf /etc/resolv.conf   
  sudo -u username run_command
  EOF

【讨论】:

    猜你喜欢
    • 2011-11-16
    • 2022-01-19
    • 2014-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-07
    • 2012-06-16
    • 2014-04-20
    相关资源
    最近更新 更多