EN ▾
Claim trial key

Fixing Ollama Connection Refused on a Remote Server

Ollama connection refused on a remote server almost always means nothing is listening on that address and port from where you are connecting. This page walks through the checks in order and shows a hosted endpoint as the alternative.

Last updated

A cable reaching a closed gate while a ribbon of light passes through an open archway to a cloud rack

Summary

  • Prepaid billing with no monthly fees means you only pay for what you use.
  • Our uncensored model runs on dedicated servers, not as a local proxy.
  • Crypto-only top-ups from $20 to $500 include bonus credit tiers.
  • Streaming, function calling, and JSON mode are fully supported.

What the error means

"Connection refused" is a network-level answer. Your computer reached the target address, and nothing on that address accepted a connection on that port. It is different from a timeout, where packets disappear, and different from a 401 or 404, where a server did answer.

If you came here searching ollama url remote server connection refused, here is the most common cause: Ollama listens only on 127.0.0.1 by default. From the same computer everything works. From another computer, the operating system refuses the connection. The rest of this page confirms that cause and checks the others.

Step 1: confirm the server is running

On the server itself, run a request against localhost. If this fails, the problem is not remote access at all.

# On the server
curl http://localhost:11434/api/tags

# Is anything listening on 11434, and on which address?
ss -ltnp | grep 11434
# 127.0.0.1:11434  -> local only (remote clients are refused)
# 0.0.0.0:11434    -> all interfaces
# *:11434          -> all interfaces

# If you want to stop debugging and use a hosted endpoint instead:
curl https://api.ollamaapiurl.com/v1/models -H "Authorization: Bearer $API_KEY"   # model ID: uncensored

If nothing listens, start the service (systemctl status ollama on Linux, or open the app on macOS and Windows) and read its logs for the reason it stopped, such as a missing GPU driver or a port already in use.

Step 2: fix the bind address

If the output shows 127.0.0.1:11434, remote clients cannot connect. Set OLLAMA_HOST so the server listens on another interface.

  • Linux with systemd. Run sudo systemctl edit ollama and add an [Service] section with Environment="OLLAMA_HOST=0.0.0.0:11434". Then reload and restart the service.
  • macOS app. Set the variable with launchctl setenv OLLAMA_HOST "0.0.0.0:11434" and restart the app.
  • Windows. Add OLLAMA_HOST as a user environment variable, then quit and restart Ollama.
  • Foreground run. Export the variable in the same shell before running ollama serve.

Prefer a specific address over 0.0.0.0 when you can. Binding to your private network address, rather than all interfaces, keeps the service off public networks by construction.

Setting the variable in a shell profile does not affect a service started by systemd or launchd. That mismatch is a frequent reason the change "does nothing".

Step 3: check the firewall and cloud rules

After the server listens on the right address, something else may still be in the way.

  • Host firewall. On Linux, check ufw or firewalld rules for port 11434. Allow only the source addresses you trust.
  • Cloud security groups. On a VPS or cloud VM, the provider's network rules apply before the machine sees traffic. Add an inbound rule for your own address only.
  • Router or NAT. At home, a server behind a router needs port forwarding to be reachable from outside the local network, which is rarely a good idea. Use a VPN or tunnel instead.

Test from the client with curl -v http://SERVER_ADDRESS:11434/api/tags. "Connection refused" points to the bind address or a firewall that rejects. A hang until timeout points to a firewall that silently drops packets.

Step 4: Docker, WSL and URL mistakes

  • Container ports. If Ollama runs in Docker, the port must be published. Check docker ps for a mapping such as 0.0.0.0:11434->11434/tcp. A container started without -p is unreachable.
  • Client in a container. The URL localhost inside a container refers to the container. Use host.docker.internal on Docker Desktop, or the host's address.
  • WSL. A server inside WSL may not be reachable from other machines unless networking is set up for it. Test locally first, then from the LAN.
  • Wrong port or scheme. The default is port 11434 over plain http. An https:// URL will fail unless you added a TLS proxy.
  • Typo in the path. A wrong path gives 404, not "refused", so a refusal is not a path problem.

