
> Ollama connection refused?60 秒定位法▋
2026年9月30日· 1 min read
The error never lies about what it means: curl: (7) Failed to connect to localhost port 11434: Connection refused is your operating system reporting that nothing is listening on port 11434. Ollama is not "broken", the model is not corrupted, and the internet's reflex answer — reinstall — misses six boring causes that take a minute each to rule out.
Run the triage command first. It splits the problem in half before you read another section:
curl http://localhost:11434
Ollama is running means the server is fine and your client is calling the wrong place — skip to the host questions. Connection refused means the server side needs work. I reproduced the refusal itself on a throwaway bench box with nothing listening: the kernel answers bash: connect: Connection refused before any application ever gets involved.
Why does Ollama say connection refused?
Because a TCP connect arrived at a host where no socket holds port 11434. That is the whole mechanism — one of six things is true, and they are ranked here by how often each one is the answer, most likely first.
Is Ollama actually running?
The desktop builds (macOS, Windows) run Ollama as a tray application, and it is easier to quit than people expect. The Linux install runs a systemd service that may never have been enabled after a reboot.
# Linux: is the service alive?
systemctl status ollama
# The direct check that works everywhere:
ollama list
ollama list reaching the server answers with a model table. If it answers with a connection error too, start the server and make the start permanent:
sudo systemctl enable --now ollama # Linux: start + survive reboots
journalctl -u ollama -n 50 # if it keeps dying, read why
A service that starts and immediately dies shows up here as a crash loop, and journalctl prints the reason — port already taken, disk full, bad environment override.
Is it the port, or the host you're calling?
Ollama listens on 127.0.0.1:11434 unless told otherwise. Two classic mismatches:
A custom port. If you (or a tutorial you followed) ever set OLLAMA_HOST=127.0.0.1:11435, the server answers on 11435 and every client still calling 11434 gets refused. Confirm what is actually listening:
ss -ltn | grep 1143
Expect one line holding 127.0.0.1:11434. No line at all means the server is down (previous section). A different port or address means your clients are the ones out of date.
localhost versus 127.0.0.1. On some machines localhost resolves to the IPv6 address ::1 first, and a server bound only to 127.0.0.1 never sees those connection attempts. The discriminating test costs two seconds:
curl http://127.0.0.1:11434 # works, and curl http://localhost:11434 refuses
If the raw IP works and the name does not, bind the server to both or point your clients at 127.0.0.1 directly.
Why does it work on the host but not from Docker?
This is the most common flavor in the wild — it is why the autocomplete for this error is full of n8n, Open WebUI and VS Code extensions. Every container that calls http://localhost:11434 is calling itself: inside the container, 127.0.0.1 is the container's own loopback, where nothing listens.
| Caller | Correct URL for the host's Ollama |
|---|---|
| Container on Docker Desktop | http://host.docker.internal:11434 |
| Container on plain Linux | http://host.docker.internal:11434 plus --add-host=host.docker.internal:host-gateway |
| Container on the same Docker network | http://<service-name>:11434 |
| Another machine on your LAN | http://<machine-ip>:11434 (see next section) |
The host-gateway flag comes from Docker's own documentation for exactly this case, and it is the one line that fixes half of all "Ollama connection refused" reports filed from containers.
How do I expose Ollama to other machines?
By default Ollama binds to loopback only — by design, since the API has no authentication. Exposing it is one environment variable, set it in the systemd override rather than your shell so the service actually sees it:
sudo systemctl edit ollama
[Service]
Environment="OLLAMA_HOST=0.0.0.0:11434"
Then sudo systemctl restart ollama and confirm with ss -ltn | grep 11434 — the address column should now read 0.0.0.0:11434. Two follow-ups people skip: a firewall still blocking 11434 produces timeouts rather than refusals (different failure, same port), and browser JavaScript calling the API from another origin needs OLLAMA_ORIGINS set, per Ollama's own FAQ — the browser calls arrive and are turned away at the CORS layer, which looks identical from the outside.
A refused connection is a placement problem, not a broken program: something that should be listening isn't, or the caller is calling from a place the listener doesn't reach.
What if it keeps coming back?
Then one process owns the port and another keeps losing the race. ss -ltnp | grep 11434 shows the process holding the socket; a second Ollama instance started by hand is the usual thief. Kill the stray, leave the service as the single owner, and the error stays gone.
For the rest of the cluster: once the server answers, the GPU it refuses to use is the next most common complaint, and running GGUF models locally covers the load side. Both live in the local LLM hub.
Ollama crossed 181,000 GitHub stars in September 2026 — more machines running it means more of these six answers being needed the same week they are searched. The triage is one curl away.
faq
+ 为什么 Ollama 报 connection refused?
connection refused 是操作系统在回答,不是 Ollama:你调用的那台主机上,11434 端口没有任何进程监听。要么服务没起来,要么它跑在别的端口,要么你从它够不着的地方调用——比如 Docker 容器内部。
+ Windows 下 Ollama connection refused 怎么修?
先看托盘图标:Windows 版 Ollama 以后台应用方式运行,退出托盘图标就会停掉服务。从开始菜单重新启动它,然后用 curl http://localhost:11434 验证——正常应返回 Ollama is running。
+ 为什么 curl 正常,n8n 或 Docker 里却 connection refused?
容器内的 127.0.0.1 指容器自己,不是你的机器。把客户端指向 host.docker.internal(原生 Linux 还要加 --add-host=host.docker.internal:host-gateway),或者用 Docker 网络里的服务名。
+ Ollama 用哪个端口?
默认 11434,绑定在 127.0.0.1。地址和端口都通过 OLLAMA_HOST 环境变量设置,比如 OLLAMA_HOST=0.0.0.0:11434 可以接受来自其他机器的连接。
— mrsaynothing
$ Related entries
Jujutsu 对比 Git:Git 一直没有的那个 undo
2026-09-29
从公开记录读 jj-vcs/jj:31,796 颗星、月更的 release、写进历史的冲突——外加一本能撤销 git 撤销不了的东西的操作日志。
Fatal: Not a Git Repository? The 60-Second Fix
2026-09-28
The four real causes of fatal: not a git repository, ranked plus the one command that tells you which one you have before you touch anything.
My Newsletter Server Is 1,258 Lines of node:sqlite
2026-09-26
I self-hosted this site's newsletter in 1,258 lines: double opt-in, one-click unsubscribe, a send CLI — and one honest deliverability ceiling worth knowing.