【Ubuntu】DNS设置不生效/重启被重置

ops/2024/10/19 1:33:26/

/etc/resolv.conf 是一个链接,指向/run/systemd/resolve/stub-resolv.conf

ubuntu@VM-4-13-ubuntu:/run/systemd/resolve$ ll /etc/resolv.conf 
lrwxrwxrwx 1 root root 39 Sep 30 14:40 /etc/resolv.conf -> ../run/systemd/resolve/stub-resolv.conf

这两个(resolv.confstub-resolv.conf)文件时间每次重启后会重新生成,所以单纯修改/etc/resolv.conf 后续会被覆盖

ubuntu@VM-4-13-ubuntu:/run/systemd/resolve$ ll
total 8
drwxr-xr-x  2 systemd-resolve systemd-resolve 120 Sep 30 18:10 ./
drwxr-xr-x 23 root            root            580 Sep 30 18:11 ../
srw-rw-rw-  1 systemd-resolve systemd-resolve   0 Sep 30 18:10 io.systemd.Resolve=
srw-------  1 systemd-resolve systemd-resolve   0 Sep 30 18:10 io.systemd.Resolve.Monitor=
-rw-r--r--  1 systemd-resolve systemd-resolve 930 Sep 30 18:10 resolv.conf
-rw-r--r--  1 systemd-resolve systemd-resolve 920 Sep 30 18:10 stub-resolv.conf

resolvectl status用来查看当前DNS

ubuntu@VM-4-13-ubuntu:/opt$ sudo resolvectl status
GlobalProtocols: -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupportedresolv.conf mode: stubLink 2 (eth0)Current Scopes: DNSProtocols: +DefaultRoute -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
Current DNS Server: 183.60.83.19DNS Servers: 183.60.83.19 183.60.82.98Link 3 (docker0)Current Scopes: noneProtocols: -DefaultRoute -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupportedLink 10 (br-ef5110e42154)Current Scopes: noneProtocols: -DefaultRoute -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported

查询了一些资料说是修改sudo vi /etc/systemd/resolved.conf 这个文件

[Resolve]
DNS=8.8.8.8 114.114.114.114

我修改后重启,resolv.conf这个文件的内容是修改了的,但是的stub-resolv.conf的内容还是没有修改,但是/etc/resolv.conf 是指向stub-resolv.conf的,所以我改了一下链接的引用让他指向/run/systemd/resolve/resolv.conf

ubuntu@VM-4-13-ubuntu:/run/systemd/resolve$ sudo rm /etc/resolv.conf
ubuntu@VM-4-13-ubuntu:/run/systemd/resolve$ sudo ln -s /run/systemd/resolve/resolv.conf /etc/resolv.confubuntu@VM-4-13-ubuntu:/run/systemd/resolve$ ll /etc/resolv.conf 
lrwxrwxrwx 1 root root 32 Sep 30 14:46 /etc/resolv.conf -> /run/systemd/resolve/resolv.conf

resolvectl status查看一下就出来了配置的DNS

ubuntu@VM-4-13-ubuntu:/run/systemd/resolve$ resolvectl status
GlobalProtocols: -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupportedresolv.conf mode: uplinkDNS Servers: 8.8.8.8 114.114.114.114Link 2 (eth0)Current Scopes: DNSProtocols: +DefaultRoute -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupportedDNS Servers: 183.60.83.19 183.60.82.98Link 3 (docker0)Current Scopes: noneProtocols: -DefaultRoute -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupportedLink 4 (br-ef5110e42154)Current Scopes: noneProtocols: -DefaultRoute -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported

这样就关联上了,但还有些疑惑不太明白,后面再学习~
1.自动生成的机制是怎么样的?
2.Global的 resolv.conf mode: stub ==> resolv.conf mode: uplink,这里受什么控制?


http://www.ppmy.cn/ops/122391.html

相关文章

kubernetes(K8s)学习(一)

本文主要是搭建一个k8s平台,并部署一个springboot的jar包,后续以此作为学习k8s的环境。 1. 搭建k8s集群 网上有很多指导,大家可以在网上搜索一下,比如这个:K8s搭建集群-CSDN博客,本人通过VMware安装3台虚拟…

ip的类型有多少种?我想做大数据需要使用哪一种

IP地址主要分为两种类型: IPv4(Internet Protocol version 4): 由32位二进制数组成,通常以四个十进制数表示(例如:192.168.1.1)。每个十进制数的范围是0到255。IPv4地址的总数量约为…

亲测无限坐席在线客服系统源码/二开版/基于ThinkPHP+搭建教程

源码简介: 亲测了一款实用的无限坐席在线客服系统源码,这可是基于ThinkPHP框架开发的二开版哦!里面还附带了一份超详细的搭建教程。 安装过程简直不能更简单,只需一键操作,启动两个端口就搞定了。而且,它…

【查找算法概念】与【线性表的相关查找算法】

1.知识回顾 2.查找算法相关问题汇总 2.1在哪里查找 查找表 2.2通过什么进行查找 关键字的对应 主关键字:比如我们可以通过一个学号来唯一确定一名学生 这里的学号就是一种主关键字。 次关键字:而通过一个名字李华,我们可能会确定不止一名…

Python项目文档生成常用工具对比

写在前面: 通过阅读本片文章,你将了解:主流的Python项目文档生成工具(Sphinx,MkDocs,pydoc,Pdoc)简介及对比,本文档不涉及相关工具的使用。 概述 近期,由于…

鸿蒙next开发者第一课02.DevEcoStudio的使用-习题

【习题】DevEco Studio的使用 通过/及格分80/ 满分100 判断题 1. 如果代码中涉及到一些网络、数据库、传感器等功能的开发,均可使用预览器进行预览。F 正确(True)错误(False) 预览器不能进行传感器等特殊功能的开发,需要使用真机开发 2. module.json5文件中的…

【python】对象池的使用,如何封装一个对象池管理器

对象池是一种用于管理和复用对象实例的设计模式,通过在需要时从对象池中获取对象,使用完毕后再归还给对象池,可以提高性能和减少资源消耗。下面是一个简单的对象池使用和对象池管理器的封装示例:首先,我们需要定义一个…

MQ(仅供自己参考)

同步通讯的优缺点: 优点:时效高,数据一致,过程简单 缺点:耦合度高。性能下降。CPU等待资源的浪费。级联失败。 2、异步通讯:异步调用常见的实现就是事件驱动模式 异步的优缺点: 优点&#xf…