Access Ollama from Another Device: OLLAMA_HOST vs SSH Tunnel
OLLAMA_HOST=0.0.0.0 opens Ollama's unauthenticated API to your whole network. Reach it from another device through an SSH tunnel, or firewall the source.
Ollama listens only on 127.0.0.1:11434 by default (official FAQ). Calling a desktop or server's Ollama from your laptop is therefore refused, and the usual fix is OLLAMA_HOST=0.0.0.0. But the official docs state that "the local API at http://localhost:11434 does not require authentication." Widen the address and anyone who can reach it gets the same access. Solve it with an SSH tunnel first, and open the port only when you really must, together with a firewall rule.
[1] See what you expose. Here a server started from the official image (default OLLAMA_HOST=0.0.0.0:11434) is called from a container standing in for another device. Nothing in the response asks for credentials:
$ curl -sS -i http://192.0.2.10:11434/api/tagsHTTP/1.1 200 OKContent-Type: application/json; charset=utf-8…{"models":[{"name":"qwen2.5:0.5b-instruct-fp16","model":"qwen2.5:0.5b-instruct-fp16", …It isn't read-only. A delete request from the same place was accepted:
$ curl -sS -X DELETE http://192.0.2.10:11434/api/delete -d '{"model":"qwen2.5:0.5b-instruct-fp16"}' -w 'HTTP %{http_code}\n'HTTP 200The model was gone from the server's ollama list. Anyone on the network can make it pull models (/api/pull), delete them, or burn its compute:
NAME ID SIZE MODIFIEDqwen2.5:0.5b a8b0c5157701 397 MB 12 minutes ago[2] If you can SSH to the machine, use a tunnel. Leave the server's Ollama on 127.0.0.1 and open the tunnel from the calling device:
$ ssh -f -N -L 11434:127.0.0.1:11434 user@server1-L 11434:127.0.0.1:11434 forwards connections to your local 11434 to 127.0.0.1:11434 inside server1. -f -N keeps just the tunnel running in the background. Apps on the calling side keep using http://127.0.0.1:11434. In testing, connecting straight to the loopback-only server was refused, and after opening the tunnel the local 127.0.0.1 answered:
$ curl -sS http://192.0.2.10:11434/api/version; echo "exit=$?"curl: (7) Failed to connect to 192.0.2.10 port 11434 after 0 ms: Couldn't connect to serverexit=7$ curl -sS http://127.0.0.1:11434/api/version; echo; echo "exit=$?"{"version":"0.40.11"}exit=0If the calling device already runs Ollama on 11434, change only the first number (-L 21434:127.0.0.1:11434) and call http://127.0.0.1:21434. To close the tunnel, end that ssh process.
[3] If you must open it on the network, restrict the source first. Order matters: add the firewall rule, then change the listen address. With ufw on Ubuntu (format from the official docs, allowing a single device):
$ sudo ufw allow proto tcp from 192.0.2.25 to any port 11434$ sudo ufw status numberedThen give the Linux service the listen address. Add the following with systemctl edit ollama.service and reload (official FAQ):
[Service]Environment="OLLAMA_HOST=0.0.0.0:11434"$ sudo systemctl daemon-reload$ sudo systemctl restart ollamaTo undo, remove the line with systemctl edit ollama.service and run the same two commands. For the macOS app, run launchctl setenv OLLAMA_HOST "0.0.0.0:11434" and restart the app; on Windows, set it as a user or system environment variable and restart Ollama (FAQ). Finally, check both sides: curl http://<server address>:11434/api/version works from the allowed device and fails from any other.
[4] If Ollama runs in Docker, suspect -p 11434:11434. Docker's docs say a port published without an address is published "to all host addresses," and that published-port traffic is diverted before ufw rules apply, effectively ignoring your firewall configuration. The ufw rule from [3] doesn't protect the container.
$ docker run -d --name ollama -v ollama:/root/.ollama -p 127.0.0.1:11434:11434 ollama/ollamaPublish on loopback like this and come in from other devices through the tunnel in [2]. For container-to-container calls, see the table in Ollama 11434 connection refused.
[5] If a browser-based app on another origin calls Ollama, check OLLAMA_ORIGINS as well. Per the FAQ, cross-origin requests are allowed only from 127.0.0.1 and 0.0.0.0 by default; add other origins with this variable. Don't open it wholesale with * — add just that app's origin (for example http://app.example.com:3000).