How to proxy on wsl2: Difference between revisions

From 清冽之泉
Jump to navigation Jump to search
Created page with "== 查 WSL 眼中本机的 ip == 查 ipcofig 能查到在 wsl 眼中的主机 ip == == == Host 机 == * Proxy 软件开启允许局域网连入。 * 开防火墙允许 WSL 流量接入本机 <syntaxhighlight lang="bash" line> New-NetFirewallRule -DisplayName "WSL" -Direction Inbound -InterfaceAlias "vEthernet (WSL)" -Action Allow </syntaxhighlight> * .wslconfig 里写入 <syntaxhighlight lang="bash" line> dnsTunneling=false </syntaxhighlight> == Guest 机 == # .bas..."
 
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
== 查 WSL 眼中本机的 ip ==
== 查 IP ==
查 ipcofig 能查到在 wsl 眼中的主机 ip
在 PowerShell 里运行 ipconfig。
 
==  ==


== Host 机 ==
== Host 机 ==
Line 16: Line 14:


== Guest 机 ==
== Guest 机 ==
<syntaxhighlight lang="bash" line>
# .bashrc 里设开关
# .bashrc 里设开关
<syntaxhighlight lang="bash" line>
host_ip=$(awk '/nameserver/ {print $2}' /etc/resolv.conf 2>/dev/null)
host_ip=$(awk '/nameserver/ {print $2}' /etc/resolv.conf 2>/dev/null)
alias pon='export {http,https,ftp,all}_proxy="http://$host_ip:35280"'
alias pon='export {http,https,ftp,all}_proxy="http://$host_ip:12345"'
alias poff='unset {http,https,ftp,all}_proxy'
alias poff='unset {http,https,ftp,all}_proxy'
</syntaxhighlight>
== 检测成功与否 ==
<syntaxhighlight lang="bash" line>
wget www.google.com
curl -Iv https://www.google.com
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 15:31, 30 April 2025

查 IP

在 PowerShell 里运行 ipconfig。

Host 机

  • Proxy 软件开启允许局域网连入。
  • 开防火墙允许 WSL 流量接入本机
New-NetFirewallRule -DisplayName "WSL" -Direction Inbound  -InterfaceAlias "vEthernet (WSL)"  -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