[GH-ISSUE #1157] [Linux] - Instructions for exposing Ollama doesn't work #586

Closed
opened 2026-04-12 10:17:16 -05:00 by GiteaMirror · 8 comments
Owner

Originally created by @SoloBSD on GitHub (Nov 16, 2023).
Original GitHub issue: https://github.com/ollama/ollama/issues/1157

Instructions for Linux on how to expose ollama doesn't work.

https://github.com/jmorganca/ollama/blob/main/docs/faq.md#how-can-i-expose-ollama-on-my-network

For some reason when Ollama gets installed on Linux it creates:
/etc/systemd/system/ollama.service

So it seems it never processes
/etc/systemd/system/ollama.service.d/environment.conf file

I tried to add:
Environment=OLLAMA_HOST=0.0.0.0:11434
under the [Service] section of /etc/systemd/system/ollama.service
but still doesn't take it.
There is already there an "Environment" statement which contains some paths. Didn't try to append the OLLAMA_HOST variable at the end, but created a new line down the existing one.

I only made it work issuing manually:
export OLLAMA_HOST=0.0.0.0:11434

Originally created by @SoloBSD on GitHub (Nov 16, 2023). Original GitHub issue: https://github.com/ollama/ollama/issues/1157 Instructions for Linux on how to expose ollama doesn't work. https://github.com/jmorganca/ollama/blob/main/docs/faq.md#how-can-i-expose-ollama-on-my-network For some reason when Ollama gets installed on Linux it creates: /etc/systemd/system/ollama.service So it seems it never processes /etc/systemd/system/ollama.service.d/environment.conf file I tried to add: Environment=OLLAMA_HOST=0.0.0.0:11434 under the [Service] section of /etc/systemd/system/ollama.service but still doesn't take it. There is already there an "Environment" statement which contains some paths. Didn't try to append the OLLAMA_HOST variable at the end, but created a new line down the existing one. I only made it work issuing manually: export OLLAMA_HOST=0.0.0.0:11434
Author
Owner

@mxyng commented on GitHub (Nov 16, 2023):

Did you run systemctl daemon-reload and systemctl restart ollama after creating the environment.conf file? Without these commands, systemd will not see the new configurations or restart ollama with the changes.

$ ss -tlnp | grep ollama
LISTEN 0      4096                                   127.0.0.1:11434      0.0.0.0:*    users:(("ollama",pid=7864,fd=3))
$ mkdir -p /etc/systemd/system/ollama.service.d
$ cat <<EOF >/etc/systemd/system/ollama.service.d/environment.conf
> [Service]
> Environment=OLLAMA_HOST=0.0.0.0
> EOF
$ ss -tlnp  | grep ollama
LISTEN 0      4096                                   127.0.0.1:11434      0.0.0.0:*    users:(("ollama",pid=7864,fd=3))
root@orac:/home/ollama# systemctl daemon-reload
root@orac:/home/ollama# systemctl restart ollama
root@orac:/home/ollama# ss -tlnp  | grep ollama
LISTEN 0      4096                                           *:11434            *:*    users:(("ollama",pid=7998,fd=3))

There is already there an "Environment" statement which contains some paths.

You can have multiple Environment statements in systemd service configurations.

<!-- gh-comment-id:1815370529 --> @mxyng commented on GitHub (Nov 16, 2023): Did you run `systemctl daemon-reload` and `systemctl restart ollama` after creating the `environment.conf` file? Without these commands, systemd will not see the new configurations or restart ollama with the changes. ``` $ ss -tlnp | grep ollama LISTEN 0 4096 127.0.0.1:11434 0.0.0.0:* users:(("ollama",pid=7864,fd=3)) $ mkdir -p /etc/systemd/system/ollama.service.d $ cat <<EOF >/etc/systemd/system/ollama.service.d/environment.conf > [Service] > Environment=OLLAMA_HOST=0.0.0.0 > EOF $ ss -tlnp | grep ollama LISTEN 0 4096 127.0.0.1:11434 0.0.0.0:* users:(("ollama",pid=7864,fd=3)) root@orac:/home/ollama# systemctl daemon-reload root@orac:/home/ollama# systemctl restart ollama root@orac:/home/ollama# ss -tlnp | grep ollama LISTEN 0 4096 *:11434 *:* users:(("ollama",pid=7998,fd=3)) ``` > There is already there an "Environment" statement which contains some paths. You can have multiple `Environment` statements in systemd service configurations.
Author
Owner

@SoloBSD commented on GitHub (Nov 16, 2023):

Yes I ran both commands and for some reason I don't get the variable exported.
Only if I do it manually.

<!-- gh-comment-id:1815512308 --> @SoloBSD commented on GitHub (Nov 16, 2023): Yes I ran both commands and for some reason I don't get the variable exported. Only if I do it manually.
Author
Owner

@mxyng commented on GitHub (Nov 17, 2023):

What does systemctl cat ollama return? It will display the merged configuration. If Environment=OLLAMA_HOST is not in the outputs, it hasn't been configured correctly

<!-- gh-comment-id:1815548117 --> @mxyng commented on GitHub (Nov 17, 2023): What does `systemctl cat ollama` return? It will display the merged configuration. If `Environment=OLLAMA_HOST` is not in the outputs, it hasn't been configured correctly
Author
Owner

@johnm-starling commented on GitHub (Nov 17, 2023):

Instructions for Configuring the ollama Service in Ubuntu

Note: These instructions have been tested on Ubuntu variants.

  1. Edit Service Configuration

    • Run the following command to edit the service configuration:
      sudo systemctl edit ollama.service
      
    • This command opens an editor for the ollama.service.d/override.conf file.
  2. Add Environment Variables

    • In the opened editor, add the following lines under the [Service] section:
      [Service]
      Environment="OLLAMA_HOST=0.0.0.0:11434"
      Environment="OLLAMA_ORIGINS='*'"
      
    • Important: Do not omit the quotes around the environment variable values.
  3. Effect of Configuration

    • These settings will configure the ollama service to listen on all interfaces on port 11434 and allow connections from any IP.
  4. Reload and Restart Service

    • After editing the configuration, reload the systemd daemon and restart the ollama service:
      sudo systemctl daemon-reload
      sudo systemctl restart ollama.service
      
  5. Verify Service Status

    • To check that the service is using the additional configuration file:
      sudo systemctl status ollama.service
      
  6. Check Open Ports

    • Use the following command to view open ports and confirm if port 11434 is listening for communications:
      sudo ss -tuln
      
    • You should see port 11434 open and ready for communications on any interface and to any remote IP.

I have just tested this on my Ubuntu 23.10.1 but have also done the same in 22.04 variants including PopOS!.

<!-- gh-comment-id:1815550029 --> @johnm-starling commented on GitHub (Nov 17, 2023): **Instructions for Configuring the `ollama` Service in Ubuntu** *Note: These instructions have been tested on Ubuntu variants.* 1. **Edit Service Configuration** - Run the following command to edit the service configuration: ```bash sudo systemctl edit ollama.service ``` - This command opens an editor for the `ollama.service.d/override.conf` file. 2. **Add Environment Variables** - In the opened editor, add the following lines under the `[Service]` section: ```ini [Service] Environment="OLLAMA_HOST=0.0.0.0:11434" Environment="OLLAMA_ORIGINS='*'" ``` - *Important:* Do not omit the quotes around the environment variable values. 3. **Effect of Configuration** - These settings will configure the `ollama` service to listen on all interfaces on port 11434 and allow connections from any IP. 4. **Reload and Restart Service** - After editing the configuration, reload the systemd daemon and restart the `ollama` service: ```bash sudo systemctl daemon-reload sudo systemctl restart ollama.service ``` 5. **Verify Service Status** - To check that the service is using the additional configuration file: ```bash sudo systemctl status ollama.service ``` 6. **Check Open Ports** - Use the following command to view open ports and confirm if port 11434 is listening for communications: ```bash sudo ss -tuln ``` - You should see port 11434 open and ready for communications on any interface and to any remote IP. --- I have just tested this on my Ubuntu 23.10.1 but have also done the same in 22.04 variants including PopOS!.
Author
Owner

@mxyng commented on GitHub (Nov 17, 2023):

Yes, those are the instructions described in the FAQ

<!-- gh-comment-id:1815551354 --> @mxyng commented on GitHub (Nov 17, 2023): Yes, those are the instructions described in the [FAQ](https://github.com/jmorganca/ollama/blob/main/docs/faq.md#how-can-i-expose-ollama-on-my-network)
Author
Owner

@johnm-starling commented on GitHub (Nov 17, 2023):

The Environment statements are echo'd differently between the FAQ and what I have posted. I wrap my Environment assignment in quotes per this document.

https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html#Environment=

"If you need to assign a value containing spaces or the equals sign to a variable, put quotes around the whole assignment. "

Environment="VAR1=word1 word2" VAR2=word3 "VAR3=$word 5 6"

<!-- gh-comment-id:1815558910 --> @johnm-starling commented on GitHub (Nov 17, 2023): The Environment statements are echo'd differently between the FAQ and what I have posted. I wrap my Environment assignment in quotes per this document. https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html#Environment= "If you need to assign a value containing spaces or the equals sign to a variable, put quotes around the whole assignment. " Environment="VAR1=word1 word2" VAR2=word3 "VAR3=$word 5 6"
Author
Owner

@SoloBSD commented on GitHub (Nov 17, 2023):

Hi, yeah,
Seems that the quotes are making the magic.
Now it is working.
Thanks!

<!-- gh-comment-id:1815565831 --> @SoloBSD commented on GitHub (Nov 17, 2023): Hi, yeah, Seems that the quotes are making the magic. Now it is working. Thanks!
Author
Owner

@mxyng commented on GitHub (Nov 17, 2023):

Good call. Updated the FAQ

<!-- gh-comment-id:1815576884 --> @mxyng commented on GitHub (Nov 17, 2023): Good call. Updated the FAQ
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#586