A cross platform local DNS server (Dnsmasq like) written in rust to obtain the fastest website IP for the best Internet experience, supports DoT, DoQ, DoH, DoH3.
SmartDNS-rs
Docs β’
English | δΈζ
SmartDNS-rs π is a local DNS server imspired by C SmartDNS to accepts DNS query requests from local clients, obtains DNS query results from multiple upstream DNS servers, and returns the fastest access results to clients. Avoiding DNS pollution and improving network access speed, supports high-performance ad filtering.
Features
- Multiple upstream DNS servers
- Return the fastest IP address
- Support for multiple query protocols
- Domain IP address specification
- DNS domain forwarding
- Windows / MacOS / Linux multi-platform support
- Support IPV4, IPV6 dual stack
- DNS64
- High performance, low resource consumption
Note: The C version of smartdns is very functional, but because it only supports Linux, while MacOS and Windows can only be supported through Docker or WSL. Therefore, I want to develop a rust version of SmartDNS that supports compiling to Windows, MacOS, Linux and Android Termux environment to run, and is compatible with its configuration.
It is still under development, please do not use it in production environment, welcome to try and provide feedback.
Please refer to TODO for the function coverage
Installing
Nightly builds can be found here.
- MacOS
brew update
brew install smartdns
Note: Listening on port 53 requires root permission, so sudo is required.
The command sudo smartdns service start for brew installed smartdns is the same as sudo brew services start smartdns.
If you don't have brew installed, just download the compiled program compression package and install it as below.
- Windows / Linux
1. Get help
./smartdns --help
2. Run as foreground, easy to check the running status
./smartdns run -c ./smartdns.conf -v
- -v is enabled to print debug logs.
3. Run as background service, run automatically at startup
Get help of service management commands.
./smartdns service --help
Note: Installed as a system service, administrator / root permissions are required.
Service management is compatible with all systems, call sc) on Windows; call launchctl or brew on MacOS; call Systemd or OpenRc on Linux.
Configuration
The following is the simplest example configuration
# Listen on local port 53
bind 127.0.0.1:53
Configure bootstrap-dns, if not configured, call the system_conf,
it is recommended to configure, so that it will be encrypted.
server https://1.1.1.1/dns-query -bootstrap-dns -exclude-default-group
server https://8.8.8.8/dns-query -bootstrap-dns -exclude-default-group
Configure default upstream server
server https://cloudflare-dns.com/dns-query
server https://dns.quad9.net/dns-query
server https://dns.google/dns-query
Configure the Office(Home) upstream server
server 192.168.1.1 -exclude-default-group -group office
Domain names ending with ofc are forwarded to the office group for resolution
nameserver /ofc/office
Set static IP for domain name
address /test.example.com/1.2.3.5
Block Domains (Ad Blocking)
address /ads.example.com/#
The following features are not yet supported in the C SmartDNS and are only applicable to SmartDNS-rs.
Configure DoH3
server-h3 1.1.1.1
Configure DoQ
server-quic unfiltered.adguard-dns.com
For more advanced configurations, please refer to here , and refer to TODO for the function coverage.
Built-in diagnostics via dig
SmartDNS-rs supports built-in CHAOS TXT queries for server/client diagnostics.
# most common: full identity info (server + client, multi TXT records)
dig @127.0.0.1 CH TXT whoami +short
server identity info only (multi TXT records)
dig @127.0.0.1 CH TXT smartdns +short
server name
dig @127.0.0.1 CH TXT server-name +short
server version
dig @127.0.0.1 CH TXT version +short
client source IP seen by smartdns-rs
dig @127.0.0.1 CH TXT client_ip +short
dig @127.0.0.1 CH TXT client-ip +short
client MAC from ARP table (LAN, ARP available)
dig @127.0.0.1 CH TXT client_mac +short
dig @127.0.0.1 CH TXT client-mac +short
JSON output with suffix style
dig @127.0.0.1 CH TXT whoami.json +short
dig @127.0.0.1 CH TXT smartdns.json +short
Compatibility examples
dig @127.0.0.1 CH TXT hostname.bind +short
dig @127.0.0.1 CH TXT version.bind +short
dig @127.0.0.1 CH TXT id.server +short
Building
Assuming you have installed Rust, then you can open the terminal and execute these commands:
git clone https://github.com/mokeyish/smartdns-rs.git
cd smartdns-rs
install https://github.com/casey/just
cargo install just
build
just build --release
print help
./target/release/smartdns --help
run
sudo ./target/release/smartdns run -c ./etc/smartdns/smartdns.conf
For cross-compilation, it is recommended to use cross (requires Docker).
Acknowledgments !!!
This software wouldn't have been possible without:
License
This software contains codes from https://github.com/hickory-dns/hickory-dns, which is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
- GPL-3.0 license (LICENSE-GPL-3.0 or https://opensource.org/licenses/GPL-3.0)
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the GPL-3.0 license, shall be licensed as above, without any additional terms or conditions.