The symptom: Windows browsers use Clash, WSL2 does not

On a typical Windows 11 workstation you install a Mihomo-based Clash client, import a working profile, and watch Edge or Chrome follow system proxy or a mixed port without drama. The moment you open Ubuntu on WSL2 and run sudo apt update or git fetch, the same machine suddenly feels like two different networks. Downloads stall on direct paths, name resolution may point at odd servers, and verbose logs in your Clash core stay quiet even though “the internet” works from the host.

Nothing is mystically broken. WSL2 runs inside a virtualized network namespace: when a Linux process inside the distro opens 127.0.0.1:7890, it is talking to port 7890 on the Linux side, not the Windows service that you configured for Clash. Until you point traffic at the Windows host IP that bridges the two sides—or you layer a different capture model such as a corporate VPN or a carefully scoped TUN stack on the host that also covers Hyper-V clients—you will keep debugging the wrong half of the system.

If you are also tuning shell exports on a Mac, our macOS terminal proxy guide walks the same mental model: the GUI toggle is not the same contract as a POSIX tool chain. The difference on Windows is that the boundary is not zsh versus launchd; it is a virtual switch between NT and a Linux guest.

The mental model: two hosts, one laptop

Treat WSL2 and Windows as two machines on a small LAN connected by a virtual Ethernet adapter. Your Clash process listens on Windows loopback, on all interfaces, or both depending on the GUI toggles. Linux programs inside WSL2 must use the address of the Windows default gateway for that virtual LAN, not the Linux loopback address, unless you add explicit port forwarding that mirrors a Windows port into the guest.

That single distinction explains a large share of “I pasted export http_proxy=http://127.0.0.1:7890 from a blog and nothing changed” reports. The export was syntactically fine; the address was simply the wrong side of the bridge.

Step 1: Read the real Windows host IP from WSL2

Before you change YAML or firewall rules, print the address your distro already uses to reach Windows. On recent WSL2 releases, the default route inside the guest often matches the nameserver line in /etc/resolv.conf because the stub resolver on Windows also participates in DNS wiring. A compact check looks like this:

ip route show | grep -i default
grep -i nameserver /etc/resolv.conf

The default gateway via value and the first nameserver frequently agree; keep both outputs on screen while you work. If you use multiple WSL distros, repeat the check per distro, because the virtual NIC order can differ after updates.

Write the IPv4 you will target as WIN_IP in your head. You will use it in http_proxy and, if you enable allow LAN on the Clash side, in the bind decision as well. Storing it in a small shell function avoids hunting every reboot—some people wrap it as export WIN_HOST=$(ip route | awk ...) while others prefer the resolv file because it is stable on many builds. Pick one approach, stick to it, and re-check after a major Windows or WSL update because Microsoft has adjusted resolver generation several times.

Step 2: Make Clash reachable from the WSL side

Open your Clash or Mihomo GUI and note the mixed or split HTTP and SOCKS ports—very often a single 7890 mixed listener in documentation, but your template may differ. Then answer two questions: does the service bind only to 127.0.0.1, and is allow LAN disabled?

If the listener is loopback-only, processes on Windows that connect to 127.0.0.1 will continue to work, but WSL2 will never reach that socket across the virtual switch without additional plumbing. The straightforward fix, when you are comfortable with host-side exposure, is to let the client bind the mixed port on 0.0.0.0 and enable the equivalent of allow LAN so the bridge subnet can connect. Tighten Windows Defender Firewall with a narrow inbound rule: scope the allow rule to the vEthernet WSL interface subnet instead of the entire public profile.

If you are not ready to open the port broadly, the alternative is port forwarding on Windows so that a listen address the guest can use maps to the loopback service. An administrator PowerShell or elevated prompt can use netsh interface portproxy to add a v4tov4 mapping. The exact listenaddress and connectaddress pair depends on whether you want the mapping attached to a host-only interface or a specific IPv4, so record your WIN_IP first and test with curl from WSL only after the rule is active.

For sharing Clash to other devices on a physical Wi‑Fi segment, the wider LAN story—including SSID guest isolation and manual phone proxy fields—is covered in our Windows Wi‑Fi LAN proxy article. The WSL2 case is a subnet smaller than a café network, but the same instinct applies: do not allow LAN without a matching firewall story.

Step 3: Export http_proxy, https_proxy, and all_proxy in WSL2

Most CLI tools in Debian- or Ubuntu-based images honor lowercase and uppercase HTTP_PROXY variables, but the ecosystem is as fragmented as on macOS. Set both cases for predictability, and if you use SOCKS for some binaries, set all_proxy as well. With WIN_IP and PORT in place, a minimal block looks like the following, using the mixed port pattern:

export http_proxy="http://WIN_IP:PORT"
export https_proxy="http://WIN_IP:PORT"
export HTTP_PROXY="$http_proxy"
export HTTPS_PROXY="$https_proxy"
export all_proxy="socks5h://WIN_IP:PORT"
export ALL_PROXY="$all_proxy"

Omit the all_proxy lines if your Clash side exposes HTTP only, or set PORT to a dedicated SOCKS listener when your profile uses split ports.

Replace WIN_IP and ports with the values your core actually serves. The socks5h form sends hostnames through the proxy for DNS; match that behavior to how your Clash DNS section resolves names. After exporting, env | grep -i proxy should be clean, then run curl -vI https://example.com and confirm a CONNECT or proxy handshake to WIN_IP instead of a direct TLS path.

