Why Ollama says connection refused, and how to fix it
curl: (7) Failed to connect to 127.0.0.1 port 11434: Connection refused
Also appears as
- Error: could not connect to ollama app, is it running?
- dial tcp 127.0.0.1:11434: connect: connection refused
- requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=11434): Max retries exceeded
Short answer
Ollama connection refused almost always means the ollama serve process is not running, is listening on a different interface than expected, or is bound to 127.0.0.1 while your client is calling it from another host or container. Start or restart the service, confirm it is listening on 11434, and if you need remote access set OLLAMA_HOST to 0.0.0.0 explicitly.
Affects: Ollama 0.1.x and later, Linux, macOS, and Windows installs, both native service and Docker deployments
Fix it in 60 seconds
- 1Check whether Ollama is running: ps aux | grep ollama on Linux/macOS or check the tray icon on Windows.
- 2Start it manually if it is not running: ollama serve (or restart the ollama systemd service with systemctl restart ollama).
- 3Confirm it is listening: curl http://127.0.0.1:11434/api/tags should return JSON, not a connection error.
- 4If calling from another container or machine, set OLLAMA_HOST=0.0.0.0:11434 before starting the service and retry.
- 5If still refused, check for a firewall rule blocking port 11434 and allow it for your trusted network.
How to confirm this is your problem
- curl or any HTTP client to localhost:11434 fails immediately with connection refused
- The Ollama desktop app or CLI works fine locally but a script or container calling it over the network fails
- ollama list works from the terminal but a separate process cannot reach the API
- The error appears right after a reboot or after the machine was updated
Root causes and fixes
The ollama service is not running
Ollama runs as a background service (a systemd unit on Linux, a menu bar app on macOS, or a tray app on Windows) that listens on port 11434. If the process crashed, was never started, or was stopped by a system update, there is nothing listening on that port and any connection attempt is refused immediately at the TCP level.
Fix: Start the service directly with ollama serve in a terminal to see any startup errors, or restart the managed service with systemctl restart ollama on Linux. On macOS or Windows, quit and relaunch the Ollama app from the applications menu.
systemctl status ollama systemctl restart ollama ollama serve
OLLAMA_HOST is bound to localhost only
By default Ollama binds to 127.0.0.1, which only accepts connections originating from the same machine. A request from a Docker container, a different VM, or another host on the network is refused even though the service is healthy, because the kernel never routes that traffic to a loopback-bound socket.
Fix: Set the environment variable OLLAMA_HOST=0.0.0.0:11434 before starting the service so it binds to all interfaces, then restart Ollama. Pair this with a firewall rule or reverse proxy since it removes the implicit localhost-only protection.
export OLLAMA_HOST=0.0.0.0:11434 systemctl set-environment OLLAMA_HOST=0.0.0.0:11434 systemctl restart ollama
A firewall or security group is blocking port 11434
Even with the service correctly bound to 0.0.0.0, host firewalls (ufw, firewalld, Windows Defender Firewall) or cloud security groups drop inbound traffic to ports that were never explicitly opened, which produces the same connection-refused or connection-timeout behavior from the client side.
Fix: Open port 11434 for the specific source network you trust, not for the whole internet. On Ubuntu use ufw, on a cloud VM update the security group or NSG rule.
sudo ufw allow from 10.0.0.0/8 to any port 11434 sudo firewall-cmd --add-port=11434/tcp --permanent
Another process is already using port 11434
If a previous Ollama instance did not shut down cleanly, or another application was configured to use the same port, the new Ollama process fails to bind and can exit silently in some install methods, leaving nothing listening even though you just ran the start command.
Fix: Check what is bound to the port and stop the stale process, or change Ollama's port with OLLAMA_HOST=127.0.0.1:11435 and update your client to match.
sudo lsof -i :11434 sudo kill <pid>
Calling the API from inside a container without host networking
A container that calls localhost:11434 is talking to its own network namespace, not the host, so even a healthy host-level Ollama service is unreachable. This produces connection refused inside the container while the host itself works fine.
Fix: Use host.docker.internal instead of localhost from inside the container on Docker Desktop, run the container with --network host on Linux, or point OLLAMA_HOST at the container-reachable host IP.
curl http://host.docker.internal:11434/api/tags docker run --network host ollama/ollama
Diagnostic commands
Check if the process is running
ps aux | grep ollama
No matching process means the service crashed or was never started; restart it and read the startup log for the real error.
Check what is listening on the port
sudo ss -tlnp | grep 11434
If nothing is listed, Ollama is not bound to that port at all. If it shows 127.0.0.1:11434, remote clients will be refused; you need 0.0.0.0:11434 for remote access.
Test the API locally
curl -v http://127.0.0.1:11434/api/tags
A JSON list of models confirms the service is healthy locally; a connection refused here means the service itself is down, not a networking issue.
Check the service logs
journalctl -u ollama -n 50 --no-pager
Look for bind errors, permission errors, or crash stack traces that explain why the process exited after starting.
Stopping it from happening again
- Run Ollama as a managed systemd service (or the official Docker image) rather than a manual background process, so it restarts automatically on crash or reboot.
- Document your intended OLLAMA_HOST value in your deployment scripts instead of relying on the default, so binding behavior is explicit and reviewed.
- Add a basic health check (curl to /api/tags) to your deployment or monitoring pipeline so a dead service is caught before a user hits it.
- Keep firewall rules for port 11434 scoped to specific subnets, and review them whenever you move Ollama to a new host.
When this becomes an architecture problem
If connection refused persists across multiple hosts, or you find yourself opening 11434 to broad network ranges just to make things work, that is a sign you need a proper reverse proxy with authentication and TLS rather than ad hoc firewall rules, which is an architecture decision worth getting right before you have real users depending on it.
Frequently asked questions
Does restarting my computer fix Ollama connection refused?
Sometimes, because a reboot restarts the Ollama service along with everything else, but if the underlying cause is a wrong OLLAMA_HOST binding or a firewall rule, the error will return as soon as another process tries to reach it remotely. Treat a reboot as a temporary workaround, not a fix.
Why does curl localhost:11434 work but my Python script fail?
This usually means the Python script is running inside a container or environment with a different network namespace than your shell, or it is pointed at a different host or port than the one Ollama is actually bound to. Print the exact URL your client is using and compare it to ss -tlnp output.
Is it safe to bind Ollama to 0.0.0.0?
Only on a trusted network, because Ollama's API has no built-in authentication. Binding to 0.0.0.0 without a firewall rule or reverse proxy in front of it exposes model inference, and potentially your prompts, to anyone who can reach that port.
What port does Ollama use by default?
11434 for the HTTP API. You can change it by setting OLLAMA_HOST to a different host:port combination, but make sure every client and container that talks to Ollama is updated to match.
Size it properly next time
Free calculators that prevent this class of failure before you provision hardware.
On-Prem AI Deployment Checklist
A 30-point pre-deployment checklist covering use cases, hardware, security, model operations, and rollout for self-hosted enterprise LLMs.
Free ToolAir-Gapped LLM Deployment Checklist
A practical control checklist for deploying and maintaining large language models in a fully air-gapped environment, from initial staging through ongoing patching and drift detection.
Related problems
Configuring Ollama for remote access safely
Ollama binds to 127.0.0.1 by default, which blocks any connection from another machine, container, or network. Setting OLLAMA_HOST=0.0.0.0 makes it listen on all interfaces, but Ollama's API has no built-in authentication, so any remote-accessible instance must sit behind a reverse proxy or VPN that adds authentication and TLS before it is exposed beyond a fully trusted local network.
Ollama says a model was not found
Ollama model not found means the exact tag you requested, including the version suffix after the colon, does not exist locally or in the registry. Either the tag has a typo, the model was never pulled, or a custom Modelfile references a FROM path that does not resolve on this machine. Run ollama list to see what is actually installed, then pull or fix the Modelfile.
GPU not visible inside a Docker container
Docker containers cannot see a host GPU unless the NVIDIA Container Toolkit is installed and the nvidia runtime is registered with the daemon, since containers are isolated from host devices by default. The fix is almost always to install nvidia-container-toolkit, run nvidia-ctk runtime configure, restart Docker, and launch with --gpus all. If nvidia-smi already fails on the host itself, the problem is the driver, not Docker.
Kubernetes readiness probe fails while the model is still loading
LLM service pods get killed or marked unready during startup because default Kubernetes readiness and liveness probes assume a service starts in seconds, while loading multi-gigabyte weights into GPU memory can take minutes. Add a startupProbe sized with a failureThreshold times periodSeconds budget that comfortably exceeds your worst-case load time; Kubernetes suppresses readiness and liveness checks entirely until the startup probe succeeds, which stops premature restarts without needing a fragile fixed initialDelaySeconds guess.
GuideOn-Prem LLM Deployment Architecture: Reference Guide
Reference architecture for on-prem LLM deployment: inference servers, GPU sizing, RAG pipelines, and security zones for regulated manufacturers.
GuideAir-Gapped LLM Deployment Patterns That Actually Work
Air-gapped LLM deployment patterns that work: offline model transfer, update workflows, monitoring without telemetry, and CMMC-ready architectures.
Still stuck, or tired of fighting your own infrastructure?
Netray deploys and operates on-prem AI for regulated manufacturers and defense suppliers. We have debugged this stack in production, on air-gapped networks, at scale.