OpenClash + AdGuardHome + MosDNS Complete Closed-Loop Solution: Fake-IP Enforcement, DNS Anti-Pollution, More Thorough Ad Blocking & DNS Cache Optimization

1,028 Views
6 Comments

Total 3664 characters, estimated reading time: 10 minutes.

openclash+adguarddhome+MosDNS adblock DNS anti-leakage domestic and international shunt parsingWe commonly use it for DNS ad blocking, smart triage and DNS anti-pollution features. Previously our multiple settings, includingpasswall+adguardhome+MosDNSCombined with the use of use can be stable and efficient operation, but found a problem OpenClash in the Fake-IP mode can not be effective, which is also in the previous video partner message response to this problem, did not notice before. So how much it affects certain proxy rules and access efficiency and security issues. Recently, after repeated testing and debugging, the final realization of the Fake-IP effective, DNS leakage prevention, and compared to the previous configuration AdGuardHome ad blocking effect to enhance the effect of better, with MosDNS as a DNS cache intelligent triple!make superiorObjective.

OpenClash + AdGuardHome + MosDNS Complete Closed-Loop Solution: Fake-IP Enforcement, DNS Anti-Pollution, More Thorough Ad Blocking & DNS Cache Optimization
DNS anti-pollution, this is the most basic requirement surely we don't care how we change the settings, we need to make sure that the
OpenClash + AdGuardHome + MosDNS Complete Closed-Loop Solution: Fake-IP Enforcement, DNS Anti-Pollution, More Thorough Ad Blocking & DNS Cache Optimization
addguardhome adblock works better!

This post will shareKing of Science and TechnologyTested and proven set ofComplete Closed-Loop DNS Architecture::Make Open Clash's Fake-IP work properly, Adguardhome ad blocking stronger, MosDNS caching stable and efficient, and avoid DNS pollution and duplicate resolution problems.

Of course, stating the DNS resolution logic here may be a bit controversial because theopenclashWith Mosdns self formed a closed loop, so it may also form a dead loop or parsing errors instead of lagging response, partners need to be careful to try to see if it is suitable for their own use of the scene!

Tip: Due to network restrictions, the YouTube videos on this page may not load in mainland China.
To view, please open this page in an internet environment with access to YouTube.
A full graphic description is provided below and can be read on.

✅ Core objectives

  • ✔️ Fake-IP mode back in effect to enhance proxy resolution - That's what's important here today and that's what we're going to fix.
  • ✔️ AdGuardHome ad blocking is more thorough and reduces the number of leakage - That's what's important here today and that's what we're going to fix.
  • ✔️ MosDNS acts as a transit cache and gas pedal, lightweight and efficient - This is just a test use and not unique, FYI
  • ✔️ builds a complete closed-loop link, with OpenClash making the final DNS decision, ensuring global resolution security.

🔁 Data flow logic (full closed-loop version)

The overall flow direction is as follows:

Client request
   ↓
OpenClash hijack DNS
   ↓
AdGuardHome (listening on port 533, ad blocking)
   ↓
MosDNS (listens on port 5335, caching only)
   ↓
OpenClash (listens on port 7874, final resolution)
   ↓
Upstream DNS (DoH / DoT)
OpenClash + AdGuardHome + MosDNS Complete Closed-Loop Solution: Fake-IP Enforcement, DNS Anti-Pollution, More Thorough Ad Blocking & DNS Cache Optimization
openclash's fake-ip in effect

🔧 Core Change Points:I have found after various tests that the only way to get the DNS trafficFirst import OpenClash and have it do the Fake-IP processing in order for the mode to take effect. Therefore, the key setup for the tweak is to place OpenClash at the beginning of the DNS link, and the other components are configured with that in mind, thenThe upstream of MosDNS is then set to OpenClash itself (port 7874), creating a closed loop of resolution, giving OpenClash full control over outbound/inbound, and ensuring that Fake-IP works.

📌 Detailed configuration of each component

