A llama.cpp server listener decides which clients can reach the API and web UI. Explicit host and port settings keep a local service on loopback and avoid a port already used by another application.
llama-server reads its listener settings at startup. A loopback address accepts connections only within the same machine or container network namespace, while an address on a network interface accepts traffic arriving through that interface. Clients need the new port in their URLs after a listener change.
A network-facing listener can expose prompts, responses, and inference capacity to other machines. Remote access needs network restrictions, authentication, and TLS before exposure; an API key does not encrypt HTTP or replace network restrictions. A same-machine reverse proxy can connect to a loopback listener without making the model server itself network-facing.
Steps to set llama.cpp server host and port:
- Choose 127.0.0.1 and an unused TCP port for a same-machine listener.
Port 9091 keeps this listener separate from services using 8080. The bind address belongs to the server; it is not the client's address. A specific interface address must exist on the server. Loopback is the appropriate choice when only local clients or a same-machine proxy need access.
- Start llama-server on loopback port 9091 with the local model.
$ llama-server -m models/chat-model.gguf \ --host 127.0.0.1 --port 9091 ##### snipped ##### 0.00.809.112 I srv server_run_i: model loaded 0.00.809.127 I srv server_on_li: listening on http://127.0.0.1:9091
This assumes llama-server is installed and models/chat-model.gguf is an existing chat GGUF. The listening on line must show 127.0.0.1:9091. Listener flags take effect at process startup; changing them requires restarting that process. Ctrl+C stops a foreground server so it can be restarted with different values. An occupied port causes startup to fail rather than moving the listener to another port.
Related: How to start the llama.cpp server - Test the loopback restriction from a second machine using the server's network hostname.
$ curl --noproxy '*' --connect-timeout 3 --max-time 5 \ --fail --silent --show-error http://server.example.net:9091/health curl: (7) Failed to connect to server.example.net port 9091 after 2 ms: Couldn't connect to server
server.example.net stands for a hostname resolving to the server's network address, not 127.0.0.1. The request must fail to connect for a loopback listener. A returned HTTP response means a service is reachable through that address and needs investigation. A timeout alone does not identify the bind address because routing or firewall rules can also block traffic.
- Request the health endpoint locally through port 9091 from another terminal.
$ curl --noproxy '*' --fail --silent --show-error \ http://127.0.0.1:9091/health {"status":"ok"}
The local response, the listener address in the startup log, and the failed remote connection together distinguish a working loopback service from an unreachable server. The process remains available at http://127.0.0.1:9091. Health checks listener access and service readiness; model inference has its own API check.
Related: How to check llama.cpp server health
Related: How to call the llama.cpp chat completions API