中文 English

Why Did My Blog Jump to Baidu? Unmasking DNS Poisoning & 302 Hijacking: The Ultimate AdGuard Home + DoH Hardening Guide

Published: 2026-09-18 · 阅读量 --
DNS Domain Resolution Network Troubleshooting Security Automation AdGuard Home

Bottom Line First: Your blog wasn’t hacked, your static site wasn’t injected with malicious JavaScript, and GitHub Pages wasn’t down. The root culprit was cleartext DNS poisoning and transparent proxy interception along the transit ISP path!

In a legacy cleartext UDP port 53 environment, rogue intermediate network equipment forged a rogue DNS reply, redirecting your blog’s domain to an unrelated external IP. That rogue server, having no virtual host configuration for your site, executed a default fallback HTTP 302 Found redirect, abruptly bouncing the browser to mobile Baidu!

By switching AdGuard Home’s Upstream DNS Servers to DoH (DNS-over-HTTPS), intermediate off-path injection is immediately neutralized, restoring domain resolution to authentic origin servers. This guide combines forensic packet traces with intuitive everyday analogies to help you permanently resolve this network anomaly.

AI Concept Illustration: DNS Off-Path Poisoning vs AdGuard Home DoH Encrypted Cryptographic Tunnel


1. Incident Background: Hard Work Built a Blog, So Why Does Hitting Enter Open Baidu?

For every developer and tech enthusiast, a personal independent blog is their digital sanctuary. You spend hours curating your Hugo static theme, configuring your GitHub Pages CI/CD deployment pipeline, and binding a custom domain (blog.margrop.net). Everything looks sleek, modern, and rock solid.

