dns.fake-ip-filter invalid domain: why Clash rejects the line, and how to find which character

2026-12-03来源 dev.toEnglish

dns.fake-ip-filter is a list of domains that should not receive a fake IP. It looks like a plain list of hostnames. It is not: the entries are parsed by a pattern matcher with its own grammar, and some strings that look perfectly reasonable are rejected.

The rejection message names a character offset, not the offending entry. That single detail is why this error gets misdiagnosed as a corrupted config file or a broken update.

What fake-ip actually does

With enhanced-mode: fake-ip, the DNS module answers every A query with an address from fake-ip-range (default 198.18.0.1/16) and remembers which domain it handed out which address for. Routing decisions then have a domain name available at connect time, which is what makes domain-based rules work for traffic that never sent SNI.

Two consequences follow:

  1. Any address in that range is a placeholder. It does not route anywhere on its own.
  2. Applications that resolve a name and then connect to the literal IP will connect to 198.18.x.x. If they bypass the client's TUN or proxy, nothing answers.

The filter list exists for the second group: domains whose real address an application genuinely needs — LAN discovery, local services, anything that hands the address to a third party.

The grammar that trips people up

Entries are matched as domain patterns. The rules that matter in practice:

A leading *. is wrong. *.example.com is not the way to write "all subdomains". The matcher treats the entry as a domain and * is not valid inside a label in the position people put it.

A leading dot is the documented form. .example.com matches example.com and its subdomains. That is the one-character difference between a working filter list and a parse error.

Wildcards belong in specific positions. Some pattern types accept * as a full label (ads.*.example.com) and reject it embedded inside a label (ad*s.example.com). The second form is the one that produces the offset error.

An entry must be a domain, not a URL. https://example.com/ and example.com:8080 are both rejected — the port and scheme are not part of the grammar.

Why the error reports an offset

The parser builds a matcher per entry, and when construction fails it reports the position inside the entry where the invalid token was found. A message like invalid domain at offset 2 means: the second character of the entry is where the grammar broke.

That is actionable only if you can find which entry it refers to. Two ways:

# count entries, then bisect: comment out the second half and reload grep -n '^\s*-' config.yaml | head -40 

Bisecting a 40-entry list takes 6 reloads. It is faster than reading the file and guessing, because the entries all look valid.

If your config is generated by a subscription provider, the offending entry came from upstream and will come back on the next update. In that case the durable fix is an override: keep the provider's file unmodified and put the corrected filter list in your own extend block, so the upstream regeneration does not reintroduce the bad line.

The failure people do not expect

A filter entry that is valid but wrong produces no error at all, and a worse symptom.

If a domain is in the filter list, it resolves to a real address. Traffic to a real address is routed by IP rules, not by domain rules. So a mis-scoped filter entry — say .example.com when you meant .internal.example.com — makes an entire domain silently stop obeying the domain-based rules you wrote for it. The rules still exist, they just never match.

The test is direct: resolve the domain and look at the answer.

nslookup some.example.com 127.0.0.1 # 198.18.x.x -> fake-ip, domain rules apply # real IP -> filtered, IP rules apply instead 

That single command distinguishes "the filter is rejecting my line" from "the filter accepted my line and is now silently bypassing my rules". They produce completely different debugging paths.

A filter list that stays correct

Three habits that avoid most of this:

  • prefer the leading dot, never a leading *.
  • keep the filter list in an override block, not in the provider file
  • after any change, resolve one domain from the list and one not on it, and compare the two answers

The second one matters most over time. Provider files are regenerated; your override is not.

The index-based rejection and the silent-mis-scoping case are both worked through on a real config in fake-ip filter invalid domain, including which line the client actually reports. For the wider question of when fake-ip should be on at all, the layer-by-layer comparison is in TUN mode and fake-ip.

If you are seeing a different DNS-shaped error and are not sure which stage produced it, the error string table maps messages to stages.

原文:https://www.a8q9.cn/en/article/dns-fake-ip-filter-invalid-domain-why-clash-rejects-the-line-and-how-to-find-whi-049cc6.html

相关文章