This guide configures WSL2 to use mirrored networking mode, so Linux inside WSL can access Windows-hosted services through localhost.
Example use case: curl from WSL2 Ubuntu to reach Ollama running on Windows:
curl http://localhost:11434/api/tags- Windows 11 22H2 or newer
- WSL2
- Recent WSL version
Check your WSL version:
wsl --versionUpdate WSL if needed:
wsl --updateIn PowerShell:
notepad $env:USERPROFILE\.wslconfigIf the file does not exist, Notepad will ask to create it.
Add this:
[wsl2]
networkingMode=mirrored
localhostForwarding=trueOptional, useful if you use VPNs or corporate networks:
[wsl2]
networkingMode=mirrored
localhostForwarding=true
dnsTunneling=true
autoProxy=trueClose your WSL terminals, then run in PowerShell:
wsl --shutdownStart your WSL distro again.
If a Windows app is listening on port 11434, test from WSL:
curl http://localhost:11434/api/tagsFor Ollama specifically:
export OLLAMA_HOST="http://localhost:11434"
curl "$OLLAMA_HOST/api/tags"To persist this for future shells:
echo 'export OLLAMA_HOST="http://localhost:11434"' >> ~/.bashrc
source ~/.bashrcCheck if WSL is still using NAT-style networking:
ip routeIf localhost does not work, restart WSL again:
wsl --shutdownThen reopen WSL.
If a Windows service still cannot be reached, check whether the Windows app is listening only on 127.0.0.1 or on all interfaces:
netstat -ano | findstr :11434For Ollama, make sure it is reachable from Windows first:
curl.exe http://127.0.0.1:11434/api/tags- Microsoft WSL networking docs: https://learn.microsoft.com/en-us/windows/wsl/networking
- Microsoft WSL config docs: https://learn.microsoft.com/en-us/windows/wsl/wsl-config
ollama serveto show logs.