How to Fix “Connection refused” on Ollama Port 11434
Ollama listens on localhost only, by design. Everything else about this error follows from that one default.
On this page
- The 5 causes, in order
- 1. Check it's actually up
- 2. The default that causes this
- 3. From a container, localhost is the container
- 4. The malformed host variable
- 5. Port conflicts and firewalls
- 6. The option I'd pick over opening the port
- 7. Check the model is actually there
- Match your symptom to the fix
- When it's still refused
Ollama runs fine in your terminal. Anything else that tries to reach it gets refused instantly:
Error: dial tcp 127.0.0.1:11434: connect: connection refused
The model is loaded, ollama run works, and your app, your container or your other machine can't get near it. That combination is confusing until you know the default, at which point every symptom lines up.
#The 5 causes, in order
| # | Cause | Tell | Time |
|---|---|---|---|
| 1 | Ollama isn't running | Nothing answers locally either | 1 min |
| 2 | Bound to localhost only | Works locally, refused elsewhere | 5 min |
| 3 | Client using its own localhost | Calling from a container | 5 min |
| 4 | Malformed OLLAMA_HOST |
Connects to port 80 instead | 2 min |
| 5 | Port taken or firewalled | Fails even on the host | 10 min |
#1. Check it's actually up
Start on the machine running Ollama, with the simplest possible test, because half the time the answer is that the server isn't running at all:
curl http://localhost:11434
A healthy install replies with a short confirmation that Ollama is running. If that's refused too, nothing else in this guide matters — start the server first. The desktop application and the ollama serve command are 2 different ways to run it, and quitting the app stops the server even though the command-line tool is still installed and looks ready.
#2. The default that causes this
Ollama listens on 127.0.0.1 out of the box, and that's a sensible default rather than a bug: an LLM server that accepted connections from anywhere the moment you installed it would be a genuinely bad idea on a laptop that joins public networks. The consequence is that every remote client is refused until you opt in.
OLLAMA_HOST=0.0.0.0:11434 ollama serve
On macOS set it in the app's environment and restart, and on Linux with systemd add it as an Environment= line in the service override and reload. Whichever route you take, restart Ollama afterwards — the variable is read at startup, and the single most common follow-up question here is from someone who set it and didn't restart.
Then treat the port as exposed, because it now is. Anything that can reach it can use your GPU and read whatever you send through it, so put it behind a firewall rule that allows only the addresses you intend rather than leaving it open to the network.
#3. From a container, localhost is the container
If your client runs in Docker, this is almost certainly your problem, and it's the same root cause as any other container networking confusion: localhost inside a container means that container, which has no Ollama in it.
On Docker Desktop, point at the host explicitly:
http://host.docker.internal:11434
On Linux that name doesn't exist unless you add it, with extra_hosts: ["host.docker.internal:host-gateway"] in your Compose file. If Ollama itself runs as a container in the same Compose project, use its service name instead — http://ollama:11434 — which is the version that keeps working when you move to a server. The same reasoning, worked through in more detail, is in the n8n ECONNREFUSED guide.
#4. The malformed host variable
This one is quietly nasty because the value looks correct. If OLLAMA_HOST is set to a URL with a scheme but no port, the port defaults to 80, and you end up with a connection refused against a port nothing is listening on while your configuration appears to name the right machine.
OLLAMA_HOST=http://localhost # becomes port 80
OLLAMA_HOST=http://localhost:11434 # explicit, correct
OLLAMA_HOST=localhost:11434 # also fine
Always write the port. The 2 seconds it costs you are cheaper than the 20 minutes of wondering why a correct-looking hostname is being refused.
#5. Port conflicts and firewalls
If it's refused on the host itself, something else may hold the port. Check what's listening, and move Ollama if you need to:
lsof -i :11434
OLLAMA_HOST=127.0.0.1:11435 ollama serve
On Linux the firewall is the other candidate once you've bound to 0.0.0.0. A refusal usually means nothing is listening, while a firewall more often produces a hang or a timeout — so if the connection hangs rather than refusing, look at firewall rules rather than at Ollama.
#6. The option I'd pick over opening the port
You often don't need 0.0.0.0 at all. An SSH tunnel forwards the port to the machine that needs it and nothing else:
ssh -N -L 11434:127.0.0.1:11434 user@the-ollama-machine
Ollama stays bound to loopback. The client talks to its own localhost:11434. Nothing is exposed to the network at any point.
I reach for this first on anything that isn't a container on the same host, because it gives you the access you wanted without the ongoing obligation to firewall a port correctly forever. The tradeoff is that the tunnel has to be running, which is an annoyance on a laptop and a non-issue on a server where it can be a systemd unit.
#7. Check the model is actually there
One more thing, because it produces a different error that gets confused with this one. A reachable server with no model pulled will accept your connection and then fail the request. That isn't a networking problem at all.
ollama list
If the model you're asking for isn't in that output, pull it first. The connection was never the issue.
#Match your symptom to the fix
| What you're seeing | Likely cause | Go to |
|---|---|---|
| Refused on the host itself | Not running, or port taken | 1 and 5 |
| Works on host, refused from Docker | Bound to localhost | 2 and 3 |
| Works on host, refused from another machine | Bound to localhost | 2 |
| Refused on port 80 | OLLAMA_HOST missing its port |
4 |
| Hangs instead of refusing | Firewall dropping packets | 5 |
#When it's still refused
Test from inside the client's own environment rather than from your terminal, because that's the only perspective that counts:
docker compose exec app sh -c "curl -v http://host.docker.internal:11434"
If that's refused while the same call works on the host, Ollama is still bound to loopback and the restart didn't take effect — confirm with lsof -i :11434, where you want to see 0.0.0.0 or * rather than 127.0.0.1 in the listening address. That one line of output settles the question faster than any amount of configuration review.
Frequently asked questions
Is it safe to bind Ollama to 0.0.0.0?
Only behind a firewall you control. It has no authentication, so anything that can reach the port can use your models and your GPU. On a laptop that joins public networks, bind it narrowly or use an SSH tunnel instead.
Why does ollama run work when my app can't connect?
The command-line tool talks to the same server over the same port, but it runs on the host, so loopback is fine for it. Your app is somewhere else, which is exactly the case the default excludes.
Do I have to restart after setting OLLAMA_HOST?
Yes. It's read once at startup. Setting it in a shell and expecting an already-running server to pick it up is the most common reason the fix appears not to work.
Connection refused or timeout — does the difference matter?
It matters a lot. Refused means something answered and said no, which points at the wrong address or port. A timeout means nothing answered, which usually points at a firewall.
Written by
Vemuri Abhiram
Founder & Editor
Vemuri Abhiram is the founder and editor of Underread, where he writes about AI tools, software, and practical technology. He covers hands-on tool reviews, detailed guides, product comparisons, and emerging technologies.
You might also like
How to Fix “CUDA out of memory” When Running a Local LLM
Why a model that loaded yesterday runs out of VRAM today, and the 5 fixes in the order that costs you the least quality.
Vemuri Abhiram6 min read
How to Fix “The requested webhook is not registered” in n8n (404)
Why an n8n webhook works while you watch it and 404s afterwards, and the 5 causes ranked by how often they're the answer.
Vemuri Abhiram5 min read
How to Fix Cloudflare Error 524 on Long LLM Requests (Without an Enterprise Plan)
Why a slow model call dies at exactly 100 seconds behind Cloudflare, and why streaming fixes it when raising timeouts can't.
Vemuri Abhiram6 min read
More from Underread, once a week.
The guides worth reading and the tests worth trusting. One email, every Friday.
No spam. Unsubscribe in one click.

