WSL2 Ubuntu: ping: hostname: Temporary failure in name resolution

友情提示:未必有用。有时候跟网卡配置有关

rm /etc/resolv.conf
vi /etc/resolv.conf
写入下面的内容
nameserver 192.168.2.1
nameserver 114.114.114.114
domain localnet.local

一开始是查Temporary failure in name resolution 的相关问题 ,结果一点用没有,浪费时间

结论:关于WSL2  一定要带上 "WSL2"

转载自

WSL2 Ubuntu: ping: hostname: Temporary failure in name resolution – CT Studio

Now it does what I want it to do. Maybe not what the WSL guys intended, but there you go!

改用外部网络也能解决(缺点,每次开机都要设置)

wsl2 固定ip 和 wsl2 外部网络设置 ,从而解决内部网络的一些问题_viaco2love的博客-CSDN博客_wsl2网络桥接超级管理员查看一下网卡会发现,hyper-v 被勾选了。(上不了网的时候)如果想改回普通模式直接去掉这个勾就行。C:\Users\xxx\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup放一个文件linux-start.vbs内容为Set ws = WScript.CreateObject("WScript.Shell") ws.run "wsl -d Ubuntu...https://blog.csdn.net/viaco2love/article/details/118100683

github 大佬编写的bat

https://github.com/microsoft/WSL/issues/4210

wsl2 设置固定ip - 受气de灰太狼 - 博客园

编写一个bat,然后超级管理员运行就行了

wsl2.static.ip.bat 文件内容如下,wsl -d xxx(子系统名称)

wsl -d Ubuntu -u root ip addr del $(ip addr show eth0 ^| grep 'inet\b' ^| awk '{print $2}' ^| head -n 1) dev eth0


wsl -d Ubuntu -u root ip addr add 192.168.50.2/24 broadcast 192.168.50.255 dev eth0


wsl -d Ubuntu -u root ip route add 0.0.0.0/0 via 192.168.50.1 dev eth0


wsl -d Ubuntu -u root echo nameserver 192.168.50.1 ^> /etc/resolv.conf


powershell -c "Get-NetAdapter 'vEthernet (WSL)' | Get-NetIPAddress | Remove-NetIPAddress -Confirm:$False; New-NetIPAddress -IPAddress 192.168.50.1 -PrefixLength 24 -InterfaceAlias 'vEthernet (WSL)'; Get-NetNat | ? Name -Eq WSLNat | Remove-NetNat -Confirm:$False; New-NetNat -Name WSLNat -InternalIPInterfaceAddressPrefix 192.168.50.0/24;"

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值