Append the same block to ~/.bashrc or ~/.zshrc in the distro, but do not copy secrets into team-wide dotfiles. If you split work between corporate VPN and public networks, use a small wrapper script that sets or clears exports instead of a permanent global proxy in every session.

Step 4: NO_PROXY for local Kubernetes, Docker, and file shares

Once apt and git work through Clash, the next class of failures is over-proxying. A local Minikube IP, a Docker bridge, a git remote on a corporate RFC1918 address, or a Windows file share reached through a translated address should stay DIRECT in the proxy sense even if the rest of the session is tunneled. Maintain a deliberate no_proxy list and mirror it to NO_PROXY:

export no_proxy="127.0.0.1,localhost,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,*.local"
export NO_PROXY="$no_proxy"

Wildcard support varies by library. When a tool still misbehaves, enumerate the exact hostnames. This step is the bridge between “global proxy in WSL2” and “my git remote on a LAN git server is suddenly unreachable” tickets.

Step 5: apt, git, and the pieces that ignore generic exports

apt in Ubuntu derivatives reads /etc/apt/apt.conf and family fragments under /etc/apt/apt.conf.d when you need a persistent proxy separate from a single shell. For a quick test, the environment is enough; for automation images, you may add Acquire::http::Proxy and Acquire::https::Proxy lines with the same http://WIN_IP:PORT values you validated with curl.

Git honors git config --global http.proxy even when the environment looks correct. Check both repository-local and global settings before you blame Clash. A temporary pair of commands mirrors the same proxy URL; remove them when you change ports. For SSH remotes, remember that git over SSH is not the same as HTTPS through HTTPS_PROXY; in that case you are debugging ssh and ~/.ssh/config ProxyCommand patterns instead of HTTP env vars.

Containers started from WSL2 with their own network stack may not inherit the parent shell. Treat each runtime as a separate consumer of the same Windows 11 Clash host IP story.

Step 6: WSL2 DNS that fights your Mihomo policy

When TCP flows finally traverse the mixed port and you still get “can resolve can not connect” or odd CDN edges, the remaining suspect is the Linux resolver behind /etc/resolv.conf. WSL2 can regenerate that file on boot, pointing stub queries at a Windows service that may not match the fake-ip or redir-host model your profile assumes.

If you need a static file, /etc/wsl.conf with generateResolvConf = false and a hand-written resolv.conf is the controlled approach—then point nameserver at an address you truly trust, often a loopback on the Linux side if you also run a local stub, or a well-known public resolver when policy allows. The trade-off is you must own renewals: a wrong static file is worse than the Windows-managed default.

Align this section with the Clash DNS panel in your GUI: if the core is supposed to be the only resolver, make sure the OS is not racing around it. For big-picture TUN, DNS, and global capture topics on desktop, read the Clash TUN mode guide on this site so you can decide when host-level TUN is simpler than permanent WSL2-only exports.

A verification checklist you can run in one sitting

  1. On Windows, confirm the Clash mixed port is listening where you think it is, with client logs set to a useful verbosity level.
  2. In WSL2, print ip route and resolv.conf and write down WIN_IP.
  3. From WSL2, curl -vI http://WIN_IP:PORT to separate firewall refusal from application refusal.
  4. Export http_proxy and HTTPS_PROXY, re-run curl -vI https://example.com, and read whether the handshake mentions the proxy.
  5. Run sudo apt update on a test package index after apt either inherits env or you add Acquire::http::Proxy.
  6. Run a small git ls-remote against an HTTPS host you are allowed to hit.
  7. If only names fail, temporarily test with a resolver you control and compare against your Mihomo DNS settings.

How this differs from a pure shell-only fix on macOS or Linux

On a single bare-metal Linux install, loopback to 127.0.0.1:7890 is usually truthful. In macOS, Terminal and Safari share a kernel with consistent interface semantics for loopback, even though proxy env is still a separate concern, as covered in the link above. Windows 11 with WSL2 is the outlier: 127.0.0.1 in the guest is a different world than the service port on the host, so “first hop” debugging must start at the vNIC, not at subscription latency.

Safety and why we still prefer the site download for clients

Opening listeners beyond loopback, editing firewall rules, and touching resolver files are all powerful operations. Keep your Clash or Mihomo build current, use narrow firewall scopes, and never paste opaque “one-line miracle” portproxy snippets without matching them to your actual WIN_IP and Clash ports. For vetted client packages and the surrounding documentation, start from our documentation hub; for license text and upstream source browsing, use GitHub in a separate step from your everyday installer path.

Closing: the bridge is the product

Once you stop treating WSL2 as “just another terminal” and start treating it as a guest with its own default route, Clash on Windows 11 becomes predictable. Discover WIN_IP, make the mixed listener reachable on that path or map it with portproxy, export HTTP_PROXY and friends consistently, give apt and git the explicit nudge they sometimes need, then align DNS with the resolver model your profile expects. The reward is a single mental map that works for curl, apt, and long git sessions without re-importing a profile every time Windows Update touches Hyper-V.

Among desktop proxy stacks, a maintained Clash or Mihomo client on Windows with clear toggles, logs, and documentation still makes that bridge easier to own than a pile of ad hoc scripts. When your guest shell finally shows the same egress as the browser on the host, you can return to the code you actually opened the terminal to write.

→ Download Clash for free and experience the difference

Download Clash from this site