ubuntu解决域名不能访问的问题

news/2025/2/21 7:42:22/

刚装好的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 .
    

    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 the4 #  terms of the GNU Lesser General Public License as published by the Free5 #  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 configuration9 # should be created by either modifying this file, or by creating "drop-ins" in10 # 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.com20 # Google:     8.8.8.8#dns.google 8.8.4.4#dns.google 2001:4860:4860::8888#dns.google     2001:4860:4860::8844#dns.google21 # 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.net22 DNS=8.8.8.8 114.114.114.11423 #FallbackDNS=24 #Domains=25 #DNSSEC=no26 #DNSOverTLS=no27 #MulticastDNS=no28 #LLMNR=no29 #Cache=no-negative30 #CacheFromLocalhost=no31 #DNSStubListener=yes32 #DNSStubListenerExtra=33 #ReadEtcHosts=yes34 #ResolveUnicastSingleLabel=no

    重启域名解析服务

    systemctl restart systemd-resolved
    systemctl enable systemd-resolved
    

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


http://www.ppmy.cn/news/136693.html

相关文章

常用 DNS 分享

DNS 域名系统,他可以将域名(例如www.baidu.com)转换为计算机用于在互联网上的 IP 地址的系统。它允许用户使用易于记住的域名访问网站,而不必记住IP地址。全球常用DNS:Google Public DNS: 8.8.8.8 and 8.8.4.4 OpenDN…

全球免费公共 DNS 解析服务器 IP 地址列表推荐 (解决无法上网/加速/防劫持)

全球免费公共 DNS 解析服务器 IP 地址列表推荐 基本上接触过网络相关知识的人应该多少都会听过 DNS 这个名词。因为 DNS 它非常重要,在我们上网的过程中扮演着重要的角色——“将网址/域名解析成 IP 地址”。 如果配置了不合理的 DNS 服务器,可能会导致…

Linux 网络配置与网关设置

多网卡配置: metric 120 dns-nameservers 192.168.15.1 166.111.8.28 166.111.8.29 114.114.114.114 8.8.8.8 网关设置: ref: linux - How to configure systemd-resolved and systemd-networkd to use local DNS server for resolving local domains …

linux开启ipv6

一、阿里云ecs服务器配置(centos系统) 1.修改/etc/sysctl.conf中ipv6的配置,如下 net.ipv6.conf.all.disable_ipv6 0 net.ipv6.conf.default.disable_ipv6 0 net.ipv6.conf.lo.disable_ipv6 0 2.修改/etc/modprobe.d/disable_ipv6.conf的配置,如下 …

QQ群文件无法显示,空白,加载不出来

无法访问的情况在我的电脑中发生了,就贴出来了给各位参考。 我的网络可以使用IPV6,并且使用google的Ipv6DNS(2001:4860:4860:8888)才出现了这种情况。 并且不止腾讯的会出现这种问题,都是开启Ipv6后某些地址被解析到错误的Ip导致不能访问。…

25 openEuler管理网络-使用nmcli命令配置ip

文章目录 25 openEuler管理网络-使用nmcli命令配置ip25.1 nmcli介绍25.2 设备管理25.2.1 连接到设备25.2.2 断开设备连接 25.3 设置网络连接25.3.1 配置动态IP连接25.3.1.1 配置IP25.3.1.2 激活连接并检查状态 25.3.2 配置静态IP连接25.3.2.1 配置IP25.3.2.2 激活连接并检查状态…

2023.4.4

24:final关键字 final修饰变量: (1)final修饰一个基本类型的变量,变量的值不可以改变,这个变量也变成了一个字符常量,规定:名字大写。 (2)final修饰一个引用…

公用IPv6 IPv4 DNS

IPv6 下一代互联网国家工程中心 China IPv6 DNS 服务器 雪人计划 Yeti DNS Project 首选:240c::6666 备用:240c::6644 备用:240c::4444 CNNIC IPv6 DNS 服务器 首选:2001:dc7:1000::1 百度 2400:da00::6666 阿里云 2400:3200::1 2…