OpenClash + MosDNS + AdGuard Home Configuration: DNS Traffic Splitting, Ad Blocking, and Leak Detection

.hcb_wrap.hcb_wrap{–hcb–bgc:#0d1117;–hcb–c:#e6edf3;–hcb–ff:”Consolas”,” Menlo”, ”Courier New”, monospace; –hcb–data-label–bgc:#161b22; –hcb–data-label–c:#8b949e; –hcb–line-numbers–c:#484f58;–hcb–scbar-track–bgc:#161b2280;–hcb–scbar-thumb–bgc:#30363d}
.hcb_wrap.hcb_wrap>pre,.hcb_wrap.hcb_wrap>pre>code { background: #0d1117; color: #e6edf3; text-shadow: none!important; -webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;letter-spacing:0;font-weight:400!important}
.hcb_wrap :is(code,span){font-weight:400!important;font-style:normal!important;text-shadow:none!important}
.hcb_wrap .token.comment, .hcb_wrap .token.prolog, . hcb_wrap .token.doctype, .hcb_wrap .token.cdata, .hcb_wrap .token.punctuation { color: #8b949e }
.hcb_wrap .token.keyword, .hcb_wrap .token.boolean, .hcb_wrap .token.selector, .hcb_wrap .token.tag { color: #ff7b72 }
.hcb_wrap .token.string, .hcb_wrap .token.attr-value, .hcb_wrap .token.char { color: #a5d6ff }
.hcb_wrap .token.function, .hcb_wrap .token.class-name { color: #d2a8ff }
.hcb_wrap .token.number, .hcb_wrap .token.constant, .hcb_wrap .token.symbol, hcb_wrap .token.operator, hcb_wrap .token.entity, hcb_wrap .token.url { color: #79c0ff; background: transparent }
.hcb_wrap .token.property, .hcb_wrap .token.attr-name, .hcb_wrap .token.atrule, .hcb_wrap .token.keyword.def { color: #7ee787 }
.hcb_wrap .token.variable, .hcb_wrap .token.regex, .hcb_wrap .token.important { color: #ffa657 }
.hcb_wrap .hcb-clipboard { opacity: .85 }

In this age of rampant advertising and rampant DNS poisoning, browsing the web has become a “high-risk activity.” You think you’re clicking on a web page, but a pop-up appears instead; you try to visit a legitimate website, but your DNS is hijacked and redirected to some mysterious server. Privacy leaks, tracking scripts, and ISP-injected ads—it’s all impossible to guard against.

DNS Anti-Censorship
DNS Leak Protection

As a result, the “ultimate trio” consisting of OpenClash, mosDNS, and AdGuardHome has become the top choice for an increasing number of people looking to improve their internet experience. They each play one of three roles:

  • AdGuard Home: The client's first line of defense, filtering out advertising domains, trackers, and malicious links;
  • mosDNS: Central Dispatch Center, intelligently selects upstream DNS servers, supports encryption, traffic shunting, and caching to prevent contamination;
  • OpenClash: Traffic Controller—determines which data is routed through the proxy and which is sent directly, ensuring both unrestricted access and optimal speed.

Here’s how the entire process works: The device first sends the DNS request to AdGuardHome, which filters out a wave of spam before passing it on to mosDNS. mosDNS then encrypts the query and prevents tampering, and finally, OpenClash determines the route to ensure that “traffic is routed through a VPN when necessary and connects directly when appropriate.”

DNS Unlock Configuration

This architecture doesn't rely on gimmicks; it simply aims to be clean, efficient, and controllable. It isn't a magic solution to speed things up—it's a tool that gives you freedom and order.

If you have even the slightest expectations for the internet and don’t want to continue passively accepting “ads, restrictions, and a lack of transparency,” then it’s time to consider establishing your own network sovereignty.

AdGuard Home Filter Rules

???? One-Sentence Summary:

Use the combination of OpenClash, mosDNS, and AdGuardHome to build an all-in-one network system that blocks ads, prevents DNS poisoning, and provides VPN routing, making your online experience cleaner, freer, and more controllable.

???? Three-Part Logical Relationship Diagram (Text Version):

[Client Device]
│
▼
[AdGuardHome]
Blocks ads and tracking domains; allows clean requests
│
▼
[mosDNS]
Smart traffic routing across multiple upstreams, encrypted queries, and protection against traffic tampering
│
▼
[OpenClash]
Detects whether to use a proxy, allowing for flexible outbound routing or direct local connections
│
▼
[Final DNS Results & Network Access]

Original link: Old Wang's Tech Blog https://kejilaowang.com/openclash-mosdns-adguardhome-dns/

Related Reading:

First, clearly illustrate the DNS data flow.

The most common issue with three-piece suites isn’t a lack of functionality, but rather confusion regarding upstream and downstream relationships. It is recommended to maintain only a single client-facing entry point—for example, having AdGuard Home listen on port 53 on the local area network, then forwarding clean requests to MosDNS, and finally routing them to domestic servers or upstream proxies based on rules. When OpenClash handles domain name resolution, it should use a distinct, dedicated listening port to avoid creating a loop by routing back to the entry point.

Example of Port Planning

Components Sample Listener Uses
AdGuard Home LAN:53 Client Access, Filtering, and Logging
MosDNS 127.0.0.1:5335 Caching, Traffic Distribution, and Upstream Selection
OpenClash DNS 127.0.0.1:7874 Proxy-Related Domain Name Resolution

The ports are used for illustrative purposes only; the actual configuration should be based on the device's current listening status.

How do I choose ad-blocking rules?

More rules aren’t necessarily better. Duplicate rules increase memory usage and maintenance costs, and false positives can cause issues with login, payment, or application interfaces. Prioritize maintaining an active, clearly documented base list; when a false positive occurs, check the query logs first, then add an allow rule for the specific domain.

DNS Leak Check

  • Verify that the IPv4 and IPv6 DNS addresses assigned by DHCP both point to the expected entry point.
  • Verify that the browser's “Secure DNS” feature does not bypass local policies.
  • Use the query log to verify the components through which a request passed and its final upstream source.
  • Clear the caches on the client, browser, dnsmasq, and other components, then retest.

Original article by Tech.laowang. If you wish to repost this article, please credit the source: https://techlaowang.com/en/openclash-mosdns-adguardhome-dns-ad-tools/

Like (0)
Tech.laowang's profile pictureTech.laowang
Previous March 29, 2025, 12:06 p.m.
Next April 12, 2025, 4:38 a.m.

Related Recommendations

Explore the world of technology and gain access to software solutions and expert insights on accessing the internet from abroad—your trusted technology resource platform!