太多Ollama API端口暴露着,公网竟然可直接访问到
Ollama因简单易用,目前算是本地化运行AI大模型的入门级工具,而且兼容OpenAI API标准,对于喜欢折腾和拥抱AI的用户来说绝对是入门必备良品。
今天不讲如何使用,毕竟各位在本地化知识库已经是用的相当熟练了,好,不多说,先上个图了解下今天要说的重点:
啥?
Ollama的11434端口都直接暴露在公网啦?
你看到的没错,只是简单的扫描了几个段,发现了40几个Ollama直接可公网访问的情况,令人兴奋的是发现了里面居然有满血版671b的模型:
试了下能否体验下DeepSeek满血版,不过结局并不是很美好
估计本身硬件跑不起来,用户只是下载了671b模型,不过这样也相当于验证了671b模型实际需要的资源情况:至少需要462G内存哟!
其他几十个中发现真正能跑起来70b的只有一个,大部分都是只能跑7b,甚至1.5b。
也许有人并不在乎吧,我就愿意暴露在公网上,那咋了!别人想用就来用呗。
既然Ollama兼容OpenAI标准,其自身也是提供了很多API接口,先拿自身小试牛刀
命令行cli方式先看看本地已有的模型,我本地太多模型了,都是体验,大多没用到。
$ ollama list
NAME ID SIZE MODIFIED
gemma3:4b c0494fe00251 3.3 GB 3 weeks ago
phi4:latest ac896e5b8b34 9.1 GB 4 weeks ago
mistral:7b-instruct f974a74358d6 4.1 GB 4 weeks ago
linux6200/bge-reranker-v2-m3:latest abf5c6d8bc56 1.2 GB 5 weeks ago
bge-m3:latest 790764642607 1.2 GB 5 weeks ago
deepseek-r1:8b 28f8fd6cdc67 4.9 GB 5 weeks ago
deepseek-r1:aiops-base-1.5b-qwen-distill 52c3bcd11373 3.6 GB 6 weeks ago
qwen2:0.5b 6f48b936a09f 352 MB 6 weeks ago
nomic-embed-text:latest 0a109f422b47 274 MB 8 weeks ago
catllama:latest bc211880059f 4.7 GB 8 weeks ago
deepseek-r1:1.5b-qwen-distill-q8_0 be5781997fd9 1.9 GB 2 months ago
qwen2.5-coder:latest 2b0496514337 4.7 GB 4 months ago
incept5/llama3.1-claude:latest 295f2522647f 4.7 GB 5 months ago
codegeex4:latest 867b8e81d038 5.5 GB 5 months ago
codegemma:7b 0c96700aaada 5.0 GB 5 months ago
deepseek-coder:6.7b ce298d984115 3.8 GB 5 months ago
codellama:7b-instruct 8fdf8f752f6e 3.8 GB 5 months ago
brxce/stable-diffusion-prompt-generator:latest 474a09318a2e 4.1 GB 5 months ago
llava:7b 8dd30f6b0cb1 4.7 GB 5 months ago
codeqwen:7b df352abf55b1 4.2 GB 5 months ago
gemma:7b a72c7f4d0a15 5.0 GB 5 months ago
qwen2.5:7b 845dbda0ea48 4.7 GB 5 months ago
llama3:latest a6990ed6be41 4.7 GB 11 months ago
curl http://127.0.0.1:11434/
返回:
Ollama is running
http://127.0.0.1:11434/api/tags
返回当前模型列表
使用python脚本测试API
$ cat get-model-name-via-api.py
import requests
# 发送 GET 请求到 API 端点
response = requests.get("http://localhost:11434/api/tags")
# 解析响应数据
if response.status_code == 200:
models = response.json()['models']
for model in models:
print(f"模型: {model['name']} | 参数大小: {model['details']['parameter_size']}")
else:
print(f"请求失败,状态码: {response.status_code}")
$ python get-model-name-via-api.py
模型: gemma3:4b | 参数大小: 4.3B
模型: phi4:latest | 参数大小: 14.7B
模型: mistral:7b-instruct | 参数大小: 7.2B
模型:
linux6200/bge-reranker-v2-m3:latest | 参数大小: 567.75M模型: bge-m3:latest | 参数大小: 566.70M
模型: deepseek-r1:8b | 参数大小: 8.0B
模型:
deepseek-r1:aiops-base-1.5b-qwen-distill | 参数大小: 1.8B模型: qwen2:0.5b | 参数大小: 494.03M
模型: nomic-embed-text:latest | 参数大小: 137M
模型: catllama:latest | 参数大小: 8.0B
模型:
deepseek-r1:1.5b-qwen-distill-q8_0 | 参数大小: 1.8B模型: qwen2.5-coder:latest | 参数大小: 7.6B
模型:
incept5/llama3.1-claude:latest | 参数大小: 8.0B模型: codegeex4:latest | 参数大小: 9.4B
模型: codegemma:7b | 参数大小: 9B
模型: deepseek-coder:6.7b | 参数大小: 7B
模型: codellama:7b-instruct | 参数大小: 7B
模型:
brxce/stable-diffusion-prompt-generator:latest | 参数大小: 7B模型: llava:7b | 参数大小: 7B
模型: codeqwen:7b | 参数大小: 7.3B
模型: gemma:7b | 参数大小: 9B
模型: qwen2.5:7b | 参数大小: 7.6B
模型: llama3:latest | 参数大小: 8B
下面重点介绍如何给Ollama增加api token认证
最简单的就是使用Nginx作为反向代理,增加Authorization header。
本例是让Nginx监听11444端口,同时将请求反向代理给了ollama提供的API接口地址:127.0.0.0:11434
Nginx配置如下:
cat /etc/nginx/sites-enabled/ollama.conf
# Default server configuration
#
server {
listen 11444;
server_name _;
location / {
if ($http_Authorization != "Bearer API1234567890") {
return 403 'Api Key incorrect.';
}
proxy_pass http://127.0.0.1:11434/;
}
}
增加了认证之后,如果按照之前正常的访问,会得到http code 403,并且页面收到“Api Key incorrect.”的提示。
使用curl测试:不带API的header请求
curl http://127.0.0.1:11444/
使用带Authorization header的请求
curl -H "Authorization: Bearer API1234567890" http://127.0.0.1:11444/
使用python脚本测试,在request请求中增加Authorization header。
headers = {
'Authorization': 'Bearer API1234567890',
'X-Custom-Header': 'Ollama-header'
}
另外的一个发现就是在暴露11434端口的服务器上,有一半的几率会在80端口启动着Dify或者Ragflow
看来AI本地知识库还是火的可以,只是在安全上还是需要注意下,比如增加IP白名单及添加API认证等,让别人在你GPU机器上一直跑着大模型你能忍?
(全文完)