How to Test a Proxy in WSL 2
Published
Check which WSL distro runs your app
Start in Windows PowerShell. The VERSION column should show 2 for the distro where your app runs. Microsoft WSL command reference
wsl -l -v
Open a Linux shell in that distro and use the Linux build of cURL. If the app runs under a different Linux account, run its own diagnostic under that account. The shell and the app can have different proxy settings, credentials and certificate stores.
Find the proxy address from Linux
Use the address and port your proxy provider or administrator gives you. If the proxy runs on the Windows host, the address depends on WSL's networking mode. The Windows file %UserProfile%\.wslconfig can specify the mode under [wsl2]. Microsoft WSL configuration reference
Default NAT mode
For a proxy running on Windows, look for the IPv4 gateway after via on WSL's default route. Use that address with the approved proxy port if the service accepts connections on that address. A Windows proxy that listens only on Windows loopback is unreachable from Linux over this NAT path. Inside WSL, 127.0.0.1 normally reaches services in Linux in this mode. WSL networking in NAT mode
ip -4 route show default
Mirrored mode
On supported Windows 11 systems (version 22H2 or later), networkingMode=mirrored lets Linux reach a Windows proxy listening on 127.0.0.1 if your network policy permits it. Use the IPv4 loopback address explicitly when connecting from Linux to Windows. For an approved remote proxy, keep its assigned hostname and port in either mode. WSL mirrored networking
Check proxy DNS and Windows settings
If the proxy uses a hostname, replace proxy.example with that hostname and look it up from Linux before testing the port. If Windows resolves it and Linux does not, check whether the distro has the expected VPN and DNS configuration. In an HTTPS request tunneled through an HTTP proxy, Linux resolves the proxy hostname and the proxy handles resolution of the destination. Microsoft WSL DNS tunneling guidance · How cURL uses HTTP proxies
getent ahosts proxy.example
When autoProxy=true under [wsl2], supported WSL setups can import Windows proxy information as Linux environment variables such as http_proxy, https_proxy and no_proxy. With a proxy auto-configuration (PAC) script, WSL can expose the script URL as WSL_PAC_URL. A Linux app needs PAC support to evaluate that script. Check how your app uses these settings and which proxy the policy selects for your destination. If it needs a static address, ask for the approved address and authentication method. Microsoft guidance on autoProxy and PAC
Send one HTTPS request through the proxy
Run this from the distro where your app runs. Replace http://proxy.example:8080 with the approved HTTP proxy address and port. Use the TestMyProxies IP endpoint if your network permits it, or substitute an approved public HTTPS endpoint. The command keeps TLS verification enabled. --disable skips the default cURL config and --noproxy localhost overrides any inherited bypass list for this public destination. cURL option reference
curl --disable --noproxy localhost --proxy "http://proxy.example:8080" --silent --show-error --connect-timeout 8 --max-time 20 --write-out "\nCONNECT %{http_connect} | Target %{http_code}\n" "https://testmyproxies.com/api/my-ip"
A successful request normally shows CONNECT 200 | Target 200. The endpoint returns the ip it saw. Compare it with the expected proxy exit IP or range. If the proxy requires credentials, use the authentication method approved for that proxy and the identity intended for the Linux app. cURL proxy test and authentication examples
Read the failure and repeat from your app
- Could not resolve proxy. Check the hostname and the distro's DNS resolution. A failed hostname lookup occurs before cURL connects to the proxy.
- Connection refused or timed out. Verify the route, address and port. For a Windows-hosted proxy, check that the listener is available at the address you chose for your WSL mode.
- CONNECT 407. The proxy is reachable and is asking for authentication. Check the Linux client's credentials and its support for the required authentication scheme. HTTP 407 Proxy Authentication Required
- CONNECT 200 with a certificate error. The tunnel opened. Check the HTTPS hostname and the certificate store used by the Linux client. Diagnose proxy TLS certificate errors
Retry the same URL with the app's built-in connection test or through its normal request path. Compare its effective proxy address, authentication scheme, bypass rules and returned IP with the cURL result. If it only fails on VPN, compare both requests while the same VPN session is active.