The article on the uncensored LLM API alternatives and the hosted API docs show the other side of this setup.

Reading the evidence

When the steps above do not settle it, collect evidence from both ends instead of guessing.

  • Server log. On Linux with systemd, journalctl -u ollama shows startup lines, including the address the server bound to. If a request never appears in the log, it never arrived, which points to the network, not to Ollama.
  • Traceroute or ping. A ping that fails tells you about reachability but not about the port, because many hosts block ping. A refused TCP connection, by contrast, proves the host is reachable.
  • Another client. If curl from a third machine works, the problem lies with your first client's network or proxy settings. Corporate proxies and VPN clients are a known cause.
  • Another port. Start a throwaway test server on a different port, for example with Python's built-in HTTP server, and try to reach it. If that also fails, your firewall is the problem, not Ollama.

Remember also that an address can change under you. A home server on a dynamic IP, a cloud VM that was stopped and started, or a DHCP lease that expired will each leave your saved URL pointing at nothing. Use a stable hostname or a reserved address for any server you plan to call regularly, and re-check it first when a working setup suddenly refuses connections.

Write down what changed before the failure appeared: a restart, an upgrade, a new network. Most "it stopped working" cases trace back to a service restart that dropped an environment variable set in a terminal session.

A safer way to connect from elsewhere

Once the connection works, and before you share the address with anyone, think about who else can connect. Ollama has no login, so a reachable port is an open door. The safer choices:

  1. SSH tunnel. Keep Ollama on localhost and run ssh -N -L 11434:127.0.0.1:11434 user@server. Your client then uses http://localhost:11434.
  2. Private network. Join the server and your devices with WireGuard or a similar tool, and bind Ollama to that private address.
  3. Authenticating reverse proxy. Add TLS and a token check in front of Ollama, and keep the Ollama port itself closed to the outside.

All three are things you keep running. If the real goal is calling a model from an app on another machine, they are more work than the task needs.

The alternative: a hosted endpoint with a key

A hosted OpenAI-compatible API replaces the entire chain of bind address, firewall, tunnel and proxy with a URL and a key. Nothing of yours listens on a port, so there is nothing to refuse the connection. Use the base URL https://api.ollamaapiurl.com/v1, a bearer key, and the model uncensored.

import os
from openai import OpenAI

client = OpenAI(base_url="https://api.ollamaapiurl.com/v1", api_key=os.environ["API_KEY"])

reply = client.chat.completions.create(
    model="uncensored",
    messages=[{"role": "user", "content": "Confirm that this connection works."}],
)
print(reply.choices[0].message.content)

The tradeoffs are plain. You pay per token ($0.15 per 1M input and $0.50 per 1M output, prepaid, no subscription, and failed or refused requests are not charged), your prompts go to a provider (they are not used for training), and you get one fixed open-weight model instead of the models you choose locally. The window is 100,000 tokens, and output is text only.

New users can claim $0.50 of trial credit on the API key page to test the connection from the machine that was being refused. It lasts 7 days and needs no card. If the call works there but fails to your own server, the problem is on the server side, which you now have a baseline for. Top-ups and bonuses are on the pricing page.

Frequently asked questions

Why does Ollama work on localhost but refuse remote connections?

It listens on 127.0.0.1 by default. Set OLLAMA_HOST to a reachable address, restart the service, and open the port only to trusted sources.

Is connection refused the same as a timeout?

No. Refused means the target answered and rejected the connection. A timeout usually means a firewall is silently dropping packets.

Is it safe to bind Ollama to 0.0.0.0?

Only on trusted networks, since Ollama has no authentication. Prefer an SSH tunnel, a VPN or a proxy that checks credentials.

Does a hosted API avoid connection refused errors?

It removes the self-hosted causes, since you call a public HTTPS endpoint. You may still see 401 for a wrong key or 429 for limits.

Get your API key in one step

Sign up, copy the key, update your base URL. Simple as that.

Start with free credit

Use email and password; key appears instantly on screen.