From 39bb4fefa15afb16d117fb84f1265516d624280c Mon Sep 17 00:00:00 2001 From: theS1LV3R Date: Mon, 27 Jul 2026 12:33:56 +0200 Subject: [PATCH] feat: Add support for custom DNS servers Adds an option `dns_servers` which takes IPs for custom servers. Does not allow for custom DNS ports as this is largely not supported in tokio and hickory, and would otherwise be a pain to implement properly. Fixes: #1866 See-Also: https://matrix.to/#/!ksTlboXVgcyWjv5GrlEeKyQuJ8ZCprnwQx2b6-BQ44Q/%24qrBGOzosK4BdRbF5jhf5ehrxQUTaIr-U-UpqTmPhkPY?via=wolfgirl.pet&via=matrix.org --- src/core/config/mod.rs | 9 +++++++++ src/service/client/mod.rs | 20 ++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/core/config/mod.rs b/src/core/config/mod.rs index 98c74a116..658f93735 100644 --- a/src/core/config/mod.rs +++ b/src/core/config/mod.rs @@ -383,6 +383,15 @@ pub struct Config { #[serde(default = "default_stateinfo_cache_capacity")] pub stateinfo_cache_capacity: u32, + /// DNS servers to use instead of system defaults. Does NOT accept IP:Port + /// pairs, only plain IPs. IPv6 addresses should be without brackets. + /// + /// Uses system configuration (/etc/resolv.conf) if empty. + /// + /// default: [] + #[serde(default)] + pub dns_servers: Vec, + /// Maximum entries stored in DNS memory-cache. The size of an entry may /// vary so please take care if raising this value excessively. Only /// decrease this when using an external DNS cache. Please note that diff --git a/src/service/client/mod.rs b/src/service/client/mod.rs index 5fe5c79de..fc139a144 100644 --- a/src/service/client/mod.rs +++ b/src/service/client/mod.rs @@ -4,7 +4,10 @@ use conduwuit::{Config, Result, Server, err, trace, utils::response::LimitReadExt, warn}; use either::Either; use hickory_resolver::{ - TokioResolver, config::ConnectionConfig, net::runtime::TokioRuntimeProvider, + TokioResolver, + config::{ConnectionConfig, NameServerConfig}, + net::runtime::TokioRuntimeProvider, + proto::rr::IntoName, }; use ipaddress::IPAddress; use reqwest::redirect; @@ -320,7 +323,20 @@ fn get_dns_resolver(server: &Arc) -> Result> { conf.add_search(sys_conf.clone()); } - for sys_conf in sys_conf.name_servers() { + let config_nameservers: Vec = server + .config + .dns_servers + .iter() + .filter_map(IntoName::to_ip) + .map(NameServerConfig::udp_and_tcp) + .collect(); + let nameservers = if !config_nameservers.is_empty() { + config_nameservers + } else { + sys_conf.name_servers().to_vec() + }; + + for sys_conf in nameservers { let mut ns = sys_conf.clone(); if config.query_over_tcp_only {