clash_for_windows_pkg icon indicating copy to clipboard operation
clash_for_windows_pkg copied to clipboard

[Bug]: WSL2 下能 curl 但是无法 ping 通

Open thsno02 opened this issue 2 years ago • 1 comments

请认真检查以下清单中的每一项

  • [X] 已经搜索过,没有发现类似issue
  • [X] 已经搜索过文档,没有发现相关内容
  • [X] 已经尝试使用过最新版,问题依旧存在
  • [X] 使用的是官方版本(未替换及修改过安装目录程序文件)

软件版本

0.20.5

操作系统

Windows x64

系统版本

win11 21H2

问题描述

WSL2 下能 curl 但是无法 ping 通

复现步骤

  1. powershell 中运行
# 找到 vEthernet (WSL) 这个网络适配器,然后将其所有已有的 IP 地址删除
Get-NetAdapter 'vEthernet (WSL)' | Get-NetIPAddress | Remove-NetIPAddress -Confirm:$False
# 添加 172.17.0.1 并命名为 'vEthernet (WSL)'
New-NetIPAddress -IPAddress 172.17.0.1 -PrefixLength 24 -InterfaceAlias 'vEthernet (WSL)'
# 为了防止冲突,删除名字叫做 WSLNat 的 NAT
Get-NetNat | ? Name -Eq WSLNat | Remove-NetNat -Confirm:$False
# 创建一个名字叫做 WSLNat 的 NAT,设置内部地址为 172.17.0.0/24
New-NetNat -Name WSLNat -InternalIPInterfaceAddressPrefix 172.17.0.0/24;
  1. WSL2 中运行
# 删除掉 WSL2 已经配置的 IP 地址
sudo ip addr del $(ip addr show eth0 | grep 'inet\b' | awk '{print $2}' | head -n 1) dev eth0
# 为其分配 172.17.0.2/24 并限定 DNS Server
sudo ip addr add 172.17.0.2/24 broadcast 172.17.0.255 dev eth0
sudo ip route add 0.0.0.0/0 via 172.17.0.1 dev eth0
# 设置代理
host_ip=$(cat /etc/resolv.conf |grep "nameserver" |cut -f 2 -d " ")
export ALL_PROXY="http://$host_ip:7890"
# 启动 sshd 服务
# https://askubuntu.com/questions/474556/hiding-output-of-a-command
systemctl start sshd.service > /dev/null 2>&1
  1. Clash
    • Clash 中选择了 Allow LAN
    • Clash 中 UWP Loopback 勾选了 Ubuntu
    • Clash 使用 tun mode => gvisor
    • 其他配置均使用默认值

日志文件

其他补充

与 https://github.com/Fndroid/clash_for_windows_pkg/issues/3245 问题相反。

thsno02 avatar Oct 12 '22 06:10 thsno02

目前的解决方案,在 /etc/resolv.conf 中添加新的 nameserver

sudo echo nameserver 172.17.0.1> /etc/resolv.conf
sudo echo "nameserver 8.8.8.8" >> /etc/resolv.conf
sudo echo "nameserver 114.114.114.114" >> /etc/resolv.conf

后能成功 ping 通。但是很奇诡的是,使用 traceroute -T www.google.com 其实还是走的 172.17.0.1,不知道背后的原因是什么。

thsno02 avatar Oct 12 '22 06:10 thsno02