如何修复升级到 Ubuntu 13.10 后不起作用的 DNS 解析(Saucy)

Wit*_*tek 76 network-manager

升级到 13.10 后,我的 DNS 解析失败。似乎没有使用我通过 DHCP (LAN) 获得的 DNS 服务器。

我可以通过添加nameserver 8.8.8.8到临时解决问题/etc/resolv.conf. 但是后来内网主机还是无法解析。

单击连接信息时网络指示器菜单项时,主 DNS 和辅助 DNS 设置正确。但是我的电脑接缝不能使用它们。

所以我的问题:

  • resolv.conf如果有的话,我应该放入什么?
  • 如何找出我的计算机正在查询哪些名称服务器?
  • 接下来去哪里看看,为什么不使用 DHCP 接收的名称服务器?

jdt*_*ood 87

首先,您需要了解自 Ubuntu 12.04 以来名称解析在 Ubuntu 中的工作原理。

Stéphane Graber blogged some information about it last year here. The most important thing to know is that both Ubuntu Server and Ubuntu Desktop use resolvconf to manage the resolv.conf file. That means that you should no longer edit /etc/resolv.conf directly; instead you should configure your network interface configuration utility to provide the right information to resolvconf. For Ubuntu Server the network interface configuration utility is ifup and it is configured by the file /etc/network/interfaces. For Ubuntu Desktop the network interface configuration utility is NetworkManager. This is what you are using.

NetworkManager is configured by means of Network indicator > Edit Connections. However, for network interfaces configured by DHCP it normally isn't necessary to change any settings manually. Normally what happens is that the (remote) DHCP server provides to NetworkManager both an IP address for the local interface and the address of a (remote) DNS nameserver to use. NetworkManager starts an instance of a forwarding nameserver that listens locally at 127.0.1.1. This address, 127.0.1.1, is sent to resolvconf which puts nameserver 127.0.1.1 in /etc/resolv.conf. NetworkManager also gives the (remote) IP address of the DHCP-provided DNS nameserver to the forwarding nameserver. Thus a program running on the local system asks the resolver to translate a host name into an IP address; the resolver queries the local forwarding nameserver at 127.0.1.1; the forwarding nameserver queries the remote nameserver(s) it has been told about, receives an answer and sends it back up the chain.

NetworkManager communicates with the forwarding nameserver process over D-Bus. You can see what NetworkManager told the forwarding nameserver by running the command

nmcli dev list iface eth0 | grep IP4.DNS
Run Code Online (Sandbox Code Playgroud)

Update arising from the comments:
Note that resolvconf actually writes the file /run/resolvconf/resolv.conf to which /etc/resolv.conf is supposed to be a symbolic link. If /etc/resolv.conf is not a symbolic link then you need to recreate it. To do so you can run

sudo dpkg-reconfigure resolvconf
Run Code Online (Sandbox Code Playgroud)

or

sudo ln -sf /run/resolvconf/resolv.conf /etc/resolv.conf        
Run Code Online (Sandbox Code Playgroud)

  • Resolvconf 实际上写入文件 /run/resolvconf/resolv.conf 并且 /etc/resolv.conf 应该是 /run/resolvconf/resolv.conf 的符号链接。如果您删除了 /etc/resolv.conf,那么您删除了符号链接。要重新创建符号链接,您可以运行 `sudo dpkg-reconfigure resolvconf` 或者您可以执行 `mv /etc/resolv.conf /run/resolvconf/resolv.conf && ln -s ../run/resolvconf/resolv.conf / etc/resolv.conf` (15认同)
  • 除了“修复”之外,这一切都有。我该如何解决这个问题? (10认同)
  • 解决方法可能是按照答案的最后一部分中的建议运行“sudo dpkg-reconfigure resolvconf”。 (6认同)
  • 谢谢你!!!我不确定我的系统发生了什么,但运行“sudo dpkg-reconfigure resolveconf”似乎效果很好! (2认同)

小智 52

我做了以下链接中建议的更改(禁用 dnsmasq)。现在一切正常! http://www.ubuntugeek.com/how-to-disable-dnsmasq-in-ubuntu-12-04precise.html

打开/etc/NetworkManager/NetworkManager.conf文件。

sudo gedit /etc/NetworkManager/NetworkManager.conf
Run Code Online (Sandbox Code Playgroud)

注释掉一行:

