SaferComputing.com

Reference · Local AI servers

Port 11434: check whether Ollama is exposed to the network

Check whether Ollama's API on port 11434 listens on 0.0.0.0, pin it to 127.0.0.1 with OLLAMA_HOST on Windows 11, macOS and a Linux systemd override, and block the port in the firewall.

Published
Updated
Last checked
Applies to
Ollama on Windows 11, macOS and Linux, including Docker
Technical specification
Target artifactThe Ollama REST API on TCP port 11434, set by the OLLAMA_HOST environment variable and the app's Expose Ollama to the network setting.
Default behaviourListens on 127.0.0.1:11434, this computer only. The API has no authentication, so once it listens on 0.0.0.0 anyone who can reach the port can run, pull and delete models.
Safe stateListening on 127.0.0.1:11434 or [::1]:11434 only; Expose Ollama to the network off; no OLLAMA_HOST=0.0.0.0 anywhere; Ollama 0.35.0 or later.
Check on WindowsGet-NetTCPConnection -State Listen -LocalPort 11434 | Select-Object LocalAddress, LocalPort, OwningProcess
Check on Linuxsudo ss -tlnp | grep 11434
Check on macOSsudo lsof -nP -iTCP:11434 -sTCP:LISTEN
Check from another devicecurl --max-time 5 http://SERVER_IP:11434/api/version
Fix on Windows[Environment]::SetEnvironmentVariable('OLLAMA_HOST', '127.0.0.1:11434', 'User'), then quit and restart Ollama
Fix on Linuxsudo systemctl edit ollama.service and add Environment="OLLAMA_HOST=127.0.0.1:11434" under [Service]
Fix on macOSlaunchctl unsetenv OLLAMA_HOST, then quit and reopen Ollama
Fix in Dockerpublish with -p 127.0.0.1:11434:11434, never -p 11434:11434

Read the result

Listening addressWho can reach the API
127.0.0.1:11434 or [::1]:11434This computer only
0.0.0.0:11434, *:11434 or [::]:11434Every network interface: Wi-Fi, Ethernet and any VPN
A network address, such as 192.168.1.20:11434Anyone who can reach that network

The listening address shows what Ollama asked for; the test from a second device shows what the network allows. A JSON reply with a version number means the API is reachable from that device. "Connection refused" or a timeout means it is not. In Windows PowerShell, type curl.exe rather than curl, which is an alias for Invoke-WebRequest there.

Exposed servers are found quickly: in a study published in January 2026, SentinelLABS and Censys counted 175,108 unique Ollama hosts answering on the public internet over 293 days of scanning.

Pin Ollama to 127.0.0.1

Ollama binds to 127.0.0.1:11434 unless OLLAMA_HOST says otherwise, so the fix is to find what set it and set it back.

Windows 11
  1. In the Ollama app's settings, turn off Expose Ollama to the network. It is off by default.
  2. Look for the variable in both scopes:
Windows PowerShell
[Environment]::GetEnvironmentVariable('OLLAMA_HOST', 'User')
[Environment]::GetEnvironmentVariable('OLLAMA_HOST', 'Machine')
  1. Pin it to the loopback address, and clear a machine-wide value if the second line printed one. The second command needs PowerShell opened with Run as administrator:
Windows PowerShell
[Environment]::SetEnvironmentVariable('OLLAMA_HOST', '127.0.0.1:11434', 'User')
[Environment]::SetEnvironmentVariable('OLLAMA_HOST', $null, 'Machine')
  1. Quit Ollama from its taskbar icon, start it again from the Start menu, and run the check again. Ollama reads the variables only when it starts.
Linux with systemd (the official installer)
Linux, as a user with sudo
systemctl cat ollama.service | grep -n OLLAMA_HOST
sudo systemctl edit ollama.service

In the editor that opens, add these lines, then save and close it. They are stored in /etc/systemd/system/ollama.service.d/override.conf:

