HOW-TO · INF

How to configure the Ollama serve port for network access

intermediate10 minBy Fredoline Eruo
Target environment
Ubuntu 24.04 · Ollama 0.4.x
PREREQUISITES

Ollama installed, command-line terminal access, basic networking knowledge

What this does

Rebinds the Ollama API server from localhost-only to a network-accessible address and port. After this guide remote clients will be able to reach the Ollama API over the network.

Steps

  1. Set the OLLAMA_HOST environment variable and restart. Changes the bind address to accept external connections.

    export OLLAMA_HOST=0.0.0.0:11434
    ollama serve
    

    Expected output: Server starts, listening on all interfaces.

  2. Configure the systemd service to persist the change. Adds the environment variable to the unit file.

    sudo mkdir -p /etc/systemd/system/ollama.service.d
    sudo tee /etc/systemd/system/ollama.service.d/override.conf << 'EOF'
    [Service]
    Environment=OLLAMA_HOST=0.0.0.0:11434
    EOF
    sudo systemctl daemon-reload && sudo systemctl restart ollama
    
  3. Open the firewall port. Allows inbound TCP traffic on the Ollama port.

    sudo ufw allow 11434/tcp && sudo ufw reload
    

    Expected output: Rule added and Rules updated.

  4. Test remote access. Sends an API request from another machine to confirm the service is reachable.

    curl http://<server-ip>:11434/api/tags
    

    Expected output: A JSON array of available models.

Verification

curl -s http://localhost:11434/api/tags | python3 -m json.tool
# Expected: valid JSON with non-empty "models" array

Common failures

  • connection refused - Firewall blocking the port; verify with sudo ufw status or check cloud security groups.
  • address already in use - Another process is on port 11434; use sudo lsof -i :11434 to identify it.
  • OLLAMA_HOST not respected - The daemon may be started by systemd which ignores the shell export; always use the override.conf method for systemd setups.
  • model unreachable after config - Client is using an IP that the server is not bound to; verify with ss -tlnp | grep ollama.

Operator checkpoint

Before treating this as solved, write down the local runtime, model or package version, hardware/backend if relevant, and the verification output. This keeps the guide useful as a Will-It-Run style decision instead of a one-off command transcript.

Related guides

RELATED GUIDES