How to Connect to Local Ollama: A Complete Setup Guide
Running a large language model on your own machine is one of the more empowering things you can do as a developer or power user. Ollama makes it surprisingly approachable — but connecting to a local Ollama instance involves more than just installing the app. Whether you're building an app, using a front-end UI, or calling the API from a script, the connection path varies depending on your setup.
What Ollama Actually Does Under the Hood
When you install and run Ollama, it starts a local HTTP server on your machine. By default, that server listens on http://localhost:11434. This is a REST API — the same style of interface used by cloud AI providers — except everything runs locally, with no data leaving your machine.
This means connecting to Ollama isn't really about "connecting" in a network sense the way you'd think of pairing Bluetooth devices. It's about pointing a client — whether that's a terminal, an application, or your own code — at that local address and port.
The Default Connection: localhost:11434
The simplest way to verify Ollama is running and reachable is to open a browser or terminal and check:
http://localhost:11434 If Ollama is running, you'll see a plain text response like Ollama is running. That confirms the server is active and accepting connections.
From the terminal, you can also use:
curl http://localhost:11434/api/tags This returns a list of models you've pulled locally. If it returns data, your connection is working.
Connecting from Code or Scripts
Ollama exposes a clean REST API, so any language that can make HTTP requests can connect to it.
Python example using the requests library:
import requests response = requests.post( "http://localhost:11434/api/generate", json={"model": "llama3", "prompt": "Explain DNS in simple terms", "stream": False} ) print(response.json()["response"]) Using the official Ollama Python library:
import ollama response = ollama.chat(model='llama3', messages=[ {"role": "user", "content": "What is a subnet mask?"} ]) print(response['message']['content']) The official libraries for Python and JavaScript handle the HTTP layer for you and are kept in sync with Ollama's API changes.
Connecting a Front-End UI to Ollama 🖥️
Many users prefer a chat-style interface instead of raw API calls. Tools like Open WebUI, Msty, and Hollama can connect to a local Ollama instance. The general process is:
- Ensure Ollama is running in the background
- Open your chosen UI application
- In the UI's settings, set the API base URL to
http://localhost:11434 - Select a model from your locally pulled list
Most of these interfaces follow the same pattern — they just need the address and port of your Ollama server.
Connecting from Another Device on the Same Network
By default, Ollama only listens on localhost, which means it rejects requests from other devices — even on the same Wi-Fi network. To allow connections from another machine (like a phone, tablet, or second computer), you need to change the bind address.
On Linux/macOS, set the environment variable before starting Ollama:
OLLAMA_HOST=0.0.0.0 ollama serve On Windows, set OLLAMA_HOST as a system environment variable, then restart the Ollama service.
Once set, other devices on the same network can connect using your machine's local IP address instead of localhost:
http://192.168.x.x:11434 ⚠️ Opening Ollama to your local network removes the localhost-only security boundary. Anyone on the same network can send requests to your model. This is usually fine on a trusted home network but worth considering on shared or public networks.
Variables That Affect Your Connection Setup
| Factor | How It Affects Connection |
|---|---|
| Operating system | Environment variable syntax differs between Windows, macOS, and Linux |
| Firewall settings | May block port 11434 even on local network connections |
| Ollama version | API endpoints and supported parameters evolve between releases |
| Running as a service vs. manually | Affects whether Ollama starts automatically and who can manage it |
| Client type | Raw HTTP, official library, or third-party UI each have different config steps |
| Network topology | LAN connections require IP changes; Docker adds its own networking layer |
Connecting Inside Docker
If you're running an application inside a Docker container and want it to talk to Ollama running on the host machine, localhost won't work — containers have their own network namespace.
Use the special Docker hostname instead:
http://host.docker.internal:11434 This resolves to the host machine's IP from inside a container and works on Docker Desktop for Mac and Windows. On Linux with Docker, you may need to use --add-host=host.docker.internal:host-gateway in your run command.
Common Connection Problems
Port already in use: Another process may be occupying 11434. Check with lsof -i :11434 on macOS/Linux or netstat -ano on Windows.
Model not found errors: The connection itself is working, but the model name in your request doesn't match what's pulled locally. Run ollama list to check available model names exactly.
Refused connection: Ollama isn't running. Start it with ollama serve or check that the background service is active.
Timeout from another device: The host machine's firewall is likely blocking the port, or OLLAMA_HOST hasn't been set to 0.0.0.0.
The Setup That Works Depends on Where You're Connecting From
A developer running Python scripts locally has a completely different connection path than someone building a multi-device home lab, running containerized apps, or setting up a shared interface for a team. The mechanics of port, host address, and network scope interact differently in each scenario — and which steps matter most comes down to what your environment actually looks like.