自学内容网 自学内容网

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

/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
Global
         Protocols: -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
  resolv.conf mode: stub

Link 2 (eth0)
    Current Scopes: DNS
         Protocols: +DefaultRoute -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
Current DNS Server: 183.60.83.19
       DNS Servers: 183.60.83.19 183.60.82.98

Link 3 (docker0)
    Current Scopes: none
         Protocols: -DefaultRoute -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported

Link 10 (br-ef5110e42154)
    Current Scopes: none
         Protocols: -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.conf

ubuntu@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
Global
         Protocols: -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
  resolv.conf mode: uplink
       DNS Servers: 8.8.8.8 114.114.114.114

Link 2 (eth0)
    Current Scopes: DNS
         Protocols: +DefaultRoute -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
       DNS Servers: 183.60.83.19 183.60.82.98

Link 3 (docker0)
    Current Scopes: none
         Protocols: -DefaultRoute -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported

Link 4 (br-ef5110e42154)
    Current Scopes: none
         Protocols: -DefaultRoute -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported

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


原文地址:https://blog.csdn.net/qgf1099062139/article/details/142662001

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!