1️⃣ OpenClash Settings

  • start using Fake-IP mode
  • start using dnsmasq Hijacking DNS requests
  • Nameserver:: Point to AdGuardHome → 127.0.0.1#533
  • Fallback DNS: Foreign encrypted DNS (e.g. tls://1.1.1.1, tls://8.8.8.8)
  • Default Nameserver:: Domestic standby (e.g. 114.114.114.114)
  • Keep listening on port 7874 as the final DNS forwarding interface

recount (e.g. results of election): OpenClash is the first hijacking entry point and the final upstream resolution exit (it's the upstream for MosDNS)

OpenClash + AdGuardHome + MosDNS Complete Closed-Loop Solution: Fake-IP Enforcement, DNS Anti-Pollution, More Thorough Ad Blocking & DNS Cache Optimization
Nameserver:: Point to AdGuardHome → 127.0.0.1#533
OpenClash + AdGuardHome + MosDNS Complete Closed-Loop Solution: Fake-IP Enforcement, DNS Anti-Pollution, More Thorough Ad Blocking & DNS Cache Optimization
Fallback DNS: Foreign encrypted DNS (e.g. tls://1.1.1.1, tls://8.8.8.8)
OpenClash + AdGuardHome + MosDNS Complete Closed-Loop Solution: Fake-IP Enforcement, DNS Anti-Pollution, More Thorough Ad Blocking & DNS Cache Optimization
Domestic Alternate (e.g. 114.114.114.114(or carrier DNS)

2️⃣ AdGuardHome Settings (ad filtering core)

  • listening port:: 533
  • The upstream DNS is set to MosDNS:127.0.0.1:5335
  • Turn off caching to let MosDNS be the caching server, turn on ad rules filtering (e.g. EasyList, AdGuard Chinese rules, etc.)

recount (e.g. results of election): AdGuardHome specializes in ad blocking and avoids hijacking and diversion duties to interfere with the effect.

OpenClash + AdGuardHome + MosDNS Complete Closed-Loop Solution: Fake-IP Enforcement, DNS Anti-Pollution, More Thorough Ad Blocking & DNS Cache Optimization

3️⃣ MosDNS setup (lightweight caching node)

  • listening port:: 5335
  • Upstream DNS Settings::127.0.0.1:7874(OpenClash's DNS listening port)
  • Shut down port 53 listening and drop dnsmasq takeover
  • Keep caching on, but don't do complex domestic and international triage logic

recount (e.g. results of election)MosDNS no longer handles domestic/foreign domains directly, but caches and forwards them to OpenClash, reducing its own burden significantly.

OpenClash + AdGuardHome + MosDNS Complete Closed-Loop Solution: Fake-IP Enforcement, DNS Anti-Pollution, More Thorough Ad Blocking & DNS Cache Optimization
The mosdns remote DNS is set to openclash listening port 7874.

✅ Effectiveness verification

Test items in the end
Fake-IP mode ✅ Normal validation with complete policy matching
Ad blocking effect ✅ Visibly enhanced and clean
DNS Triage and Contamination Treatment ✅ Stable, no contamination
MosDNS Cache Hit Rate ✅ Enhancement to reduce duplicate queries
OpenClash + AdGuardHome + MosDNS Complete Closed-Loop Solution: Fake-IP Enforcement, DNS Anti-Pollution, More Thorough Ad Blocking & DNS Cache Optimization

⚠️ Notes

  • The upstream of MosDNS must be a listening port for OpenClash.(e.g., 7874), otherwise the closed loop cannot be formed
  • Do not use conflicting ports for each component. It is recommended to use non-standard ports such as 533 / 5335.
  • If there are DNS deadlocks or failed requests, troubleshoot on a layer-by-layer basis (use the nslookup utility)
  • Disable the system's local DNS service (e.g. systemd-resolved) to avoid interference.

❗ Note the logical key points:

  • OpenClash takes over DNS for the first time: make sure Fake-IP in effectThe
  • AdGuardHome is in the middle tier: only responsible for ad blocking, no complex triage.
  • MosDNS no longer does master triage: only cache forwarding.
  • MosDNS upstream back to OpenClash: forming a “closed loop”.

✅ Why does this configuration work for internet?

This is because OpenClash takes on both:

  1. Initial DNS Hijacking Entry(handling fake-ip, validation policy)
  2. Final DNS Exit(Exit analysis via DoH/DoT)

MosDNS and AdGuardHome only play the role of “caching” and “ad cleaning” in this link, and no longer dominate the diversion and exit paths, so they do not cause DNS loops or errors.

⚠️ Possible risks or imperfections

sports event instructions
❗ Potential dead ends If OpenClash is configured to go back to AdGuardHome for resolution (such as when fallback occurs), this may cause a loop. Make sure that in OpenClash's DNS settings, theStop pointing to AdGuardHome or MosDNS! as fallback.
⚠️ MosDNS Loses Intelligent Triage MosDNS originally supported domestic/foreign judgments, but now that the upstream has been changed to OpenClash, it has “lost its intelligence” and has become a pure cache forwarder. But if you just need performance optimization, that's fine.
⚠️ Not good for troubleshooting If there is a parsing error in the link (e.g., a layer hangs), troubleshooting will be more expensive, and it is recommended to keep logs, use the dig tool to test each layer of response.

🔚 Closed-loop optimization scheme::

  • ✅ Can realize fake-ip mode
  • ✅ Enables ad blocking enhancements
  • ✅ MosDNS has cache optimization effects
  • ⚠️ Not recommended for deployment by novice users, setup with caution

The key to this program is:Making OpenClash the Start and End of DNSIn this way, Fake-IP can be restored to normal, and the whole DNS architecture is clearer, more controllable, and more flexible. In this way, not only the Fake-IP can be restored to normal and the effect of ad blocking can be improved, but also the whole DNS architecture is clearer, more controllable and flexible, which is suitable for users with high demands on the network environment.

If you also encounter DNS confusion, Fake-IP failure, ads blocking problems, you may want to try this program. Of course, please make sure to make a backup before deployment and verify it carefully in a test environment.

END
 0
Mr wang
Copyright Notice: Our original article was published by Mr wang on 2025-06-15, total 3664 words.
Reproduction Note: Unless otherwise noted, this site is distributed under a CC BY 4.0 license. Reprints please indicate the author "Technology Lao Wang" and the original source link, any unattributed reprints, remove the source or washing behavior is considered an infringement of copyright.
RackNerd Cost Effective VPS Recommendation AI Preferred by newbie website builders Stable only 10th+ Movers VPS Recommendation
Comment(6 Comments)
Loong2004

http://www.kejilaowang.com/adguardhome-mosdns-openclash/#comment-83
Hello, which option is more recommended, this one in this article, or the one in the link? Thank you for your time.

    I'll come back with a video of it again, it's experimental, there's something wrong with the logic, but it's working fine, so you can come back and give it a try.

    Oh this solution is fine, but it's just a problem, this fake-ip is not working, other than that it's normal and logical, I thought you were talking about this http://www.kejilaowang.com/openclash-adguardhome-mosdns-dns/这篇文章.

666

Tried the copy, no other problems, dns test has Hong Kong and Japan, not sure if it's a leak or not

ericjin211

Hi, tried this solution and found that foreign sites going through openclash proxy will not go through adguardhome, what could be the problem 🤔