Overview
DNS management ensures:- DNS requests only go to approved servers (relay or custom DNS)
- No DNS leaks outside the tunnel
- Automatic restoration of original DNS settings
- Platform-specific integration with system services
talpid-dns/src/lib.rs
DNS Configuration Types
Default DNS
Uses the VPN relay server (default gateway) as resolver:talpid-dns/src/lib.rs:71-82
Custom DNS
Tunnel config: DNS servers accessible through the tunnel Non-tunnel config: DNS servers accessible on non-tunnel interfaces (typically private IPs) Source:talpid-dns/src/lib.rs:44-67
Platform Selection
The daemon automatically selects the appropriate DNS method, or it can be forced:docs/README.md:182-196
Windows DNS Methods
Available Methods
Windows tries methods in this order (when auto-detecting):- iphlpapi - IP Helper API (default)
- netsh -
netshcommand-line tool - tcpip - Registry TCP/IP parameters
talpid-dns/src/windows/mod.rs:34-46
1. iphlpapi Method
Primary method usingSetInterfaceDnsSettings from IP Helper API:
- Calls Windows API directly
- Sets DNS servers per interface
- Fastest and most reliable
- Requires Windows 10+
talpid-dns/src/windows/iphlpapi.rs
2. netsh Method
Fallback usingnetsh interface ipv4/ipv6 set dnsservers:
- Spawns
netsh.exeprocess - Configures via command-line
- Works on older Windows versions
- Slower than API approach
talpid-dns/src/windows/netsh.rs
3. tcpip Method
Registry-based method:- Modifies
HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\{GUID} - Sets
NameServerandNameServer6registry values - Most compatible but least reliable
- Requires service restart for changes to take effect
talpid-dns/src/windows/tcpip.rs
DNS Flushing
Windows caches DNS responses. The daemon usesDnsFlushResolverCache from dnsapi.dll to clear cache when DNS servers change.
Source: talpid-dns/src/windows/dnsapi.rs
Linux DNS Methods
Available Methods
Linux automatically detects the best method:- systemd-resolved (via D-Bus)
- NetworkManager (via D-Bus)
- resolvconf (program)
- static-file (
/etc/resolv.conf)
talpid-dns/src/linux/mod.rs:116-141
1. systemd-resolved (Preferred)
Primary method on systemd-based systems:- Uses D-Bus to communicate with
systemd-resolved - Calls
SetLinkDNSmethod on interface - Sets per-interface DNS servers
- Automatic when resolved is running
talpid-dns/src/linux/systemd_resolved.rs
2. NetworkManager
Alternative for NetworkManager-managed systems:- Uses D-Bus to communicate with NetworkManager
- Modifies DNS configuration per connection
- Used when systemd-resolved unavailable
talpid-dns/src/linux/network_manager.rs
3. resolvconf Program
Compatibility method usingresolvconf tool:
- Executes
/sbin/resolvconfbinary - Writes DNS config via stdin
- Standard on Debian-based systems
talpid-dns/src/linux/resolvconf.rs
4. Static resolv.conf
Fallback directly modifying/etc/resolv.conf:
- Backs up original
/etc/resolv.conf - Writes new file with
nameserverentries - Restores backup on reset
- Last resort when no other method works
talpid-dns/src/linux/static_resolv_conf.rs
Routing Considerations
On Linux, DNS requests to custom non-tunnel servers require routing:- Route manager adds routes to DNS servers
- Ensures traffic doesn’t go through tunnel
- Only for private IP ranges
talpid-dns/src/linux/systemd_resolved.rs
macOS DNS Management
Implementation
MacOS uses System Configuration framework:- Set DNS via
SCDynamicStoreSetValue - Configure per interface using
State:/Network/Service/{service}/DNS - Set search domains (if applicable)
- Priority ordering ensures tunnel interface used first
talpid-dns/src/macos.rs
Local DNS Resolver
macOS runs a local DNS proxy by default at127.0.0.1:53:
Behavior:
- Forwards queries to configured upstream servers
- Can be disabled:
TALPID_DISABLE_LOCAL_DNS_RESOLVER=1 - May cache AAAA queries aggressively
- App filters AAAA queries when IPv6 disabled
- Prevents IPv6 DNS leaks
- Force disable:
TALPID_NEVER_FILTER_AAAA_QUERIES=1
docs/README.md:197-200
System Configuration Keys
macOS stores DNS configuration in dynamic store:Android DNS Management
Implementation
Android uses VPN Service API:- Sets DNS servers for VPN interface
- System routes DNS through VPN automatically
- No direct DNS configuration needed
- Exempt traffic (connectivity checks) bypasses DNS settings
talpid-dns/src/android.rs
Split Tunneling
Excluded apps use system DNS:- Not routed through VPN
- Use DHCP or manually configured DNS
- Behave as if VPN disconnected
docs/split-tunneling.md:63-73
iOS DNS Management
Implementation
iOS uses Network Extension:- Sets DNS servers for tunnel
- System enforces DNS routing
- Cannot be bypassed by apps
- Local network DNS accessible
docs/security.md:71-76
DNS in Firewall States
Disconnected State
Lockdown mode disabled:- Uses system default DNS (ISP or DHCP)
- No restrictions applied
- All DNS blocked
- Behaves like Error state
docs/security.md:146-163
Connecting State
- All DNS blocked via firewall
- Exception: relay endpoint (if on port 53)
- Prevents leaks during setup
docs/security.md:166-189
Connected State
Default DNS:- DNS to relay server only
- Blocked on non-tunnel interfaces
- DNS to specified servers through tunnel
- All other DNS blocked
- DNS to private IPs on non-tunnel interfaces
- Example:
192.168.1.1for local DNS
docs/security.md:194-208
Error State
- All DNS blocked
- API access exception (for daemon)
- Prevents all leaks
docs/security.md:221-238
DNS Configuration Flow
Setting DNS
- Daemon receives tunnel config
- Resolves DNS config (default or custom)
- DnsMonitor applies platform-specific method
- Firewall rules enforce DNS restrictions
- Monitors for external changes (platform-dependent)
Restoring DNS
- Daemon receives disconnect request
- Firewall rules removed
- DnsMonitor restores original settings
- System DNS behavior returns to normal
Implementation Details
DnsMonitor Interface
Platform-agnostic interface:talpid-dns/src/lib.rs:211-226
State Management
Initialization:Environment Variables
All Platforms
macOS Only
docs/README.md:182-200
Common Issues
systemd-resolved Conflicts
Problem: Multiple DNS managers compete Solution: Ensure only one active:DNS Cache Stale Entries
Problem: Old DNS responses cached Solution:- Windows: Automatically flushed via
DnsFlushResolverCache - Linux: systemd-resolved clears cache
- macOS:
dscacheutil -flushcache
Private DNS Routing
Problem: Custom private DNS unreachable Solution:- Enable “Allow LAN” setting
- Ensures traffic to private IPs allowed
- Routing manager adds necessary routes
Security Considerations
DNS Leak Prevention
Multiple layers prevent DNS leaks:- DNS configuration - Only allows approved servers
- Firewall rules - Blocks port 53 to other destinations
- Routing - Ensures DNS traffic uses correct interface
- Monitoring - Detects and corrects external changes
docs/security.md:276-291
DNS in Split Tunneling
Desktop platforms:- DNS requests from all processes use tunnel
- Cannot be excluded per-process
- System DNS service not excluded
- Excluded apps use system DNS
- Requests bypass VPN entirely
- Behave as if VPN disconnected
docs/split-tunneling.md:16-73