回顾:

回顾:

我知道有几篇关于这个问题的帖子,我也全部看完了,但还是不明白如何解决它。

问题 我已连接到网络,但未连接到互联网。如果你执行 ping,你会看到以下信息

ping: www.google.com: Name or service not known

尝试这个答案并且不起作用:Ubuntu 14.04 中的 DNS_PROBE_FINISHED_BAD_CONFIG 错误

/etc/resolvconf/update.d/libc: Warning: /etc/resolv.conf is not a symbolic link to /run/resolvconf/resolv.conf`
sudo rm /etc/resolv.conf
sudo ln -s ../run/resolvconf/resolv.conf /etc/resolv.conf
sudo resolvconf -u

尝试使用 sudo dpkg-reconfigure resolvconf并收到此错误

resolvconf-pull-resolved.service is a disabled or a static unit, not starting it.
resolvconf-pull-resolved.service is a disabled or a static unit, not starting it.

我发现的唯一可能的解决方案就是这个,但我认为这是一个临时的答案:https://askubuntu.com/a/46036/83345

必须编辑 /etc/resolv.conf 并手动添加 DNS

sudo nano /etc/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
# 127.0.0.53 is the systemd-resolved stub resolver.
# run "systemd-resolve --status" to see details about the actual nameservers.

nameserver 208.67.222.222
nameserver 208.67.220.220
nameserver 8.8.8.8

所以问题是,我如何永久添加这些 DNS,如果我重新启动,这些更改就会丢失?

/etc/netplan/*.yaml 的内容

# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager
#I add these manually, base in one of the answers but
#getting this error
#sudo netplan apply --debug -Error in network definition: unknown key #'nameservers'nameservers:

nameservers:
  [8.8.8.8, 208.67.222.222,208.67.220.220]

/etc/网络/接口

# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback

/etc/resolv.conf

# Generated by Connection Manager
nameserver ::1
nameserver 127.0.0.1

答案1

如果你有 Ubuntu >= 18.04,那么,是的,它们最终会丢失,因为它们会被覆盖。Jack Wallen 在他的文章,以及您应该如何配置您的 DNS。

如果你的 Ubuntu 版本低于 18.04,那么你可以使用以下命令手动编辑其他一些设置/etc/network/interfaces

回顾:

18.04

基本上,首先要修改现在位于以下位置的网络配置文件:/etc/netplan/<<01-99>>-netcfg.yaml。您需要对.yaml文件进行适当的编辑,如下所示:

...
nameservers:
    [8.8.8.8, 8.8.4.4]
...

然后输入:sudo netplan apply或者sudo netplan apply --debug如果出现问题。

< 18.04

编辑:/etc/network/interfaces像这样:

...
dns-addresses 8.8.4.4,8.8.8.8
...

相关内容