Linux:我如何编辑 resolv.conf

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19432026/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 01:06:57  来源:igfitidea点击:

Linux: How do i edit resolv.conf

linuxdns

提问by Ricky Wilson

I need to setup Open DNS but i cant edit resolv.conf

我需要设置 Open DNS 但我无法编辑 resolv.conf

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.1.1
search gateway.2wire.net

采纳答案by Chawarong Songserm PMP

Your system uses resolvconf, so the resolv.conf file is replaced by a symbolic link to /etc/resolvconf/run/resolv.confand resolvconf dynamically generated the file. That's why DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN

您的系统使用 resolvconf,因此 resolv.conf 文件被替换为指向/etc/resolvconf/run/resolv.conf并 resolvconf 动态生成文件的符号链接。这就是为什么DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN

To properly update the information in the file, you can put the dns-* parameters in /etc/network/interfacese.g.

要正确更新文件中的信息,您可以将 dns-* 参数放在/etc/network/interfaceseg

auto eth0
iface eth0 inet static
     address 33.33.13.10
     netmask 255.255.255.0
     gateway 33.33.13.1
     dns-nameservers 33.33.13.1 12.34.56.78
     dns-search example.com

Then, you can update the dns-* info by

然后,您可以通过以下方式更新 dns-* 信息

$ resolvconf -d eth0
$ resolvconf -a eth0

Or you can do ifdown & ifup and resolvconf -d, -a will happen behind the scenes.

或者你可以做 ifdown & ifup 和 resolvconf -d, -a 会在幕后发生。

Note: sometimes I find resolvconf -u doesn't work. I don't know why

注意:有时我发现 resolvconf -u 不起作用。我不知道为什么

You should read man resolvconf. There's more information about all this.

你应该阅读man resolvconf。还有更多关于这一切的信息。

TIP: if you want to update /etc/resolv.conf manually, you can remove the symlink and create /etc/resolv.conf by hand. This way, the file won't get updated from resolvconf ever.

提示:如果您想手动更新 /etc/resolv.conf,您可以删除符号链接并手动创建 /etc/resolv.conf。这样,文件将永远不会从 resolvconf 更新。

    $ rm /etc/resolv.conf         ;# to remove the symlink
    $ vi /etc/resolv.conf         ;# to create a regular file

回答by Cris Favero

This usually requires editing /etc/resolvconf/resolv.conf.d/base(depending on your distro this placement may vary slightly) or other files in this directory. They are added by the resolvconf process itself. The format of those files is the same as a standard resolv.conf.

这通常需要编辑/etc/resolvconf/resolv.conf.d/base(根据您的发行版,此位置可能略有不同)或此目录中的其他文件。它们是由 resolvconf 进程本身添加的。这些文件的格式与标准 resolv.conf 相同。

After you have made those edits then you can force resolvconf to update using the command resolvconf -u.

完成这些编辑后,您可以使用命令强制 resolvconf 进行更新resolvconf -u