idot : DNS over TLS Client for Rust
Based on idns. See idns for DnsRace, Cache, Parse trait, and more.
Features
- RFC 7858 compliant DoT implementation
- Built-in DoT server list (Cloudflare, Google, Quad9, Alibaba DNS)
- Async/await with Tokio
- TLS 1.3
- A, AAAA, MX, TXT, NS, CNAME, PTR, SRV record types
- Connection reuse
- 9s timeout
Installation
[]
= "0.1"
= "0.1"
Usage
DnsRace + Cache (Recommended)
Race multiple servers and cache results:
use ;
use ;
use Instant;
async
Basic Query
use ;
use Query;
async
Custom Server
use ;
use Query;
async
API Reference
Structs
Dot
DoT client with connection reuse. Implements idns::Query trait.
HostIp
Server configuration with host: SmolStr (TLS SNI) and ip: IpAddr.
Functions
host_ip(host, a, b, c, d) -> HostIp- Create HostIp from hostname and IPv4dot_li(li: &[HostIp]) -> Vec<Dot>- Create Dot clients from HostIp list
Constants
DOT_LI
Pre-configured DoT servers:
| Server | IP |
|---|---|
| Cloudflare | 1.1.1.1, 1.0.0.1 |
| 8.8.8.8, 8.8.4.4 | |
| Quad9 | 9.9.9.9 |
| 360 DNS (China) | 101.226.4.6, 218.30.118.6 |
| TWNIC (Taiwan) | 101.101.101.101 |
| IIJ DNS (Japan) | 103.2.57.5 |
dns module
Server hostname constants:
dns::CLOUDFLARE-"cloudflare-dns.com"dns::GOOGLE-"dns.google"dns::QUAD9-"dns.quad9.net"dns::DNS360-"dot.360.cn"dns::TWNIC-"101.101.101.101"dns::IIJ-"public.dns.iij.jp"dns::ALIDNS-"dns.alidns.com"(disabled: incomplete TXT records)dns::DNSPOD-"dot.pub"(disabled: connection issues)
Architecture
graph TD
A[Client] --> B[Dot.query]
B --> C[conn]
C --> D{Has conn?}
D -->|Yes| E[Take]
D -->|No| F[dial]
F --> G[TCP + TLS 1.3]
G --> I[TlsStream]
E --> J[send]
I --> J
J --> K[DNS Message]
K --> L[Response]
L --> M[Parse]
M --> N[Answers]
N --> O[return_conn]
Implementation Details
- Random DNS message ID (verified on response)
- 2-byte length prefix for framing (RFC 7858)
- EDNS OPT with 4096 byte payload
LazyLockfor TLSClientConfigRwLock<Option<TlsStream>>for connection reuse- TCP_NODELAY enabled
- 9s timeout
Tech Stack
| Component | Library |
|---|---|
| TLS | rustls + tokio-rustls |
| Async | tokio |
| Buffer | bytes |
| Error | thiserror |
| DNS Parse | dns_parse |
DoT vs DoQ
| Feature | DoT (idot) | DoQ (idoq) |
|---|---|---|
| Protocol | TCP + TLS | QUIC |
| Port | 853 | 853 |
| Multiplexing | No | Yes |
| 0-RTT | No | Yes |
| Head-of-line blocking | Yes | No |
| Maturity | High | Medium |
About
This project is an open-source component of js0.site ⋅ Refactoring the Internet Plan.
We are redefining the development paradigm of the Internet in a componentized way. Welcome to follow us:
idot : Rust DNS over TLS 客户端
基于 idns。DnsRace、Cache、Parse trait 等更多功能请查看 idns。
特性
- 符合 RFC 7858 的 DoT 实现
- 内置 DoT 服务器列表 (Cloudflare、Google、Quad9、阿里 DNS)
- 基于 Tokio 异步
- TLS 1.3
- 支持 A、AAAA、MX、TXT、NS、CNAME、PTR、SRV 记录
- 连接复用
- 9 秒超时
安装
[]
= "0.1"
= "0.1"
使用
DnsRace + Cache(推荐)
竞速查询多个服务器并缓存结果:
use ;
use ;
use Instant;
async
基本查询
use ;
use Query;
async
自定义服务器
use ;
use Query;
async
API 参考
结构体
Dot
DoT 客户端,支持连接复用。实现 idns::Query trait。
HostIp
服务器配置,包含 host: SmolStr(TLS SNI)和 ip: IpAddr。
函数
host_ip(host, a, b, c, d) -> HostIp- 从主机名和 IPv4 创建 HostIpdot_li(li: &[HostIp]) -> Vec<Dot>- 从 HostIp 列表创建 Dot 客户端
常量
DOT_LI
预配置 DoT 服务器:
| 服务器 | IP |
|---|---|
| Cloudflare | 1.1.1.1, 1.0.0.1 |
| 8.8.8.8, 8.8.4.4 | |
| Quad9 | 9.9.9.9 |
| 360 DNS(中国) | 101.226.4.6, 218.30.118.6 |
| TWNIC(台湾) | 101.101.101.101 |
| IIJ DNS(日本) | 103.2.57.5 |
dns 模块
服务器主机名常量:
dns::CLOUDFLARE-"cloudflare-dns.com"dns::GOOGLE-"dns.google"dns::QUAD9-"dns.quad9.net"dns::DNS360-"dot.360.cn"dns::TWNIC-"101.101.101.101"dns::IIJ-"public.dns.iij.jp"dns::ALIDNS-"dns.alidns.com"(已禁用:TXT 记录不完整)dns::DNSPOD-"dot.pub"(已禁用:连接问题)
架构
graph TD
A[客户端] --> B[Dot.query]
B --> C[conn]
C --> D{有连接?}
D -->|是| E[取出]
D -->|否| F[dial]
F --> G[TCP + TLS 1.3]
G --> I[TlsStream]
E --> J[send]
I --> J
J --> K[DNS 消息]
K --> L[响应]
L --> M[解析]
M --> N[应答]
N --> O[return_conn]
实现细节
- 随机 DNS 消息 ID(响应时验证)
- 2 字节长度前缀分帧 (RFC 7858)
- EDNS OPT 4096 字节负载
LazyLock延迟初始化 TLSClientConfigRwLock<Option<TlsStream>>连接复用- 启用 TCP_NODELAY
- 9 秒超时
技术栈
| 组件 | 库 |
|---|---|
| TLS | rustls + tokio-rustls |
| 异步 | tokio |
| 缓冲 | bytes |
| 错误 | thiserror |
| DNS 解析 | dns_parse |
DoT vs DoQ
| 特性 | DoT (idot) | DoQ (idoq) |
|---|---|---|
| 协议 | TCP + TLS | QUIC |
| 端口 | 853 | 853 |
| 多路复用 | 否 | 是 |
| 0-RTT | 否 | 是 |
| 队头阻塞 | 是 | 否 |
| 成熟度 | 高 | 中 |
关于
本项目为 js0.site ⋅ 重构互联网计划 的开源组件。
我们正在以组件化的方式重新定义互联网的开发范式,欢迎关注: