域名服务dns的主要功能为(在Ubuntu)

浏览器之DNS解析过程详解在Linux上设置自定义DNS服务器可以提高性能和安全性,甚至可以通过DNS阻止一些使用地理屏蔽的网站。有几种方法可以做到这一点,包括在许多Linux发行版中包括的Network ManagerGUI,如Debian、Ubuntu和衍生物,以及现在作为标准包含在Ubuntu 20.04中的Netplan;或者使用resolv.conf(不是直接,而是通过head文件)。/etc/resolv.conf是DNS名称解析库的主要配置文件,解析器是C库中的一组函数,提供对Internet域名系统(DNS)的访问,它的功能是检查/etc/hosts文件中的条目,或多个DNS名称服务器,或使用主机的网络信息服务(NIS)数据库。在使用systemd(系统和服务管理器)的现代Linux系统上,DNS或名称解析服务通过systemd-resolved服务提供给本地应用程序,默认情况下,该服务有四种不同的方式来处理域名解析,默认模式下使用systemd DNS stub文件(/run/systemd/resolve/stub-resolv.conf)。如果你运行ls命令查看/etc/resolv.conf,你可以看到是一个符号链接指向/run/systemd/resolve/stub-resolv.conf$ ls -l /etc/resolv.conf
lrwxrwxrwx 1 root root 29 Feb 15 2018 /etc/resolv.conf -> ../run/systemd/resolve/stub-resolv.conf因为/etc/resolv.conf是由systemd-resolved服务间接管理的.在某些情况下,是通过network service(通过使用initscripts或NetworkManager),用户手动做的任何更改都不能永久保存或只持续一段时间。在本文中,我们将展示如何安装和使用resolvconf程序在/etc/resolv.conf文件中设置永久DNS域名服务器.resolv.conf文件在每次引导时都会被覆盖,所以我们不能直接编辑这个文件,但是我们可以通过编辑head和base文件来创建resolv.conf。我们编辑head文件,以便每次启动resolv.conf在顶部用我们自定义的DNS server。为什么要编辑/etc/resolv.conf文件?主要原因可能是系统DNS设置配置错误,或者您喜欢使用特定名称的服务器或您自己的服务器,下面的cat命令显示了我的Ubuntu系统的/etc/resolv.conf文件中的默认名称服务器。$ cat /etc/resolv.conf

nameserver 127.0.0.53在这种情况下,我们访问域名就会出现解析失败。因此,当用户试图手动设置DNS服务器时,更改不会持续很长时间,或者在重新启动后会撤销。要解决这个问题,您可以安装并使用reolvconf实用程序使更改永久性。nameserver 8.8.4.4
nameserver 8.8.8.8在Ubuntu和Debian中安装resolvconf软件包取决于你使用的是哪个版本的Ubuntu/Debian, resolvconf可能安装也可能没有安装,所以在继续之前让我们检查一下sudo systemctl status resolvconf.service如果您得到以下消息"Unit: resolvconf.service could not be found"(服务未找到),那么你就需要安装resolvconf如果您得到以下消息 “Active: active (exited)” ,那么说明 resolvconf已经安装,则可以跳过后面的安装步骤。然后通过运行以下命令更新系统软件包,然后从官方存储库安装resolvconf。sudo apt update
sudo apt install resolvconf一旦resolvconf安装完成,systemd将触发resolvconf。服务将自动启动和启用。要检查它是否启动并运行,请执行以下命令sudo systemctl status resolvconf.service如果由于未知原因导致服务未自动启动和启用,您可以通过如下方式启动和启用服务sudo systemctl start resolvconf.service
sudo systemctl enable resolvconf.service
sudo systemctl status resolvconf.service在最后一条命令之后,您应该看到“Active: Active (exited)”消息。在Ubuntu和Debian中设置永久DNS服务器接下来我们打开/etc/resolvconf/resolv.conf.d/head配置文件sudo nano /etc/resolvconf/resolv.conf.d/head然后添加下面两行(我使用谷歌的DNS服务器)nameserver 8.8.8.8
nameserver 8.8.4.4然后Ctrl+o 保存, Ctrl+x退出,重新启动resolvconf服务或重启系统.$ sudo systemctl start resolvconf.service我们需要更新resolv.conf以使用新的名称服务器。输入以下代码sudo resolvconf –enable-updates
sudo resolvconf -u现在,当我们查看/etc/resolv.conf文件时,nameserver条目就被写入了。nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 127.0.0.53免费DNS提供商在更改DNS服务器之前,您需要找到第三方DNS提供商,有很多好的(和免费的)服务可用。我推荐谷歌DNS,这是我使用的,从来没有出现过问题。我将在这里列出最流行的DNS提供商GOOGLEPrimary IPv4: 8.8.8.8Secondary IPv4: 8.8.4.4Preferred IPv6: 2001:4860:4860::8888Alternate IPv6: 2001:4860:4860::8844OPENDNSPrimary: 208.67.222.222Secondary: 208.67.220.220Preferred IPv6: 2620:0:ccc::2Alternate IPv6: 2620:0:ccd::2DNS.WATCHPrimary: 84.200.69.80Secondary: 84.200.70.40LEVEL3Primary: 209.244.0.3Secondary: 209.244.0.4NORTONPrimary: 199.85.126.10Secondary: 199.85.127.10COMMODOPrimary: 8.26.56.26Secondary: 8.20.247.20VERISIGNPrimary: 64.6.64.6Secondary: 64.6.65.6MORE SERVERS…See:Free and Public DNS Server List (Valid July 2021) See:Public DNS Server List

本文出自快速备案,转载时请注明出处及相应链接。

本文永久链接: https://www.175ku.com/27578.html