5个不稳定版本
0.25.0-alpha.2 | 2024年8月6日 |
---|---|
0.25.0-alpha.1 | 2024年6月16日 |
0.24.1 | 2024年4月18日 |
0.24.0 | 2023年10月14日 |
0.1.0 | 2023年9月26日 |
在网络编程中排名第13
每月下载量339,960
在195个Crates(74个直接)中使用
2MB
36K SLoC
概述
Hickory DNS Resolver是一个库,它使用Hickory DNS Proto库实现DNS解析器。
该库包含IPv4(A)和IPv6(AAAA)解析的实现,还有更多功能正在开发中。它基于tokio异步I/O项目构建,这允许它与其他使用tokio和futures库的系统集成。Hickory DNS 项目还包含其他DNS库:用于原生协议使用的客户端库,用于托管区域的服务器库,以及基于rustls和native-tls的TLS实现的变体。
注意该项目已从Trust-DNS更名为Hickory DNS,并已迁移到https://github.com/hickory-dns/hickory-dns组织及仓库,该crate/binary已迁移到hickory-resolver,从版本0.24开始,旧版本请参阅trust-dns-resolver。
特性
- 多种IPv4和IPv6查找策略
- 基于Unix/Posix系统的
/etc/resolv.conf
配置 - 基于性能的优先级使用的名称服务器池
- 查询结果的缓存
- NxDomain/无数据缓存(负缓存)
- DNSSEC验证
- 通用记录类型查找
- CNAME链解析
- DNS over TLS(使用
native-tls
、rustls
和openssl
;推荐使用native-tls
或rustls
) - DNS over HTTPS(目前仅支持
rustls
)
示例
use std::net::*;
use hickory_resolver::Resolver;
use hickory_resolver::config::*;
// Construct a new Resolver with default configuration options
let mut resolver = Resolver::new(ResolverConfig::default(), ResolverOpts::default()).unwrap();
// On Unix/Posix systems, this will read the /etc/resolv.conf
// let mut resolver = Resolver::from_system_conf().unwrap();
// Lookup the IP addresses associated with a name.
let mut response = resolver.lookup_ip("www.example.com.").unwrap();
// There can be many addresses associated with the name,
// this can return IPv4 and/or IPv6 addresses
let address = response.iter().next().expect("no addresses returned!");
if address.is_ipv4() {
assert_eq!(address, IpAddr::V4(Ipv4Addr::new(93, 184, 215, 14)));
} else {
assert_eq!(address, IpAddr::V6(Ipv6Addr::new(0x2606, 0x2800, 0x21f, 0xcb07, 0x6820, 0x80da, 0xaf6b, 0x8b2c)));
}
DNS-over-TLS和DNS-over-HTTPS
支持DoT和DoH。这是通过使用以下之一实现的:native-tls
、openssl
或rustls
(目前仅支持rustls
用于DoH)。解析器需要注册有效的DoT或DoH解析器才能使用。
要与Client
一起使用,应使用TlsClientConnection
或HttpsClientConnection
。同样,要与tokio的AsyncClient
一起使用,应使用TlsClientStream
或HttpsClientStream
。目前不支持ClientAuth、mTLS,还有一些问题正在解决。TLS对服务器身份验证和连接隐私很有用。
要启用DoT,必须启用以下功能之一:dns-over-native-tls
、dns-over-openssl
或dns-over-rustls
,dns-over-https-rustls
用于DoH。
示例
通过依赖hickory-resolver
启用TLS库
hickory-resolver = { version = "*", features = ["dns-over-rustls"] }
默认TLS配置适用于Cloudflare的1.1.11
DNS服务(Quad9同样适用)
// Construct a new Resolver with default configuration options
let mut resolver = Resolver::new(ResolverConfig::cloudflare_tls(), ResolverOpts::default()).unwrap();
/// see example above...
DNSSEC状态
当前根密钥被硬编码到系统中。这使DNSKEY和DS记录的验证回溯到根。已实现NSEC,但没有NSEC3。由于缓存尚未启用,已经注意到一些DNS服务器似乎对连接进行速率限制,验证RRSIG记录回溯到根可能需要对这些记录进行大量额外的查询。
通过动态DNS对任何记录更新进行自动重新签名。要启用DNSSEC,必须启用以下功能之一:dnssec-openssl
或dnssec-ring
。
使用resolve通过CLI测试解析器
通过独立的CLI测试hickory-resolver及其功能很有用。
cargo install --bin resolve hickory-util
示例
$ resolve www.example.com.
Querying for www.example.com. A from udp:8.8.8.8:53, tcp:8.8.8.8:53, udp:8.8.4.4:53, tcp:8.8.4.4:53, udp:[2001:4860:4860::8888]:53, tcp:[2001:4860:4860::8888]:53, udp:[2001:4860:4860::8844]:53, tcp:[2001:4860:4860::8844]:53
Success for query name: www.example.com. type: A class: IN
www.example.com. 21063 IN A 93.184.215.14
最小Rust版本
此项目的当前最小rustc版本是1.70
版本控制
Hickory DNS尽力遵循semver。在公开API稳定后,Hickory DNS将升级到1.0。这并不意味着Hickory DNS在0.x更新之间的升级一定会破坏。尽可能的情况下,旧API将被弃用,并注明替换了这些弃用。Hickory DNS将尽力确保API更改不会破坏依赖于它的软件,尽管这不能保证。弃用的接口将在它们被弃用后的至少一个主要版本中维护(如果可能),但升级到1.0除外,届时所有弃用的接口都将计划删除。
依赖项
~4–18MB
~283K SLoC