Lines to add in the override file
[Service]
Environment="OLLAMA_HOST=127.0.0.1:11434"

If systemctl cat showed another file setting OLLAMA_HOST=0.0.0.0, remove that line too. Then reload, restart and check:

Linux, as a user with sudo
sudo systemctl daemon-reload
sudo systemctl restart ollama
sudo ss -tlnp | grep 11434
macOS

Turn off Expose Ollama to the network in the Ollama app's settings. Then look for a value set through launchctl, and clear it:

macOS Terminal
launchctl getenv OLLAMA_HOST
launchctl unsetenv OLLAMA_HOST

Quit and reopen Ollama. If the value comes back after you sign in again, something sets it at login; search your launch agents for it:

macOS Terminal
grep -rl OLLAMA_HOST ~/Library/LaunchAgents 2>/dev/null
Docker

Ollama's image sets OLLAMA_HOST=0.0.0.0 inside the container; that is expected. What matters is the host side of the published port:

Linux, as a user in the docker group
docker ps --format 'table {{.Names}}\t{{.Ports}}'

0.0.0.0:11434->11434/tcp means every interface. Recreate the container on the loopback address; the named volume keeps the downloaded models:

Linux, as a user in the docker group
docker stop ollama && docker rm ollama
docker run -d -v ollama:/root/.ollama -p 127.0.0.1:11434:11434 --name ollama ollama/ollama

On Docker Engine releases older than 28.0.0, other hosts on the same local network segment could still reach ports published to 127.0.0.1. Check with docker version.

Block the port as a second layer

Binding to 127.0.0.1 is the fix. A firewall rule catches the day someone turns the network setting back on.

Windows Defender Firewall
Windows PowerShell, as Administrator
New-NetFirewallRule -DisplayName 'Block inbound Ollama 11434' -Direction Inbound -Protocol TCP -LocalPort 11434 -Action Block

An explicit block rule takes precedence over any conflicting allow rule, including one created when someone clicked Allow at Windows' first-run prompt.

Ubuntu with UFW

UFW uses the first rule that matches, so insert the block at the top:

Ubuntu, as a user with sudo
sudo ufw status numbered
sudo ufw insert 1 deny 11434/tcp

If the numbered list is empty, ufw insert answers ERROR: Invalid position '1'; run sudo ufw deny 11434/tcp instead.

If one other computer genuinely needs the API, delete the deny rule and allow that address alone with sudo ufw allow from 192.168.1.50 to any port 11434 proto tcp. Ports published by Docker bypass UFW; see Docker published ports.

macOS

The macOS firewall decides per application, not per port, so there is no port rule to add. Keep Ollama on 127.0.0.1.

Troubleshooting

The check still shows 0.0.0.0 after the change
  • Ollama was not restarted. It reads OLLAMA_HOST at start-up only.
  • On Linux, another drop-in file sets the variable after yours. systemctl cat ollama.service prints every file in the order systemd reads them.
  • On Windows, a machine-wide value needs an Administrator PowerShell to clear, and the app setting can turn exposure back on.
  • In Docker, read the docker ps port column, not the variable inside the container.
The test from another device still connects
  • Another program is listening on the port. On Windows, the OwningProcess number in the check is the process ID; Get-Process -Id NUMBER names it. On Linux, ss -p shows the process name.
  • A reverse proxy such as nginx or Caddy forwards another port to 127.0.0.1:11434. Check its configuration.
  • The device tested over IPv6. If Ollama listens on [::], a router's IPv6 firewall may let traffic in even though IPv4 address sharing hides the computer.
Which Ollama version is safe

Run ollama --version. Version 0.35.0 fixes CVE-2026-103663, a path traversal in /api/pull that writes files outside the model store; versions 0.34.2 and later before 0.35.0 are affected. The CVE record adds that where the server can write to /usr/lib/ollama, the default in most of Ollama's Docker images, the planted file runs as root at the next restart.

Sources