优选自定义host

使用 Cloudflare Workers 和公共 DNS API 智能优选域名 IP

🟢 服务正常运行
Hosts 文件
API 文档
使用帮助

📋 当前 Hosts 内容(已启用IP优选和自定义域名)

使用缓存数据,每小时自动更新 缓存状态:加载中...
Hosts 文件内容
正在加载 hosts 内容...

📥 快速使用方法

SwitchHosts 工具

推荐使用,可自动更新

  • URL: 加载中...
  • 更新间隔:1小时

命令行工具

一键安装和更新

curl -fsSL https://github.com/Yan-nian/custom-host/releases/download/v1.0.0/install.sh | sudo bash

🔧 API 接口文档

基础接口

接口 方法 参数 描述
/hosts GET refresh=[true|false], custom=[true|false] 获取 hosts 文件内容,支持强制刷新缓存
/hosts.json GET refresh=[true|false] 获取 JSON 格式的域名数据,包含统计信息
/{domain} GET - 获取指定域名的实时 DNS 解析结果

管理接口

接口 方法 描述
/api/custom-domains GET 获取自定义域名列表
/api/custom-domains POST 添加自定义域名,需要提供domain字段,可选description字段
/api/custom-domains/batch POST 批量添加自定义域名,需要提供domains数组,每个元素包含domain字段
/api/custom-domains/{domain} DELETE 删除指定的自定义域名
/api/custom-domains DELETE 清空所有自定义域名
/api/optimize/{domain} POST 优选指定域名的 IP 地址
/api/optimize-all POST 优选所有自定义域名的 IP 地址(需要 API Key 或管理后台访问)
/api/cache/status GET 查看缓存状态和统计信息
/api/cache/refresh POST 手动刷新 GitHub 域名缓存(需要 API Key 或管理后台访问)
/api/cache DELETE 清空所有缓存数据(需要 API Key 或管理后台访问)
/api/reset POST 清空缓存并重新获取GitHub域名数据

系统配置接口

接口 方法 描述
/api/system/config GET 获取系统配置信息(需要管理后台访问)
/api/system/api-key PUT 更新 API Key(需要管理后台访问)

调试接口

接口 方法 描述
/test-custom-domains GET 测试所有自定义域名的解析状态
/debug GET 获取系统调试信息和域名统计

� 使用帮助

💻 命令行工具

MacOS 用户

sudo curl -fsSL https://github.com/Yan-nian/custom-host/releases/download/v1.0.0/custom-hosts.darwin-arm64 -o custom-hosts && sudo chmod +x ./custom-hosts && ./custom-hosts

Windows 用户

在管理员权限的 PowerShell 中执行:

irm https://github.com/Yan-nian/custom-host/releases/download/v1.0.0/custom-hosts.windows-amd64.exe | iex

Linux 用户

sudo curl -fsSL https://github.com/Yan-nian/custom-host/releases/download/v1.0.0/custom-hosts.linux-amd64 -o custom-hosts && sudo chmod +x ./custom-hosts && ./custom-hosts

🛠️ 手动更新

  1. 获取 hosts 内容并复制
  2. 编辑本地 hosts 文件:
    • Windows:C:\Windows\System32\drivers\etc\hosts
    • MacOS/Linux:/etc/hosts
  3. 粘贴内容并保存
  4. 刷新 DNS 缓存:
    • Windows:ipconfig /flushdns
    • MacOS:sudo killall -HUP mDNSResponder
    • Linux:sudo systemd-resolve --flush-caches

❓ 常见问题

权限问题

IP 优选说明

自定义域名功能

API 使用示例

管理 API(需要验证)

注意:管理类 API 需要通过管理后台访问,或使用 API Key 验证。管理后台地址在部署时配置。

主页刷新专用 API Key

特殊功能:主页刷新按钮使用限制权限的特殊 API Key。