跳过正文
Background Image
  1. Posts/

如何修复 WSL 中的 "Temporary Failure in name resolution" 错误

·200 字·1 分钟· ·
沈显鹏
作者
沈显鹏
目录

问题描述
#

我在 WSL 中执行 ping google.com 时失败,并提示:

Temporary failure in name resolution

解决方法
#

  1. WSL2 中创建或修改 /etc/wsl.conf 文件

  2. 添加以下内容,以防止 DNS 修改被系统覆盖:

    sudo tee /etc/wsl.conf << EOF
    [network]
    generateResolvConf = false
    EOF
    
  3. Windows CMD 中运行:

    wsl --shutdown
    
  4. 重启 WSL2

  5. 在 WSL2 中执行以下命令(search 行可选):

    sudo rm -rf /etc/resolv.conf
    sudo tee /etc/resolv.conf << EOF
    search yourbase.domain.local
    nameserver 8.8.8.8
    nameserver 1.1.1.1
    EOF
    

    如果删除 /etc/resolv.conf 时出现:

    rm: cannot remove '/etc/resolv.conf': Operation not permitted
    

    则先运行以下命令解锁文件:

    sudo chattr -a -i /etc/resolv.conf
    

参考链接
#

https://askubuntu.com/questions/1192347/temporary-failure-in-name-resolution-on-wsl
https://askubuntu.com/questions/125847/un-removable-etc-resolv-conf


转载本文请注明作者与出处,禁止商业用途。欢迎关注公众号「DevOps攻城狮」。

相关文章

在 Windows 做开发还能这么爽?WSL + VS Code + Docker Desktop 你值得有用
·1133 字·3 分钟
本文介绍了如何在 Windows 上使用 WSL、VS Code 和 Docker Desktop 进行开发,提供了安装和配置的详细步骤,以及使用这些工具的优势和体验。
已解决 - The Pip Inspector tree parse failed to produce output
·524 字·2 分钟
本文介绍在 Black Duck Detect 中出现 “The Pip Inspector tree parse failed to produce output” 错误的原因分析及解决方法。
修复 "hidden symbol `__gcov_init' in ../libgcov.a(_gcov.o) is referenced by DSO" 错误
·362 字·1 分钟
本文介绍在使用 Gcov 编译项目进行代码覆盖率统计时,出现 “hidden symbol `__gcov_init’…” 等错误的原因及解决方法,包括如何在构建时确保符号不被隐藏。
为什么 Windows Installer 会弹出窗口?(已解决)
·391 字·1 分钟
本文解释了一个常见的 Windows 安装程序问题:安装时意外弹出窗口的原因,以及通过修正构建文件夹命名规则来解决该问题的方法。
解决 “Remote session was disconnected because there are no Remote Desktop client access licenses available”
·262 字·1 分钟
修复 Windows Server 2012 R2 上的 RDP 连接问题,错误提示为没有可用的远程桌面客户端访问许可证。
限制他人登录你的重要 Linux 服务器
·234 字·1 分钟
本文介绍如何通过修改 /etc/security/access.conf 文件,限制只有特定用户可以登录关键的 Linux 服务器。