Access Ollama From Another Computer on Your LAN (Safely)
If you are getting connection refused when trying to reach your Ollama server from another machine, the fix requires changing the binding address and opening port 11434. Here is how to do it safely.

The Symptom: Connection Refused
Related: Fix LM Studio "Failed to load model" Error →
You have a powerful desktop computer running Ollama, maybe with a dedicated GPU. You want to sit on your couch with your laptop, write some code, and send API requests to that desktop.
You find the IP address of your desktop (let's say it is 192.168.1.50), you open your terminal on the laptop, and you run this:
curl http://192.168.1.50:11434/api/tagsInstead of a JSON list of your downloaded models, you immediately get slapped with this:
curl: (7) Failed to connect to 192.168.1.50 port 11434: Connection refusedI ran into this exact problem last week. By default, Ollama is hardcoded to bind only to 127.0.0.1 (localhost). This is a smart security default. It means only the machine running Ollama can talk to it. But if you are testing locally or building a local RAG chatbot on a separate development laptop, it is incredibly annoying.
To fix this, you have to tell Ollama to listen on all network interfaces, and then you have to tell your operating system's firewall to let the traffic through. Alternatively, you can bypass the firewall completely using an SSH tunnel. I will show you how to do both, based on exactly what worked for my setup.
Step 1: Setting OLLAMA_HOST
Related: Fix Stable Diffusion Out Of Memory on a 6GB VRAM GPU →
The environment variable that controls where Ollama listens is OLLAMA_HOST. We need to change it from the default 127.0.0.1 to 0.0.0.0, which tells the service to listen on all available network interfaces (Ethernet, Wi-Fi, etc.).
How you set this depends entirely on your operating system.
On Linux (Systemd)
If you installed Ollama on Linux using their official install script, it runs as a systemd service. You cannot just export a variable in your terminal and expect the background service to see it.
You need to create a systemd override file. Run this command:
sudo systemctl edit ollama.serviceThis opens your default terminal text editor. Do not edit the commented-out lines. Add the following text right at the top of the file:
[Service]
Environment="OLLAMA_HOST=0.0.0.0:11434"Save the file and exit the editor. Then, reload the systemd daemon and restart Ollama to apply the changes:
sudo systemctl daemon-reload
sudo systemctl restart ollamaTo verify the service is actually listening on the new address, run:
sudo netstat -tulpn | grep 11434You should see :::11434 or 0.0.0.0:11434 in the local address column.
On macOS
If you run the Ollama Mac app, it is managed by launchctl. Open your terminal and run:
launchctl setenv OLLAMA_HOST "0.0.0.0"After running that command, you must quit the Ollama app completely. Click the Ollama icon in your top menu bar and select "Quit Ollama". Then open your Applications folder and launch it again.
On Windows
If you are using the native Windows preview of Ollama, you need to set a system-wide environment variable.
- Open the Start menu and type "environment variables".
- Click "Edit the system environment variables".
- Click the "Environment Variables..." button at the bottom.
- Under the "System variables" section (the bottom half), click "New...".
- Set Variable name to
OLLAMA_HOSTand Variable value to0.0.0.0. - Click OK on all windows.
You must restart the Ollama application. Look for the llama icon in your system tray (bottom right corner), right-click it, and click "Quit". Then relaunch it from the Start menu.
Note: If you run Windows but installed Ollama inside WSL2 instead of natively, you are dealing with a virtualized network bridge. You will need to configure Windows port proxying, especially if you spent hours fixing Ollama not using my NVIDIA GPU in WSL2 and want to keep your Linux environment intact.
Step 2: Opening the Firewall
Related: Fix ComfyUI "Torch Not Compiled With CUDA Enabled" Error →
Even after telling Ollama to listen on 0.0.0.0, your operating system will usually drop incoming requests from other computers. You have to open port 11434.
Linux (UFW)
If you are on Ubuntu or Debian, you are likely using UFW (Uncomplicated Firewall). Open the port by running:
sudo ufw allow 11434/tcp
sudo ufw reloadWindows Defender Firewall
By default, Windows aggressively blocks incoming connections to new ports. To open it, open PowerShell as an Administrator and run this exact command:
New-NetFirewallRule -DisplayName "Ollama API" -Direction Inbound -LocalPort 11434 -Protocol TCP -Action AllowYou can verify the rule was added by opening "Windows Defender Firewall with Advanced Security" and checking your Inbound Rules.
A Warning About CORS
If you are trying to access your Ollama server from a web browser on your laptop (for example, using a WebUI), you will hit a CORS (Cross-Origin Resource Sharing) error. The browser will block the request because the domain of the UI does not match the domain of the API.
To fix this, you must add a second environment variable exactly the same way you added OLLAMA_HOST. The variable is OLLAMA_ORIGINS.
Set it to "*" (an asterisk) to allow all origins, or set it to the specific IP of your laptop (e.g., "http://192.168.1.60"). If you are testing different local frontends or comparing different UIs like Ollama vs LM Studio vs Jan, setting it to "*" is usually the fastest way to get things working.
The SSH Tunnel Alternative (My Preferred Method)
Related: A One-File Docker Compose Stack for Ollama and Open WebUI →
If you are on a home network you completely trust, changing OLLAMA_HOST and opening the firewall is fine. But if you are in a dorm room, an office, or on public Wi-Fi, you do not want to expose an unauthenticated AI API to your local subnet. Anyone on the network could send heavy compute requests to your machine and max out your GPU.
Instead of changing OLLAMA_HOST or touching your firewall, leave Ollama completely isolated on 127.0.0.1.
Instead, open a terminal on your laptop (the machine you want to work from) and create an SSH tunnel to your desktop:
ssh -N -L 11434:localhost:11434 your_username@192.168.1.50Here is what these flags actually do:
-Ntells SSH not to open a shell prompt; just hold the connection open.-L 11434:localhost:11434tells SSH to grab port11434on your laptop, and forward any traffic securely through the SSH tunnel tolocalhost:11434on the desktop.
Once you run this command (and leave the terminal open), you can write code on your laptop exactly as if Ollama were running locally. Your Python scripts can just target http://localhost:11434.
If you are integrating tools using the architecture from MCP servers explained, this SSH method is a lifesaver because you don't have to rewrite any hardcoded localhost URLs in your client configs.
Comparing the Methods
Related: Fixing Painfully Slow Whisper Transcription →
Depending on your daily workflow, one of these approaches will make more sense than the other. Here is how I think about them.
| Method | Setup Time | Security | Best Used For |
|---|---|---|---|
| OLLAMA_HOST (0.0.0.0) | 5 minutes | Low (No auth) | Trusted home networks, dedicated homelab servers. |
| SSH Port Forwarding | 1 minute | High (Encrypted, auth required) | Laptops, untrusted networks, temporary access. |
| Reverse Proxy (Nginx/Caddy) | 30+ minutes | High (Can add Basic Auth / HTTPS) | Exposing Ollama to the public internet securely. |
What Did NOT Work
Related: Fix Open WebUI Showing No Models in the Dropdown →
I wasted an entire evening going down some dead ends while trying to set this up. Here is what you should avoid.
Editing the main systemd file directly
At first, I opened /etc/systemd/system/ollama.service and added the environment variable there. It worked until the next time I updated Ollama via the curl script. The update completely overwrote the file and my changes were lost. You must use sudo systemctl edit ollama.service to create an override file in the ollama.service.d directory. That survives updates.
Using specific LAN IPs
I tried setting OLLAMA_HOST=192.168.1.50 instead of 0.0.0.0. It worked fine for a week, and then my router rebooted. DHCP assigned my desktop a new IP address (192.168.1.52). The Ollama service crashed on startup because it was trying to bind to an IP address that no longer belonged to the machine. Just use 0.0.0.0.
Docker host networking on Mac
I originally ran Ollama in Docker. I tried passing --network host to the docker run command, expecting it to bind to my Mac's LAN IP. Docker on Mac runs inside a lightweight virtual machine. --network host binds to the VM's network, not the Mac's physical Wi-Fi interface. I still had to publish the ports explicitly with -p 11434:11434.
FAQ
Question: Does this expose my Ollama server to the internet?
Answer: No. As long as your home router has a standard NAT firewall and you haven't manually forwarded port 11434 on your router to your computer, this only exposes Ollama to other devices on your local Wi-Fi.
Question: How do I test if the port is actually open?
Answer: From the secondary computer, open a terminal and run nc -vz 192.168.1.50 11434. If it says "Connection refused", your firewall is still blocking it. If it says "succeeded", the network path is clear.
Question: Why am I getting "Failed to fetch" in Open WebUI?
Answer: This is a CORS issue. Your browser is blocking the request to the API. You must set the OLLAMA_ORIGINS environment variable to * on the server running Ollama, then restart the Ollama service completely.
Question: Can I use a hostname instead of remembering the IP address?
Answer: Yes. If your operating systems and router support mDNS, you can reach your machine via its local hostname. For example, curl http://my-desktop.local:11434/api/tags will resolve without needing a static IP.
مواضيع مقترحة · Suggested Topics
استكشف مواضيع ومحاور ذات صلة بهذا المقال — روابط داخلية لتعميق قراءتك.
The Daily Pulse
Newsletter delivery is not connected yet. This form only saves your address in this browser; no email is sent.
Get concise, source-linked technology notes without the hype.