NetworkManager 未更新 /var/run/networkmanager/resolv.conf

NetworkManager 未更新 /var/run/networkmanager/resolv.conf

我的 NetworkManager 没有写入/var/run/networkmanager/resolv.confNetworkManager 未填充 resolv.conf不是我的情况的答案,因为我不使用resolvconf。更多详细信息如下:

我将以太网的管理从/etc/network/interfacesNetworkManager 切换到了其他管理工具,但它却从不写入/var/run/networkmanager/resolv.conf

$ nmcli d  
DEVICE  TYPE      STATE      CONNECTION  
eth0    ethernet  connected  Wired connection 1
lo      loopback  unmanaged  --          

$ ls /var/run/NetworkManager/resolv.conf
ls: cannot access '/var/run/NetworkManager/resolv.conf': No such file or directory

$ ls /var/run/nm-dns-dnsmasq.conf
ls: cannot access '/var/run/nm-dns-dnsmasq.conf': No such file or directory

当我使用时,这从未困扰过我/etc/network/interfaces,但现在我正在使用 NetworkManager,我需要它来更新我的resolv.conf

这是我的NetworkManager.conf

cat /etc/NetworkManager/NetworkManager.conf
[main]
plugins=ifupdown,keyfile
dns=dnsmasq

[ifupdown]
managed=false

[device]
wifi.scan-rand-mac-address=no

有些答案说我应该dns=dnsmasq在那里,但有些答案说我不应该。总而言之,我仍然不清楚如何让 NetworkManager 更新/var/run/networkmanager/resolv.conf

更新,更多信息:

$ resolvectl status | grep DNS
-su: resolvectl: command not found

$ dpkg -l '*dns*' | grep 'ii *dns'
ii  dns-root-data  2018013001   all          DNS root data including root zone
ii  dnsmasq        2.79-1       all          Small caching DNS proxy and DHCP/
ii  dnsmasq-base   2.79-1       amd64        Small caching DNS proxy and DHCP/
ii  dnsutils       1:9.11.3+dfs amd64        Clients provided with BIND

$ dpkg -l '*resolv*' | grep ii || echo no resolvconf
no resolvconf

$ ls -al /etc/resolv.conf
-rw-r--r-- 1 root root 79 2019-03-03 18:42 /etc/resolv.conf

$ host 8.8.8.8 
8.8.8.8.in-addr.arpa domain name pointer google-public-dns-a.google.com.

$ host www.ebay.com
www.ebay.com is an alias for slot9428.ebay.com.edgekey.net.
slot9428.ebay.com.edgekey.net is an alias for e9428.b.akamaiedge.net.
e9428.b.akamaiedge.net has address 104.93.181.25

$ lsb_release -a 
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.1 LTS
Release:        18.04
Codename:       bionic

更新2。

  • 这不是原始的 Ubuntu 安装,而是我从新定制的安装(不是从以前版本升级)。我删除了resolvconf自己,因为我正在使用/etc/network/interfaces,并且不希望我的/etc/resolv.conf一直在变化。也许这就是罪魁祸首,没有它 NetworkManager 就无法工作resolvconf
  • 我的全部意图是“用 dnsmasq 替换 systemd-resolved“(我使用 18.04 LiveCD 进行练习,它有resolvconf),并将其用于我的 LAN DNS 服务器。嗯,也许在那种情况下我不需要 NetworkManager 一直更改我的/etc/resolv.conf

无论如何,以下是需要进一步调查的信息:

$ dpkg -l '*resolv*'
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name           Version      Architecture Description
+++-==============-============-============-=================================
un  resolvconf     <none>       <none>       (no description available)

$ cat /run/resolvconf/resolv.conf
cat: /run/resolvconf/resolv.conf: No such file or directory

$ cat /run/systemd/resolve/resolv.conf
# This file is managed by man:systemd-resolved(8). Do not edit.
. . . 
nameserver 64.71.255.204
nameserver 64.71.255.198
search hitronhub.home

$ cat /etc/netplan/*.yaml
# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager
  ethernets:
    eth0:
      addresses: [192.168.0.11/24, 192.168.0.10/24]
      gateway4: 192.168.0.1

$ ps auxc | grep resolv
systemd+ 23890  0.0  0.0  70608  1520 ?        Ss   Mar01   0:00 systemd-resolve

$ sudo lsof -i tcp:53
COMMAND     PID            USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
systemd-r 23890 systemd-resolve   13u  IPv4 47127798      0t0  TCP 127.0.0.53:domain (LISTEN)
dnsmasq   29822         dnsmasq    5u  IPv4 47935969      0t0  TCP 192.168.0.10:domain (LISTEN)
dnsmasq   29822         dnsmasq    7u  IPv4 47935971      0t0  TCP 192.168.0.11:domain (LISTEN)
dnsmasq   29822         dnsmasq    9u  IPv4 47935973      0t0  TCP localhost.myhost.org:domain (LISTEN)
dnsmasq   29822         dnsmasq   11u  IPv6 47935975      0t0  TCP [fe80::xxxx]:domain (LISTEN)
dnsmasq   29822         dnsmasq   13u  IPv6 47935977      0t0  TCP [2607:fea8:xxxx]:domain (LISTEN)
dnsmasq   29822         dnsmasq   15u  IPv6 47935979      0t0  TCP [fd00:xxxx]:domain (LISTEN)
dnsmasq   29822         dnsmasq   17u  IPv6 47935981      0t0  TCP ip6-localhost:domain (LISTEN)

答案1

难怪我说“这里不对劲“。 在你的 ”定制“,你把事情搞得一团糟,这完全是不必要的。别再试图破坏系统了。抱歉。”


/etc/netplan/*.yaml已将 NetworkManager 和 netplan 脚本组合在一起。您的 .yaml 文件应如下所示...

network:
  version: 2
  renderer: NetworkManager

此信息属于 NetworkManager GUI 连接配置文件,或者/etc/network/interfaces,用 NetworkManager 的话来说...而不是用 netplan 的话来说...

ethernets:
    eth0:
      addresses: [192.168.0.11/24, 192.168.0.10/24] (why two addresses?)
      gateway4: 192.168.0.1

  • 重新安装resolvconf
  • 重置/etc/resolv.conf符号链接
    • 请参阅下面的链接信息
    • 并且不要手动编辑此文件
  • 编辑/etc/systemd/resolved.conf(请参阅下面的说明)
  • 从中删除 dns=dnsmasq/etc/network/interfaces
  • 消除dnsmasq* 除非你能解释为什么你需要它

关于dnsmasqsystemd-resolved...

执行ps auxc | grep -i dnsps auxc | grep -i resolv并查找dnsmasqsystemd-resolved,如果两者都在运行,则需要systemd-resolved通过编辑/etc/systemd/resolved.conf和禁用的 DNS 部分......

改变:

#DNSStubListener=yes

到:

DNSStubListener=no

然后重新启动 systemd-resolve 和 dnsmasq,或者重新启动。

您可能需要重置 /etc/resolv.conf 的符号链接如果 dnsmasq 没有运行)...

sudo mv /etc/resolv.conf /etc/resolv.conf.OLD# 保存旧的符号链接

sudo ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf# 创建新的符号链接

笔记:原始符号链接是……

sudo ln -s /run/resolvconf/resolv.conf /etc/resolv.conf

相关内容