Post

How to Access Ollama Running on Windows from WSL2

Learn how to enable WSL2 access to Ollama’s local API hosted on Windows.

How to Access Ollama Running on Windows from WSL2

Ollama is an application that allows you to run AI models locally. If you install Ollama on your Windows machine and try to connect to it from WSL2, you will find that it does not work. However, all connections to the server within Windows (e.g. accessing http://localhost:11434/ on the browser) works. This is because WSL2 is not found on the same network as your Windows machine as weird as it sounds. WSL2 has its own virtualized ethernet adapter with a unique IP address, which is different from your Windows machine .

Solution (Windows 11)

If you are already using Windows 11 22H2 and higher, then you can directly use the mirrored networking mode which mirrors the network interfaces that you have on Windows into Linux. The steps are as follows:

  1. Create a new environment variable OLLAMA_HOST = 0.0.0.0 on Windows.
  2. Set networkingMode=mirrored under [wsl2] in your .wslconfig file and then restart WSL using Powershell (Microsoft, 2025).
  3. Restart your WSL by running wsl --shutdown in Powershell.= and then open a new WSL2 terminal.
  4. While Ollama is running, run curl localhost:11434 in WSL2 to check if the connection succeeds. You should see the “Ollama is running” message.

Solution (Windows 10)

Unfortunately, Windows 10 does not support this mirrored networking mode but there is a workaround.

1. Setup environment variable

Create a new environment variable OLLAMA_HOST = 0.0.0.0 on Windows (not WSL2).

This allows Ollama to listen on all interfaces, allowing other devices on your network to send requests to your Ollama server.

2. Update firewall

We now need to stop Windows Defender Firewall from blocking requests from WSL2 (jira, 2022):

  1. Open Windows Defender Firewall and click on Advanced Settings. Windows Defender Firewall home page
  2. Click on Windows Defender Firewall Properties. Advanced properties page of Windows Defender Firewall
  3. In the Public Profile tab, click Customize Protected network connections Public profile tab of firewall properties with Customize Protected network connections button highlighted
  4. Uncheck vEthernet (WSL). Protected network connections tab with vEthernet(WSL) checkbox unchecked
  5. Click Ok and close.
  6. Run the following command in Powershell to verify that the correct firewall rule was disabled:
    1
    
     Get-NetFirewallProfile | Select Name,DisabledInterfaceAliases
    

    The expected output is:

    1
    2
    3
    4
    5
    
     Name    DisabledInterfaceAliases
     ----    ------------------------
     Domain  {NotConfigured}
     Private {NotConfigured}
     Public  {vEthernet (WSL)}
    

Each time you reboot your laptop, this firewall setting is reset for some reason which means that you need to update the firewall settings again to get WSL2 to work with Ollama. One way to overcome this is to create a Powershell script that automatically executes on startup to update the firewall rules.

3. Determine your Windows machine IP address

  1. In WSL2 , run the following command to determine the IP address of your Windows machine:

    1
    
     ip route show | grep -i default | awk '{ print $3}'
    

    A typical output might be 172.30.96.1 .

If the IP address of your computer changes (e.g. due to a wifi repeater that changes IP), then you need to determine the IP of your windows machine before making a request to the Ollama server.

4. Make a request

With the Ollama server running on Windows, you should now be able to make a request from WSL2 with curl http://<YOUR_IP>:11434 (e.g. curl http://172.30.96.1:11434). The output should be Ollama is running%. Similarly, if you are making an API request programmatically, use the same IP address.

References

  1. Microsoft, 2025. Advanced settings configuration in WSL [online]. Available at: https://learn.microsoft.com/en-us/windows/wsl/wsl-config#configuration-settings-for-wslconfig [Accessed 09 July 2025].
  2. Microsoft, 2024. Accessing network applications with WSL [online]. Available at: https://learn.microsoft.com/en-us/windows/wsl/networking#accessing-windows-networking-apps-from-linux-host-ip [Accessed 23 June 2025].
  3. jira, 2022. Available at: https://superuser.com/a/1730670/1764000 [Accessed 16 June 2025].
This post is licensed under CC BY 4.0 by the author.