#dnsmasq deactivated
#dns=dnsmasq
Run Code Online (Sandbox Code Playgroud)

  • 注释掉dnsmasq后,需要重启网络管理器:`sudo restart network-manager`。 (7认同)
  • 在我的情况下(Xubuntu),命令是:`sudo /etc/init.d/network-manager restart` (2认同)
  • 如果你遇到这种情况,即使没有安装 dnsmasq,也没有什么可以注释掉的,请将 ``dns=default``` 添加到``[main]```` 部分。NetworkManager 有自己令人讨厌的 dnsmasq 插件,否则它将使用它。 (2认同)
  • 我需要重新启动 `network-manager` - `sudo service network-manager restart` (2认同)

小智 21

编辑 2:上一篇文章被审核理所当然地删除了,我正在发布我发现的解决方案。对不起。

编辑:我刚刚找到答案,它就在这个页面上 - 对不起我的 miopy。我在下面发布了我的发现,扩展了 Richard Lindstedt 在本页中找到的正确答案。我把我早期的隆隆声留给了一些背景。请支持理查德的回答,他应得的。

其实真的很简单。

只需打开您的接口配置文件 --> sudo vi /etc/network/interfaces

那肯定没有帮助OP,现在也没有帮助我。我们不想要静态地址,我们想要使用 DHCP 服务器发送给我们的地址。NetworkManager 似乎认出了它们,但 Ubuntu 直截了当地忽略了它们:

# nmcli dev list iface wlan0 | grep IP4.DNS
IP4.DNS[1]:          10.*.*.*
IP4.DNS[2]:          10.*.*.*
IP4.DNS[3]:          8.8.8.8
Run Code Online (Sandbox Code Playgroud)

但...

# dig microsoft.com
; <<>> DiG 9.9.5-4.3-Ubuntu <<>> microsoft.com
;; global options: cmd
;; connection timed out; no servers could be reached
Run Code Online (Sandbox Code Playgroud)

我的 /etc/network/interfaces 是:

auto lo
iface lo inet loopback
Run Code Online (Sandbox Code Playgroud)

这有点奇怪,我希望所有接口都在这里声明(或者我错过了什么?)。

所以,简而言之:

  • 我没有弄乱任何文件开始
  • 我已经跑了 dpkg-reconfigure resolvconf
  • 正确的符号链接已就位
  • NetworkManager 从 DHCP 检索正确的 DNS 服务器
  • Ubuntu 不使用这样的地址
  • 解决方法是将固定的 8.8.8.8 放在我不想要的 /etc/network/interfaces 上
  • 我想在任何情况下都使用 DHCP 提供的 DNS 服务器。

没有打开另一个线程,因为这是确切的问题,除了我现在在 14.10 上(但是自从从 12.10 升级到 13.04 以来,这一直困扰着我)。

解决方案

最后一句话让我走上了正轨,直到那时我才注意到理查德的回答。

这个问题似乎涉及到冲突dnsmasqresolvconf包。直到 12.10,dnsmasq才使用。从 13.04 开始,Ubuntu 似乎切换到了 dnsmasq/resolvconf 混合体,您已经安装了软件包dnsmasq-baseresolvconf,但没有安装dnsmasq它本身。

我不能说它是 13.04 升级脚本中的错误还是其他什么,因为当升级(如在全新安装中)resolvconf 被安装时,dnsmasq-base 被升级并且 dnsmasq 被(正确)卸载。

美中不足的是,升级脚本无法注释掉dns=dnsmasq的行/etc/NetworkManager/NetworkManager.conf。因此,即使系统上不再存在 dnsmasq 守护进程,/etc/resolv.conf 仍然希望它存在。

  • 未来的 Google 员工应该注意,您必须“sudo service network-manager restart”才能使其生效。 (5认同)

小智 8

其实真的很简单。

只需打开您的接口配置文件 --> sudo vi /etc/network/interfaces

在您的界面(可能是 eth0)下,您将看到所有常用配置。

address 192.168.22.71
netmask 255.255.255.0
gateway 192.168.22.1
Run Code Online (Sandbox Code Playgroud)

在网关之后,只需添加“dns-nameservers 8.8.8.8 8.8.8.9”或您要使用的任何名称服务器。

所以你的配置应该是:

address 192.168.22.71
netmask 255.255.255.0
gateway 192.168.22.1
dns-nameservers 8.8.8.8 8.8.8.9
Run Code Online (Sandbox Code Playgroud)

然后只需执行“ sudo 服务网络重新启动”,您就可以开始了!