Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save jotafeldmann/1b84929130a5c2fb1d6d5654f8288c1a to your computer and use it in GitHub Desktop.

Select an option

Save jotafeldmann/1b84929130a5c2fb1d6d5654f8288c1a to your computer and use it in GitHub Desktop.
Enable WSL2 mirrored networking on Windows 11 for localhost access to Windows services (then you can access http://localhost from WSL)

Enable WSL2 Mirrored Networking on Windows 11

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

Requirements

  • Windows 11 22H2 or newer
  • WSL2
  • Recent WSL version

Check your WSL version:

wsl --version

Update WSL if needed:

wsl --update

1. Open .wslconfig

In PowerShell:

notepad $env:USERPROFILE\.wslconfig

If the file does not exist, Notepad will ask to create it.

2. Enable mirrored networking

Add this:

[wsl2]
networkingMode=mirrored
localhostForwarding=true

Optional, useful if you use VPNs or corporate networks:

[wsl2]
networkingMode=mirrored
localhostForwarding=true
dnsTunneling=true
autoProxy=true

3. Restart WSL

Close your WSL terminals, then run in PowerShell:

wsl --shutdown

Start your WSL distro again.

4. Test localhost access

If a Windows app is listening on port 11434, test from WSL:

curl http://localhost:11434/api/tags

For 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 ~/.bashrc

5. Troubleshooting

Check if WSL is still using NAT-style networking:

ip route

If localhost does not work, restart WSL again:

wsl --shutdown

Then 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 :11434

For Ollama, make sure it is reachable from Windows first:

curl.exe http://127.0.0.1:11434/api/tags

References

@jotafeldmann
Copy link
Copy Markdown
Author

ollama serve to show logs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment