Linux 主机:解析 /etc/resolv.conf 失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10750156/
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-06 06:30:23  来源:igfitidea点击:

host: parse of /etc/resolv.conf failed

linuxparsingdnshostnameservers

提问by Xavi Montero

I'm getting an error and I cannot see what happens, please see if you can catch what's wrong.

我收到一个错误,我看不到会发生什么,请看看您是否能找出问题所在。

Whenever I use the "host" command, I get this error:

每当我使用“host”命令时,我都会收到此错误:

xavi@cobalto:~$ host www.guparty.com
host: parse of /etc/resolv.conf failed

I think the syntax is correct:

我认为语法是正确的:

xavi@cobalto:~$ cat /etc/resolv.conf
search dsitelecom.com
nameserver 8.8.8.8 8.8.4.4

Also permissions are readable for everybody:

每个人都可以读取权限:

xavi@cobalto:~$ ls -l /etc/resolv.conf
-rw-r--r-- 1 root root 49 2011-10-30 12:02 /etc/resolv.conf

Probably it is a silly thing but I cannot get it. Do you see anything wrong there?

可能这是一件愚蠢的事情,但我无法理解。你看那里有什么问题吗?

Thanks!

谢谢!

采纳答案by guido

Check your syntax, you need to define one nameserver per line in /etc/resolv.conf

检查你的语法,你需要在每行定义一个名称服务器 /etc/resolv.conf

search dsitelecom.com
nameserver 8.8.8.8 
nameserver 8.8.4.4

回答by Pekka Takala

I had similar problem, but did this and got working:

我有类似的问题,但这样做并开始工作:

# mv resolv.conf resolv.conf.old
# cat resolv.conf.old
search example.com
domain example.com
nameserver 11.22.33.44
nameserver 2000::1
# echo "search example.com" >>resolv.conf
# echo "domain example.com" >>resolv.conf
# echo "nameserver 11.22.33.44" >>resolv.conf
# echo "nameserver 2000::1" >>resolv.conf

The addresses are just example, but the result is working. Why copy resolv.conf is that you get a copy of original. Then when you print it out, you dont have to remember everything inside resolv.conf. And when you make the file with echos, you can be sure that there is no extra chars those make troubles. So echo all nameserver lines to there.

地址只是示例,但结果有效。为什么要复制resolv.conf 是因为你得到一份原件。然后当你打印出来的时候,你就不用记住resolv.conf里面的所有内容了。当您使用回声制作文件时,您可以确保没有额外的字符会造成麻烦。所以将所有名称服务器行回显到那里。

回答by Putnik

I saw the same error when by mistake *nix EOLs ("\n") were replaced with windows ones ("\r\n"). Solution: dos2unix filename

当错误地将 *nix EOL(“\n”)替换为 Windows 的(“\r\n”)时,我看到了同样的错误。解决方案:dos2unix filename