Skip to content

Instantly share code, notes, and snippets.

@tmabraham
Created October 28, 2024 01:14
Show Gist options
  • Save tmabraham/653cb82af87f44f7554738a724e1ad97 to your computer and use it in GitHub Desktop.
Save tmabraham/653cb82af87f44f7554738a724e1ad97 to your computer and use it in GitHub Desktop.
Making Ollama API Publicly Accessible

Making Ollama API Publicly Accessible

This guide shows how to configure Ollama to accept connections from any IP address instead of just localhost.

1. Check Current Status

Check if Ollama is currently listening only on localhost:

ss -tulpn | grep 11434

If you see 127.0.0.1:11434, it's only accessible locally.

2. Configure Ollama to Listen on All Interfaces

# Stop Ollama service
sudo systemctl stop ollama

# Create override directory
sudo mkdir -p /etc/systemd/system/ollama.service.d

# Create override configuration
sudo nano /etc/systemd/system/ollama.service.d/override.conf

Add these lines to override.conf:

[Service]
Environment="OLLAMA_HOST=0.0.0.0"

3. Apply Changes

# Reload systemd configuration
sudo systemctl daemon-reload

# Restart Ollama
sudo systemctl restart ollama

4. Verify Configuration

ss -tulpn | grep 11434

You should see *:11434 or 0.0.0.0:11434, indicating it's listening on all interfaces.

5. Configure Firewall

Allow incoming traffic to port 11434:

sudo ufw allow 11434/tcp

Additional Notes

  • If using a cloud provider (AWS, DigitalOcean, etc.), ensure your security groups/network rules allow inbound traffic on port 11434
  • Test the connection from another machine:
    curl http://YOUR_SERVER_IP:11434/api/tags
  • Consider implementing additional security measures like authentication or IP whitelisting for production use
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment