Troubleshooting Re-authentication Prompts and Preventing DNS Leaks on Linux
Frequent re-authentication prompts are not necessarily caused by DNS leaks. This article outlines common causes, provides methods to detect DNS leaks, and details a step-by-step guide to configuring local DNS routing using systemd-resolved, dnsmasq, and nftables to enhance privacy and ensure consistent resolution.
1. Conclusion First: Re-authentication is Not Necessarily a DNS Issue
Frequent re-authentication prompts can be caused by various factors, including expired credentials, changes in device or browser environment, frequent switching of exit IPs, simultaneous multi-device logins with the same account, and server-side policy adjustments. A DNS leak is merely one environmental factor. It affects privacy and can cause inconsistent resolution results, but it alone cannot prove that an account has been flagged by the system’s risk control.
When troubleshooting, confirm each item in the following order, changing only one thing at a time to easily locate the cause:
- Credentials and sessions: Have you recently changed your password, or are there old tokens saved across multiple applications?
- Device and browser: Have the OS, browser, or extensions been recently updated, or have cookies been cleared?
- Exit IP: Have you frequently switched nodes recently, and were the switches within the same region?
- Multi-device login: Is the same account online on multiple devices simultaneously?
- Server-side policies: Check official announcements or service status pages for adjustments.
- DNS resolution: Use the methods in Section 2 to detect if a leak is actually occurring.
The server typically cannot see the source of the DNS queries sent by the client. What it can see is the connection source IP, protocol characteristics, and login behavior. Therefore, the methods in this article are primarily intended to protect local privacy, reduce resolution inconsistencies, and provide a basis for troubleshooting. These methods do not guarantee the effectiveness of any specific service.
2. Where DNS Resolution Fits in the Request Chain
Before accessing a website, the client must first resolve the domain name to an IP address. This step is handled by the DNS server configured in the operating system, which is usually the resolver provided by the ISP. Even if data traffic passes through a proxy or encrypted tunnel, DNS queries might still be sent directly to the default resolver. This scenario is a DNS leak.
To determine if a leak is occurring, you must look at two things simultaneously: which server the resolution request is actually sent to, and whether the proxy or VPN covers the resolution process. A leak occurs only when these two are inconsistent.
DNS leaks have two main types of impacts.
The first is privacy exposure. If resolution requests pass through the local network in plaintext, the network operator or others on the same network can see which domains you have visited.
The second is inconsistent resolution results. If the proxy exit is located in Region A, but the domain is resolved by a resolver in Region B, geo-dependent services might return different CDN nodes. This is a potential impact, not a definitive outcome, nor does it mean the server will ban the account based on this.
3. Three Detection Methods
Before detecting, record the current time, node name, and network environment, then clear the system DNS cache (execute sudo resolvectl flush-caches in a systemd-resolved environment). This ensures that each result can be compared accurately.
Method 1: Public DNS Leak Test Websites
Open any public DNS leak detection page and record the resolver address and region it returns. If the returned region matches your proxy exit, it indicates that the browser’s resolution path is generally normal. This method only reflects the browser’s behavior at the moment of testing and cannot cover command-line tools or other applications.
Method 2: System-Level Check
Execute the following commands in a Linux terminal:
resolvectl statuscat /etc/resolv.confdig example.com | grep SERVER
The SERVER line in the dig output shows the resolver that actually answered. If it is an ISP address and your proxy is supposed to handle resolution, further investigation is required.
You can also use packet capture to confirm where DNS traffic is going. Keep the capture time as short as possible:
sudo timeout 20 tcpdump -i any -nn port 53
In another terminal, visit a few websites. If you capture traffic destined for a non-local address on port 53, it indicates plaintext DNS is being sent out. The capture content includes access records, so delete the relevant output immediately after finishing.
Method 3: Browser Secure DNS Comparison
Modern browsers support DNS over HTTPS (DoH). Search for “Secure DNS” in your browser settings, and repeat the detection from Method 1 in both enabled and disabled states to compare the results. If the resolver address changes when enabled, it means the browser’s resolution path has been rewritten, and you need to ensure it does not conflict with your proxy settings.
DoH uses port 443, so the port 53 packet capture in Method 2 will not see it. Therefore, Method 3 must be used in conjunction with Method 2.
Evaluation Criteria
| System Resolver | Exit Region vs. Resolver Region | Evaluation |
|---|---|---|
| Local address (e.g., 127.0.0.1) | Consistent | No leak |
| ISP address | Inconsistent | Leak |
| ISP address | Consistent (accidental) | Needs further confirmation, retest multiple times |
| Local address | Inconsistent | Check local upstream configuration |
This evaluation only applies to the specific test and the network environment at that time. Node switching, proxy restarts, or browser updates can change the results. It is recommended to retest after a period of time.
4. Local Routing Configuration Example
This section uses Ubuntu 22.04 or 24.04 as an example, with the following prerequisites:
- Using
systemd-resolvedas the system resolver (systemd 245 and above). - Using
dnsmasq2.86 and above as the local forwarder, listening on127.0.0.1:53. - Using
nftables0.9.x and above for outbound restrictions. - The proxy software provides a DNS listener locally, assumed to be
127.0.0.1:1053. You need to configure this port in your proxy software and ensure it resolves domains through the proxy tunnel. - All operations require root privileges. It is recommended to try this in a virtual machine first, or on a machine where you have physical console access.
Step 1: Backup Existing Configuration
sudo cp /etc/systemd/resolved.conf /etc/systemd/resolved.conf.baksudo cp -a /etc/resolv.conf /etc/resolv.conf.baksudo nft list ruleset > ~/nft-backup-$(date +%F).nft
Step 2: Route systemd-resolved Queries to Local dnsmasq
Edit /etc/systemd/resolved.conf and set the following in the [Resolve] section:
[Resolve]DNS=127.0.0.1FallbackDNS=DNSStubListener=no
Leave FallbackDNS empty to disable systemd’s default public DNS fallback. Set DNSStubListener=no to release port 53 so dnsmasq can bind to it.
Execute the following commands to apply the configuration and point /etc/resolv.conf to the file generated by resolved:
sudo systemctl restart systemd-resolvedsudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf
If the system has NetworkManager installed, it might overwrite resolv.conf. You can set the DNS to 127.0.0.1 in NetworkManager’s connection settings, or configure NetworkManager to pass DNS to systemd-resolved.
Step 3: Configure dnsmasq
Create /etc/dnsmasq.d/local-proxy.conf:
listen-address=127.0.0.1bind-interfacesport=53no-resolvno-pollserver=127.0.0.1#1053cache-size=1000
The parameters function as follows:
no-resolv: Do not read the upstream from/etc/resolv.confto avoid falling back to the ISP resolver.server=127.0.0.1#1053: The only upstream is the DNS provided by the proxy.bind-interfaces: Bind only to the specified address to reduce unexpected exposure.
Check the syntax first, then start the service:
sudo dnsmasq --testsudo systemctl restart dnsmasq
If dnsmasq fails to start with a port 53 in use error, check if the DNSStubListener change from Step 2 has taken effect: ss -lntup | grep ':53 '.
5. Firewall Restrictions for Outbound DNS
The following nftables rules allow access to port 53 on the local loopback address, while all other DNS queries originating from the host will be dropped. Save this as /etc/nftables-dnsguard.nft:
table inet dnsguard {chain output {type filter hook output priority 0; policy accept;ip daddr 127.0.0.0/8 acceptip6 daddr ::1 acceptudp dport 53 log prefix "dnsguard-drop " limit rate 5/minute droptcp dport 53 log prefix "dnsguard-drop " limit rate 5/minute drop}}
Load the rules:
sudo nft -f /etc/nftables-dnsguard.nft
Rule explanation:
- The loopback address rules are placed first, so dnsmasq forwarding to
127.0.0.1:1053will not be blocked. - If the proxy process runs as an independent user and needs to resolve domains directly, you can add
meta skuid "username" acceptbefore the two drop rules. - These rules do not block DoH traffic, as DoH uses port 443.
- The
logcombined with rate limiting records dropped requests, making it easier to identify which program is querying DNS directly.
6. Fault Fallback and Log Troubleshooting
If the proxy disconnects briefly, dnsmasq’s only upstream becomes unavailable, and it will return a failure (SERVFAIL) to the client. This is the intended design. Applications will fail to connect rather than silently falling back to the ISP resolver. If you can still open websites normally during a disconnect, it means some part of the configuration is not working, and you need to investigate using the steps below.
First, perform a fault test. Stop the proxy software’s DNS listener, then execute:
dig example.com
The expected result is status: SERVFAIL or a timeout, and the SERVER line should not point to an ISP address.
Log troubleshooting commands are as follows:
# dnsmasq upstream failure records from the last hourjournalctl -u dnsmasq --since "1 hour ago" --no-pager | grep -iE "failed|timeout|refused"# systemd-resolved runtime logsjournalctl -u systemd-resolved --since today --no-pager# Resolution statistics, including cache hits and failuresresolvectl statistics# DNS requests dropped by the firewallsudo journalctl -k --since today | grep dnsguard-drop# View processes occupying port 53ss -unp | grep ':53 '
If you need to view dnsmasq’s query logs, you can temporarily add log-queries and log-facility=/var/log/dnsmasq.log to the configuration. Query logs contain the domains accessed, so ensure you disable logging and delete the log file after troubleshooting.
7. Verification and Rollback
Note: Performing the following steps in the wrong order may result in the local machine being unable to resolve domains. For remotely operated machines, ensure you retain console access or confirm that an alternative connection method is available.
Verification
Execute in order, with the expected results for each step as follows:
resolvectl status | grep -i "DNS Servers"dig example.com | grep SERVERdig @8.8.8.8 example.com +time=3 +tries=1ss -lntup | grep -E ':(53|1053)\b'sudo nft list table inet dnsguard
- The first command should display
127.0.0.1. - The SERVER in the second command should be
127.0.0.1#53. - The third command should timeout, indicating that direct access to external DNS is blocked.
- The fourth command should show dnsmasq listening on port 53 and the proxy DNS listening on port 1053.
- The fifth command should display the ruleset.
After confirming everything is correct, perform the fault test from Section 5.
Rollback
Execute the following commands in order. This will only delete the rules and configurations created in this article and will not affect other firewall rules:
sudo nft delete table inet dnsguardsudo systemctl stop dnsmasqsudo systemctl disable dnsmasqsudo rm -f /etc/dnsmasq.d/local-proxy.confsudo cp /etc/systemd/resolved.conf.bak /etc/systemd/resolved.confsudo systemctl restart systemd-resolvedsudo ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.confresolvectl flush-caches
After rollback, dig example.com should return normal results, and the DNS server shown in resolvectl status should revert to the original ISP or router address.
Do not use nft flush ruleset to clean up rules, as it will delete all firewall rules on the machine. Also, do not load a full backup directly using nft -f, as it will throw an error if the table already exists. Just deleting the inet dnsguard table is sufficient.
Consider writing the rules and configurations to startup settings only after verification passes and the system runs stably for a period of time. This step is outside the scope of this article; please ensure your backups are available before operating.
