ubuntu18.04 netplan 设置dns,dns不生效

ubuntu18.04通过netplan设置DNS,而查看DNS时发现DNS并没生效,其原因是系统指向的问题。

以下是解决步骤:

1.编辑netplan下的yaml文件
2.重启网络 netplan apply
3.删除原resolv.conf, rm -rf /etc/resolv.conf
4.创建软连接,ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf

对于ubuntu18.04的环境,提供了用yaml文件形式修改网络配置,但系统初始设置的/etc/resolv.conf -> /run/systemd/resolv/stub-resolv.conf,如果我们通过/etc/netplan/xxx.yaml修改我们的网络配置,假如更改了DNS,这相当于用户设置的,对应在网卡重启后,即netplan apply后更新的dns配置文件是/run/systemd/resolv/resolv.conf,系统的stub-resolv.conf还是原内容,此时我们通过/etc/resolv.conf查看DNS的配置,其实还是系统初始的软连接,所以如果存在文件用到/etc/resolv.conf时,一定要在网卡重启后,删除原先的/etc/resolv.conf,重新创建软连接,从而使根据用户修改的网络DNS配置指向/etc/resolv.conf,否则还是指向系统的链接指向。

重点

  • 系统初始链接: /etc/resolv.conf -> /run/systemd/resolv/stub-resolv.conf
  • /run/systemd/resolv/resolv.conf: 用户配置网络的DNS,重启后更新此文件
  • /run/systemd/resolv/stub-resolv.conf: 系统配置文件,默认127.0.0.53
  • 用户更改网络的DNS,指向/etc/resolv.conf的文件应改为 /run/systemd/resolv/resolv.conf

更多

外网解答:

Using resolv.conf instead of stub-resolv.conf will bypass a lot of systemd-resolved configuration, such as DNS answer caching, per-interface DNS configuration, DNSSec enforcement, etc.

When using stub-resolv.conf, applications will make DNS requests to the DNS stub resolver provided by systemd on address 127.0.0.53. This stub resolver will proxy the DNS requests to the upstream DNS resolvers configured in systemd-resolved, applying whatever logic it wants to those requests and answers, like caching them.

When using resolv.conf, applications will directly make DNS requests to the "real" (aka. upstream) DNS resolvers configured in systemd-resolved. In this case, systemd-resolved only acts as a "resolv.conf manager", not as a DNS resolver itself.

参考:

posted on   进击的davis  阅读(2805)  评论(0编辑  收藏  举报

编辑推荐:
· 软件产品开发中常见的10个问题及处理方法
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
· 一次Java后端服务间歇性响应慢的问题排查记录
· dotnet 源代码生成器分析器入门
阅读排行:
· ThreeJs-16智慧城市项目(重磅以及未来发展ai)
· .NET 原生驾驭 AI 新基建实战系列(一):向量数据库的应用与畅想
· Ai满嘴顺口溜,想考研?浪费我几个小时
· Browser-use 详细介绍&使用文档
· 软件产品开发中常见的10个问题及处理方法

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示