Bobay Stack

Networking & proxies / 2026-06-09

DNS and Traffic Splitting on a Soft Router: A Rule Set You Can Actually Maintain

Cram all traffic into one rule and nobody dares change it later. Split DNS, splitting and fallback into three layers and the rules stay alive.

4 MIN READ BY BOBAY.TOP Updated 2026-06-14 ↖ All notes
DNS and Traffic Splitting on a Soft Router: A Rule Set You Can Actually Maintain

The easiest thing to ruin on a soft router is the traffic-splitting rule set. It starts with three rules; six months later it's thirty rules that override each other, and nobody dares delete any of them, because nobody knows what deleting one would break.

Split into three layers

My current structure:

  1. Resolution layer: who looks up domain names (local dnsmasq / upstream DoH)
  2. Decision layer: which domains and which IP ranges go out which exit
  3. Fallback layer: where traffic goes by default when the decision fails

Written as three separate layers, when something breaks you can tell whether "resolution is wrong or the decision is wrong". Write them mixed together and you can only guess.

Resolution layer: local cache + a single upstream

# the key lines of dnsmasq
cache-size=4096
no-resolv
server=127.0.0.1#5335      # local DoH forwarding port

no-resolv matters: without that line, dnsmasq also reads /etc/resolv.conf, so you end up with several upstreams and both the cache and the poisoning problems show up at once.

Decision layer: domains first, IPs as the backstop

Rule order is always "specific > broad":

# write specific domains first
server=/example.com/10.0.0.2
# then broad categories
ipset=/github.com/proxy
# IP range fallback comes last

Write it the other way round and the broad rule grabs the request first, so the specific rule never takes effect. Nine times out of ten, a "rule is written but doesn't work" problem is an ordering mistake.

Fallback layer: direct by default

Default to direct rather than to proxy, for a very practical reason: when the proxy is broken, at least web pages still load, and you get a chance to fix it. Default to proxy and the moment the proxy dies, you can't even get into the admin panel.

Maintenance habits

  • Put a comment after every rule: why it was added, when it was added
  • Once a month, clear out rules that never matched (dnsmasq's query log shows this)
  • Export the config before you change anything; if you break it, copy it straight back

The value of a rule set isn't how many rules it has, but whether you can explain why each one exists.

What splitting really is

DNS-based splitting isn't as simple as "domestic goes one way, overseas goes another". The real criterion is the geographic location of the recursive result. The same domain gets different A records from different recursors, and the symptom of getting splitting wrong is: resolution is correct but the connection times out.

Three approaches

ApproachPrincipleProsCons
Domain listMatches on the list go to the proxy DNSSimple and controllableThe list needs maintaining
Dual-recursion comparisonQuery domestic and overseas once each, take the differing resultAutomaticTwice as slow
Fake-IPReturn a fake IP; the proxy forwards by domainFast, no poisoningDepends on transparent proxying

For home use I'd recommend Fake-IP with a domain list as the backstop: the vast majority of requests go through Fake-IP, and the few that need a real IP (certain games, for instance) go direct via the list.

Configuration essentials

# simplified routing logic in mosdns
- name: Domestic
  rules:
    - qname: geosite:cn
      action: forward_local
- name: Others
  rules:
    - action: forward_remote

The key point is that the domestic recursor has to be a genuine domestic DNS (Alibaba 223.5.5.5, Tencent 119.29.29.29); otherwise the splitting amounts to nothing.

Verifying that splitting is really happening

dig @192.168.1.1 www.google.com +short     # should return a Fake-IP or an overseas IP
dig @192.168.1.1 www.baidu.com +short      # should return a domestic IP
nslookup -type=A example.com 192.168.1.1

If both results fall in the Fake-IP range (198.18.x.x), the list isn't matching and everything is going down the proxy path.

One common pitfall

After a router reboot the DNS cache is empty and every request is slow for the first few minutes — that isn't a misconfiguration, it's a cold start. Adding a layer of local caching (built into mosdns, or dnsmasq's cache-size=4096) noticeably improves the first-load experience.

In one sentence: writing "where it breaks" and "how to verify it" alongside each other is more useful than writing only the config — a config can be copied, the order of the decisions can't.

iStoreOSDNStraffic splittingsoft router

References

dnsmasq documentation ↗ iStoreOS documentation ↗