WSL2 proxy 的方法

From 清冽之泉
Revision as of 10:31, 29 September 2025 by Mwroot (talk | contribs) (Created page with "== 查 IP == 在 PowerShell 里运行 ipconfig。 == Host 机 == * Proxy 软件开启允许局域网连入 * 开防火墙允许 WSL 流量接入本机 * 把那条系统自建的 WSL 入站规则先删掉 <syntaxhighlight lang="bash" line> New-NetFirewallRule -Name "WSL-Allow-Inbound" -DisplayName "WSL-Proxy" -InterfaceAlias "vEthernet (WSL)" -Direction Inbound -Action Allow </syntaxhighlight> * .wslconfig 里写入 <syntaxhighlight lang="bash" line> dnsTunneling=false <...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

查 IP

在 PowerShell 里运行 ipconfig。

Host 机

  • Proxy 软件开启允许局域网连入
  • 开防火墙允许 WSL 流量接入本机
  • 把那条系统自建的 WSL 入站规则先删掉
New-NetFirewallRule -Name "WSL-Allow-Inbound" -DisplayName "WSL-Proxy" -InterfaceAlias "vEthernet (WSL)" -Direction Inbound -Action Allow
  • .wslconfig 里写入
dnsTunneling=false

Guest 机

# .bashrc 里设开关
host_ip=$(awk '/nameserver/ {print $2}' /etc/resolv.conf 2>/dev/null)
alias pon='export {http,https,ftp,all}_proxy="http://$host_ip:12345"'
alias poff='unset {http,https,ftp,all}_proxy'

检测成功与否

wget www.google.com
curl -Iv https://www.google.com