Skip to content

masx200/deno-dns-over-https-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

deno-dns-over-https-server

deno-dns-over-https-server

使用方法

将需要反向代理的 dns over https 网址设定为环境变量 doh,

将需要反向代理的最小缓存时间(秒)设定为环境变量 ttl,

启动

npx -y cross-env "doh=https://dns.alidns.com/dns-query" 'ttl=180' token=token deno run --unstable -A ./main.tsx

访问http://localhost:8000/dns-query使用 dns over https

也可以设置doh环境变量为一个json数组,使用负载均衡

例如设置 doh["https://doh.pub/dns-query","https://security.cloudflare-dns.com/dns-query"]

添加了负载均衡的故障转移功能和校验 dns 数据包格式的功能

设置 doh 服务的路径通过环境变量DOH_PATHNAME为 "/dns-query"

环境变量

| 环境变量                   | 说明                                                  | 类型                               |
| -------------------------- | ----------------------------------------------------- | ---------------------------------- |
| `doh`                      | 上游 dnsover https 网址                               | `string` 或 `string[]`(JSON)       |
| `ttl`                      | 最小缓存时间(秒)                                      | `number`                           |
| `DOH_PATHNAME`             | 这个 dns over https 服务的路径                        | `string`                           |
| `token`                    | dns 记录管理的秘钥                                    | `string`                           |
| `mongodb_url`              | mongodb 数据库地址                                    | `string`                           |
| `mongodb_db`               | mongodb 数据库名称                                    | `string`                           |
| `mongodb_collection`       | mongodb 数据库集合名称                                | `string`                           |
| `DNS_INTERCEPTOR`          | 拦截 dns 请求的参数数组                               | `Array<{suffix: string;url: string|string[]}` |
| `DNS_INTERCEPTOR`.`url`    | 上游服务器 url 支持 udp 和 tcp 协议和 http/https 协议 | `string` 或 `string[]`             |
| `DNS_INTERCEPTOR`.`suffix` | suffix是域名后缀,开头不包含"."                        | `string`                           |

dns 记录说明

为了 dns 负载均衡,可以对 dns 记录随机排序

dns 记录默认保存在内存中,配置文件为config.ts,

数据保存方式可以使用mongodb数据库,

配置环境变量mongodb_url,mongodb_db,mongodb_collection

设置域名与地址的映射关系即可,支持多个地址

接口格式为JSONRPC 2.0

访问http://localhost:8000/dns_records使用 ddns

设置token环境变量为访问秘钥 token 即可使用 ddns

访问时需要携带token参数,例如

添加请求头Authorization:Bearer token

openapi 接口在文件deno-dns-over-https-server.openapi.json

jsonrpc 接口在文件DNSRecordsInterface.ts

可以使用客户端 deno-ddns-over-https-client 进行访问 ddns 服务

jsonrpc的调用的例子在文件夹dns_records

删除 deno deploy 上的 kv 数据

设置环境变量DENO_KV_ACCESS_TOKEN=****************************************

npx -y cross-env  "DENO_KV_ACCESS_TOKEN=****************************************" deno repl -A --unstable-kv
var kv = await Deno.openKv(
    "https://api.deno.com/databases/************************************/connect",
);
for await (const entry of kv.list({ prefix: [] })) {
    console.log(entry);
    kv.delete(entry.key).then(console.log, console.error);
}

导出所有本地的系统 hosts 文件为 json 格式

deno cache -I getHostEntry.ts
deno run -A getHostEntry.ts >hosts.log
deno run -A getHostEntry.ts --o=hosts.log