Ubuntu 20.04设置DNS解析(解决resolve.conf被覆盖问题)

您所在的位置:网站首页 重置dns设置 Ubuntu 20.04设置DNS解析(解决resolve.conf被覆盖问题)

Ubuntu 20.04设置DNS解析(解决resolve.conf被覆盖问题)

2024-06-30 18:39:26| 来源: 网络整理| 查看: 265

众所周知:

        Ubuntu在域名解析时,最直接使用的是/etc/resolve.conf文件,它是/run/systemd/resolve/

resolve.conf的软链接,而对于刚装完的ubuntu系统,该文件的内容如下:

# This file is managed by man:systemd-resolved(8). Do not edit. # # This is a dynamic resolv.conf file for connecting local clients to the # internal DNS stub resolver of systemd-resolved. This file lists all # configured search domains. # # Run "resolvectl status" to see details about the uplink DNS servers # currently in use. # # Third party programs must not access this file directly, but only through the # symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way, # replace this symlink by a static file or a different symlink. # # See man:systemd-resolved.service(8) for details about the supported modes of # operation for /etc/resolv.conf. nameserver 127.0.0.53 options edns0 trust-ad

问题分析:

        很显然,我们需要做的就是在/etc/resolve.conf中,配置我们需要的域名解析服务器地址,例如:“nameserver 8.8.8.8”,但是这个文件即使我们修改了,很快又会被覆盖,而且我们注意一个细节——文件的开头就注明了“Do not edit”,到了这里,我们就应该反应过来,直接修改/etc/resolve.conf是不正确的。

解决方案:

        第1步, 修改/etc/systemd/resolved.conf,例如:

# This file is part of systemd. # # systemd is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # # Entries in this file show the compile time defaults. # You can change settings by editing this file. # Defaults can be restored by simply deleting this file. # # See resolved.conf(5) for details [Resolve] DNS=8.8.8.8 114.114.114.114 #FallbackDNS= #Domains= #LLMNR=no #MulticastDNS=no #DNSSEC=no #DNSOverTLS=no #Cache=no-negative #DNSStubListener=yes #ReadEtcHosts=yes

       个人猜测,这个时候,系统在往/run/systemd/resolve/resolv.conf里面写域名解析服务器地址的时候,会从/etc/systemd/resolved.conf中取得DNS相关的配置。

        2,重启域名解析服务

                systemctl restart systemd-resolved                 systemctl enable systemd-resolved

        3,备份当前的/etc/resolve.conf,并重新设置/run/systemd/resolve/resolv.conf  到/etc/resolve.conf的软链接

                mv    /etc/resolv.conf    /etc/resolv.conf.bak                 ln  -s   /run/systemd/resolve/resolv.conf    /etc/

验证成果:

# This file is managed by man:systemd-resolved(8). Do not edit. # # This is a dynamic resolv.conf file for connecting local clients directly to # all known uplink DNS servers. This file lists all configured search domains. # # Third party programs must not access this file directly, but only through the # symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way, # replace this symlink by a static file or a different symlink. # # See man:systemd-resolved.service(8) for details about the supported modes of # operation for /etc/resolv.conf. nameserver 8.8.8.8 nameserver 114.114.114.114

感谢各个论坛大佬的分享,主要参考:

        https://www.cnblogs.com/mouseleo/p/14976527.html



【本文地址】

公司简介

联系我们

今日新闻


点击排行

实验室常用的仪器、试剂和
说到实验室常用到的东西,主要就分为仪器、试剂和耗
不用再找了,全球10大实验
01、赛默飞世尔科技(热电)Thermo Fisher Scientif
三代水柜的量产巅峰T-72坦
作者:寞寒最近,西边闹腾挺大,本来小寞以为忙完这
通风柜跟实验室通风系统有
说到通风柜跟实验室通风,不少人都纠结二者到底是不
集消毒杀菌、烘干收纳为一
厨房是家里细菌较多的地方,潮湿的环境、没有完全密
实验室设备之全钢实验台如
全钢实验台是实验室家具中较为重要的家具之一,很多

推荐新闻


图片新闻

实验室药品柜的特性有哪些
实验室药品柜是实验室家具的重要组成部分之一,主要
小学科学实验中有哪些教学
计算机 计算器 一般 打孔器 打气筒 仪器车 显微镜
实验室各种仪器原理动图讲
1.紫外分光光谱UV分析原理:吸收紫外光能量,引起分
高中化学常见仪器及实验装
1、可加热仪器:2、计量仪器:(1)仪器A的名称:量
微生物操作主要设备和器具
今天盘点一下微生物操作主要设备和器具,别嫌我啰嗦
浅谈通风柜使用基本常识
 众所周知,通风柜功能中最主要的就是排气功能。在

专题文章

    CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