当前位置:   article > 正文

ubuntu解决域名不能访问的问题_ubuntu 22.04 resolvectl

ubuntu 22.04 resolvectl

刚装好的ubuntu22.04或ubuntu20.04不能访问百度,然后发现只能ping通ip,而不能ping通www.baidu.com,网上查了下解决方案,

  • 方案一:修改dns:
    修改 /etc/resolv.conf配置文件,但很快就会被覆盖,文件第二行已经声明Do not edit.

    # 显示如下
    # This is /run/systemd/resolve/stub-resolv.conf managed by man:systemd-resolved(8).
    # Do not edit.
    #
    # This file might be symlinked as /etc/resolv.conf. If you're looking at
    # /etc/resolv.conf and seeing this text, you have followed the symlink.
    #
    # 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 should typically 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
    nameserver 8.8.8.8
    nameserver 114.114.114.114
    options edns0 trust-ad
    search .
    
    • 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

    nameserver改为8.8.8.8后保存,再次ping www.baidu.com恢复正常,不出意外的话很快就会发现/etc/resolve.conf又回去了,只好再次寻找查找解决办法

  • 方案二:
    修改/etc/systemd/resolved.conf,去除DNS前的#,修改值如下:

    #  This file is part of systemd.
      2 #
      3 #  systemd is free software; you can redistribute it and/or modify it under the
      4 #  terms of the GNU Lesser General Public License as published by the Free
      5 #  Software Foundation; either version 2.1 of the License, or (at your option)
      6 #  any later version.
      7 #
      8 # Entries in this file show the compile time defaults. Local configuration
      9 # should be created by either modifying this file, or by creating "drop-ins" in
     10 # the resolved.conf.d/ subdirectory. The latter is generally recommended.
     11 # Defaults can be restored by simply deleting this file and all drop-ins.
     12 #
     13 # Use 'systemd-analyze cat-config systemd/resolved.conf' to display the full config.
     14 #
     15 # See resolved.conf(5) for details.
     16 
     17 [Resolve]
     18 # Some examples of DNS servers which may be used for DNS= and FallbackDNS=:
     19 # Cloudflare: 1.1.1.1#cloudflare-dns.com 1.0.0.1#cloudflare-dns.com 2606:4700:4700::    1111#cloudflare-dns.com 2606:4700:4700::1001#cloudflare-dns.com
     20 # Google:     8.8.8.8#dns.google 8.8.4.4#dns.google 2001:4860:4860::8888#dns.google     2001:4860:4860::8844#dns.google
     21 # Quad9:      9.9.9.9#dns.quad9.net 149.112.112.112#dns.quad9.net 2620:fe::fe#dns.qu    ad9.net 2620:fe::9#dns.quad9.net
     22 DNS=8.8.8.8 114.114.114.114
     23 #FallbackDNS=
     24 #Domains=
     25 #DNSSEC=no
     26 #DNSOverTLS=no
     27 #MulticastDNS=no
     28 #LLMNR=no
     29 #Cache=no-negative
     30 #CacheFromLocalhost=no
     31 #DNSStubListener=yes
     32 #DNSStubListenerExtra=
     33 #ReadEtcHosts=yes
     34 #ResolveUnicastSingleLabel=no
    
    
    • 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
    • 32
    • 33
    • 34
    • 35

    重启域名解析服务

    systemctl restart systemd-resolved
    systemctl enable systemd-resolved
    
    • 1
    • 2

    备份当前的/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/
    
    • 1
    • 2
  • 大功告成
    在这里插入图片描述
    在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/579933
推荐阅读
相关标签
  

闽ICP备14008679号