Then, on a seemingly normal afternoon, an unnerving anomaly occurs: You type blog.margrop.net into your browser’s address bar and hit Enter. Instead of loading your technical essays, the screen flashes blank for a split second, and the address bar suddenly transforms into Baidu’s mobile search homepage (https://m.baidu.com/...)!

The Panic Questions:

  1. Was my server hacked? Did an attacker inject a malicious JavaScript redirect into my generated static pages?
  2. Was my domain hijacked? Did an attacker compromise my registrar account or let my DNS records expire?
  3. Is GitHub Pages experiencing an outage? Or did an intermediate CDN edge node suffer a disastrous routing mix-up?

Engineers who lack deep network protocol forensics often scramble into emergency mode: frantically reviewing Git commit logs, rebuilding static site generators, or even nuking and recreating DNS zone records. Yet, after hours of frustration, reopening the browser on the local LAN continues to land right on Baidu!

What is really happening? Let’s open DevTools and capture real wire evidence.


2. Problem Symptoms: A Deceptive Redirect Hiding On-Wire Forensics

When encountering HTTP redirects, never guess. The golden rule of troubleshooting is: preserve the scene and inspect raw wire headers.

Press F12 to open Chrome DevTools, switch to the Network tab, check Preserve log, and type http://blog.margrop.net/. The very first HTTP transaction immediately reveals the truth:

Real Screenshot: Chrome DevTools Network inspect trace capturing HTTP 302 Found redirecting to Baidu

Dissecting the Response Headers:

Looking closely at the captured headers:

The Striking Clues:

  1. The Server Signature: The server software identifies itself as bfe/1.0.*.* (Baidu Front End, Baidu’s edge reverse proxy cluster). It is neither GitHub Pages (GitHub.com) nor Fastly CDN (Varnish)!
  2. The Destination IP: 123.125.*.* belongs to Baidu’s network range, completely disconnected from GitHub Pages’ official Anycast IP pool (185.199.*.*)!
  3. The Motive for Bouncing to Baidu: Baidu’s edge gateway received an HTTP request bearing Host: blog.margrop.net. Baidu’s ingress checked its virtual host tables: “I have no website registered under this domain!” Under default fallback routing, unknown HTTP requests are redirected via 302 Found to mobile Baidu search!

The first myth is shattered: Your website code never instructed the redirect. Your HTTP request knocked on the wrong door from the very first packet!


3. Technical Analysis: The Three Security Gates of Web Browsing

Why was the packet dispatched to a completely foreign server? To understand the underlying failure, we must separate web browsing into three distinct, sequential security gates:

Architectural Flowchart: The Three Security Gates of Web Browsing and HTTP 302 Redirect Mechanics

Gate 1: DNS Resolution (Looking Up the Phonebook)

Gate 2: TLS Cryptographic Handshake (Inspecting ID Cards & Seals)

Gate 3: HTTP Application Session (Entering the Room for Conversation)


👦 Elementary School Analogy: Visiting a Classmate & The Prank Chalkboard

Imagine young Timmy wants to visit his best friend Leo (blog.margrop.net) after school:

  1. Gate 1: Checking the Janitor’s Chalkboard (DNS Lookups) Timmy doesn’t know Leo’s house number, so he checks the school janitor’s noticeboard. Normally it says: “Leo lives at 8 Elm Street (185.199..)”. But yesterday, a mischievous bully erased the board and wrote: “Leo lives at 99 Broadway (123.125..)”! Timmy trusts the board and heads off to Broadway.

  2. Gate 2: Knocking on the Iron Door (HTTP Knock) Timmy knocks on 99 Broadway: “Hi, is Leo here? We’re going to play video games!” A bewildered department store clerk (Server: bfe) opens the door: “Who is Leo? This is a shopping mall! If you want stationery, go down to the Grand Bazaar!” The clerk points down the avenue—that is an HTTP 302 Found, Location: Grand Bazaar (Baidu Search)!

  3. Gate 3: Why Didn’t the Guard Dog Bark? (HTTPS Validation) Why didn’t Timmy catch the trick? Because Timmy took the uninspected backdoor (plain unencrypted HTTP)! If Timmy had followed HTTPS strict security rules, he would have demanded the clerk show Leo’s family photo and national ID card. The department store clerk obviously wouldn’t have Leo’s family certificate, and Timmy would have spotted the fake immediately and backed away!


4. In-Depth Diagnostics & Evidence: The Zero-Privacy Forensic Matrix

To rigorously verify that the site was intact and that only the DNS path was poisoned, we set up a controlled, repeatable experimental matrix.

In compliance with privacy standards, all internal LAN IPs, private hostnames, and computer identifiers have been sanitized.

Experiment 1: Raw Lookups vs Source-Targeted Verification (curl --resolve)

If we execute curl normally, it inherits the poisoned local DNS. But if we use --resolve to force blog.margrop.net:443 to connect directly to the verified official GitHub Pages IP (185.199.*.*), the contrast is decisive:

Real Screenshot: Terminal curl –resolve controlled experiment, poisoned IP fails TLS vs verified IP returns 200 OK

Key takeaways from the terminal output:

Forensic Finding 1: The blog source, GitHub Pages infrastructure, and TLS certificates are 100% healthy!

Experiment 2: Cleartext UDP 53 vs TCP 53 vs DoH

Next, we interrogate the DNS transport layer using dig with varying protocols:

Real Screenshot: dig contrast suite, UDP 53 intercepted with 9ms fake reply vs TCP 53 penetrating to authentic Anycast IP

Notice the stark differences:

Forensic Finding 2: The network path is plagued by UDP 53 interception and cache-poisoning, while encrypted or connection-oriented DNS transports remain completely immune!


5. Root Cause: Cleartext UDP 53 Poisoning and AdGuard Home’s “Encryption Trap”

The root culprit is evident: intermediate cleartext DNS poisoning.

Security Contrast Diagram: Legacy UDP 53 Cleartext Broadcast vs DoH Encrypted Cryptographic Envelope

Yet, many users who already run AdGuard Home on their home networks still fall victim. Why? Because of a pervasive misunderstanding regarding AdGuard Home’s configuration:

Trap 1: Confusing “Encryption Settings” with Upstream Hardening

In AdGuard Home’s navigation menu, there is a prominent tab labeled [Encryption Settings]. Many users open this tab, see prompts for SSL certificates, private keys, and listening ports (443, 853), and assume this is where they enable DoH protection.

Real Screenshot: AdGuard Home Encryption Settings page, which configures downstream inbound server mode, not upstream resolution

Crucial Truth: This setting turns AdGuard Home into an inbound DoH/DoT SERVER for your downstream clients!

Trap 2: Failing to Distinguish the “Two Legs” of DNS Topology

DNS traffic must be divided into Inbound Leg 1 and Outbound Leg 2:

Topology Architecture Diagram: AdGuard Home Two-Leg Topology and Exact Encryption Placement

  1. Leg 1: Inbound Leg (Local LAN)
    • Path: Endpoints (PC/Phone/TV) ──[Standard UDP 53]──> AdGuard Home.
    • Analysis: Your LAN is a trusted, controlled environment without ISP interception equipment. Keeping standard UDP 53 here ensures zero-config plug-and-play compatibility for all devices!
  2. Leg 2: Outbound Leg (Public WAN Transit) — The Real Battlefield!
    • Path: AdGuard Home ──[WAN Transit]──> Public Upstream Resolvers.
    • Analysis: Packets traversing the WAN are exposed to DPI sniffing and injection.
    • The Golden Fix: You must configure DoH URLs (starting with https://) under [Settings -> DNS Settings -> Upstream DNS servers]!

👦 Elementary School Analogy: The Front Door Lock vs The Town Rumor-Monger

Making this mistake in AdGuard Home is like this:

  • You spend $1,000 installing a high-tech biometric face-scanner on your front door (Encryption Settings). Now your parents have to scan their retinas just to enter the living room;
  • But when you go grocery shopping, you still ask the neighborhood liar down the street (Cleartext UDP 53 upstream) for directions! The liar grins: “The supermarket moved to Mars today!”
  • What is the smart approach? Keep your home front door easy to push open (simple LAN access). But hire an armored security convoy with armed escorts (Upstream DoH tunnel) to deliver all your inquiries directly to the National Archives! Nobody on the street can trick you anymore!

6. How to Resolve: Step-by-Step AdGuard Home DoH Hardening

Armed with this architectural clarity, fixing the issue takes only six clean steps.

Step 1: Open AdGuard Home DNS Settings

Log in to your AdGuard Home web panel (e.g. http://192.168.X.X:3000). In the top menu, navigate to Settings -> DNS settings.

Step 2: Configure Verified DoH Upstreams

Locate the Upstream DNS servers textarea. Remove all legacy plain IP addresses (such as 223.5.*.* or 114.114.*.*), and enter verified high-availability DoH endpoints:

https://dns.alidns.com/dns-query
https://doh.pub/dns-query

Real Screenshot: AdGuard Home Upstream DNS configuration interface with DoH endpoints passing test query verification

Step 3: Configure Bootstrap DNS

A classic chicken-and-egg dilemma emerges: AdGuard Home must connect to https://dns.alidns.com/dns-query, but how does it know the numerical IP of dns.alidns.com?

Key Mechanism Diagram: Bootstrap DNS Resolving the Chicken-and-Egg Deadlock

This is the sole purpose of Bootstrap DNS servers:

Step 4: Clear Plaintext Fallback Resolvers

In the Fallback DNS servers box, ensure all cleartext UDP IP entries are removed! If an unencrypted fallback resolver is left behind, minor WAN latency spikes could prompt AdGuard Home to query the fallback concurrently, allowing poisoned replies back into the cache!

Step 5: Flush Operating System DNS Caches

After saving, AdGuard Home clears its internal cache. However, local endpoint caches (Windows, Linux, macOS) may still retain stale poisoned records. Run one of the following commands:

Real Screenshot: Cross-platform OS DNS client cache flush and instant resolution verification

Step 6: Audit the Live Query Log Stream

Navigate to Query Log in AdGuard Home. Reload your blog in the browser and watch the real-time stream:

Real Screenshot: AdGuard Home Query Log details confirming hits on DoH upstream with authentic origin Anycast IP

From the live log inspection:


7. Cross-Platform 1-Click Automation Toolkits (Windows 11 / Ubuntu 26.04 / macOS 26)

Manual UI tweaks work well for one-off fixes. But across edge gateways, home lab clusters, and automated DevOps workflows, manual clicks are error-prone.

We built a dependency-free, pure Python 3.10+ standard library automation toolkit utilizing AdGuard Home’s OpenAPI. It supports both interactive manual runs and unattended Agent orchestration!

Toolkit Downloads


Core Automation Architecture (Safety First)

  1. API Preflight Check: Connects via Basic Auth to AdGuard Home OpenAPI, verifying schema compatibility.
  2. Server-Side Upstream Testing: Invokes /control/test_upstream_dns so the server validates candidates beforehand.
  3. Atomic Snapshot Backup: Saves a protected snapshot in ~/.agh-doh-backups/ (0600 permissions) before mutations.
  4. Transaction Commit & Read-Back: Applies new DoH upstreams via /control/dns_config, immediately querying /control/dns_info to guarantee parity.
  5. Automatic Rollback: Restores original settings if any transaction step fails.
  6. Server Cache Eviction: Calls /control/cache_clear to flush stale records.

Real Screenshot: configure_doh.py cross-platform automated orchestration execution log


Method A: Interactive Manual Execution

Extract the archive and run the platform launcher:

1. Windows 11 (PowerShell)

# Preflight test only (dry-run)
powershell -NoProfile -File .\windows11.ps1

# Apply configuration changes
powershell -NoProfile -File .\windows11.ps1 --apply

2. Ubuntu 26.04 / 24.04 (Bash)

chmod +x ./ubuntu26.sh
# Dry run
./ubuntu26.sh
# Apply changes
./ubuntu26.sh --apply

3. macOS 26 (Bash/Zsh)

chmod +x ./macos26.sh
# Dry run
./macos26.sh
# Apply changes
./macos26.sh --apply

The script prompts securely for the management URL, username, and password (input hidden), applying changes automatically.


Method B: AI Agent Automated Orchestration (Headless Mode)

For AI coding agents or unattended Ansible playbooks, decouple credentials from the command line.

Create plan.json in a private directory:

{
  "base_url": "https://192.168.X.X/control/",
  "username": "admin",
  "upstreams": [
    "https://dns.alidns.com/dns-query",
    "https://doh.pub/dns-query"
  ]
}

Store the secret password in a dedicated file:

chmod 600 password.txt

Instruct the Agent to execute the headless run:

# Preflight check
python3 configure_doh.py --plan plan.json --password-file password.txt

# Atomic apply
python3 configure_doh.py --plan plan.json --password-file password.txt --apply

Instant Rollback Command:

To roll back immediately, specify the snapshot path:

python3 configure_doh.py --plan plan.json --password-file password.txt \
  --restore "~/.agh-doh-backups/agh-backup-20260918-221802.json" --apply

8. Frequently Asked Questions (Q&A)

Q1: When my blog redirected to Baidu, was Baidu responsible for the hijack?

A: Absolutely not. Baidu’s BFE reverse proxy cluster handles tens of millions of requests daily. When external DNS poisoning incorrectly routes packets intended for your domain to Baidu’s gateway IP, Baidu’s servers find no matching virtual host. By standard web server conventions, unhandled HTTP traffic is redirected via 302 Found to their mobile search portal. The destination of a 302 redirect reflects only where the misaddressed server chose to bounce the traffic.

Q2: If I configure 8.8.. or 223.5.. on my PC, will that prevent poisoning?

A: Usually no! Legacy DNS travels over unencrypted UDP port 53. Many regional ISPs employ transparent DNS proxies. Whenever a UDP packet targeting port 53 traverses an optical ONT or gateway router, hardware switches intercept and divert the query to local cache servers. Even if you configure Google DNS, you are often interacting with an ISP proxy. Only cryptographic encapsulation (DoH / DoT over port 443) can bypass intermediate interception.

Q3: My PC works now, but my smartphone on Wi-Fi still jumps to Baidu. Why?

A: Check these three hidden bypasses:

  1. IPv6 RA / DHCPv6 Leakage: Many home routers assign AdGuard Home for IPv4 DNS but continue distributing the ISP’s default IPv6 DNS! Modern smartphones prioritize IPv6, bypassing AdGuard Home entirely.
    • Fix: Point IPv6 DNS to AdGuard Home’s IPv6 address or disable IPv6 DNS announcement on the router.
  2. Mobile Browser Secure DNS Conflicts: Chrome and Safari on mobile sometimes ship with built-in “Secure DNS” that points overseas, falling back to cellular networks upon failure.
  3. Persistent Mobile OS Caches: Toggle Airplane Mode on for 10 seconds and off, or restart the device to flush the network stack.

Q4: Can I just hardcode GitHub Pages’ IP into my hosts file?

A: Strongly discouraged for production! GitHub Pages and CDN edge networks continually optimize Anycast routing and IP allocation. Hardcoding an IP into your local hosts file turns a dynamic architecture into a brittle point of failure that will break without warning during infrastructure maintenance.

Q5: Are DNSSEC and DoH the same thing? Do I need both?

A: They are complementary and protect different links of the chain.


9. Conclusion: Hardening More Than Just a Redirect

End-to-End Acceptance Standard Flowchart: Four Verification Funnels

When encountering an unexpected redirect, inexperienced operators often waste days rebuilding software, blaming cloud vendors, or chasing rumors. A disciplined engineer, however, relies on packet captures, protocol standards, and controlled baselines:

  1. Question 1: Who provided this street address? (Was DNS poisoned by intermediate transit equipment?)
  2. Question 2: Whose door did I connect to? (Does the destination IP match the origin server, and does the TLS certificate validate?)
  3. Question 3: What instruction did the door issue? (Was the 302 Found emitted by an unconfigured default virtual host?)

By decomposing network protocols into discrete stages, baffling incidents resolve into straightforward engineering tasks.

By locking down AdGuard Home with DoH upstream encryption, you do not merely fix a personal blog redirect—you erect an impenetrable digital shield across your entire home network, protecting every device from cleartext DNS tampering for good!


References and Standards

All forensics and evidence were gathered in a dedicated engineering laboratory and sanitized before publication.

  1. RFC 8484: DNS Queries over HTTPS (DoH) - Encapsulation of DNS exchanges over HTTP/2 and TLS.
  2. RFC 1035 / RFC 5905: Domain Names - Implementation and Specification - Standard domain architecture.
  3. AdGuard Home OpenAPI Specification: AdGuard Home Repository - /control/dns_config & /control/test_upstream_dns.
  4. GitHub Pages Custom Domains: Configuring a custom domain for your GitHub Pages site.
  5. MDN Web Docs: 302 Found Specification & Strict-Transport-Security (HSTS).

Published by the Margrop Engineering Team. All rights reserved. For reproduction, please cite the original author and link.

Comments

Sign in with GitHub to comment. Chinese and English versions share the same discussion. Discuss on GitHub

本文阅读量 --