GeoIP and GeoSite Databases: Update URLs, Automatic Updates, and Rule Syntax
Learn what GeoIP and GeoSite data files do, how to configure geox-url and automatic updates, and how to write common category rules.
What GeoIP and GeoSite Match
GEOIP classifies the destination IP address, while GEOSITE classifies the destination domain. Using CN in both rules does not mean they match the same things: a domain may be in the cn domain category while DNS returns an overseas CDN address; the same CDN address may also host domains from multiple categories. The databases provide category classifications—they do not measure a server’s physical location or the network path.
| Rule | Matches | mihomo data source |
|---|---|---|
GEOIP,CN,DIRECT | Destination IPv4 or IPv6 address | geox-url.mmdb or geox-url.geoip, depending on geodata-mode |
GEOSITE,cn,DIRECT | Destination domain | geox-url.geosite, which points to geosite.dat here |
For a connection with only a destination IP and no original domain available to the core, GeoSite cannot classify it by domain. Conversely, to apply GeoIP to a connection with only a domain, the core first needs the destination IP. A standard GEOIP rule may trigger a DNS lookup to get it. Adding no-resolve prevents the rule from initiating a lookup, but it can still use a destination IP that is already available when matching.
geox-url Update URLs and File Formats
Add the following fields at the top level of your mihomo config, alongside rules. This example uses release assets from MetaCubeX’s meta-rules-dat. Each key points to a different data source: mmdb for an MMDB file, geoip for a GeoIP DAT file, and geosite for a GeoSite DAT file. Don’t enter a release page URL or a rule-set URL intended for rule-providers here.
geodata-mode: false
geo-auto-update: true
geo-update-interval: 24
geox-url:
mmdb: "https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/country.mmdb"
geoip: "https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip.dat"
geosite: "https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geosite.dat"
geodata-mode: false: GeoIP uses MMDB, which meanscountry.mmdbin this example. Even ifgeox-url.geoipis also set, GeoIP matching won’t use the DAT file at that URL.geodata-mode: true: GeoIP switches to the DAT file specified bygeox-url.geoip. GeoSite continues to usegeox-url.geosite; this switch does not change its file format.geo-auto-update: trueenables scheduled updates in the core.geo-update-interval: 24is measured in hours, so updates run every 24 hours—not at midnight local time each day. Scheduled tasks won’t run while the core is stopped.
The target of latest changes with each release, and category membership may change over time. To reproduce the same rule results across multiple devices, use asset URLs with an explicit version from the same release, and record the current version before changing the URLs. Changing a URL does not replace files already on disk; check the actual update logs and subsequent connection results.
How to Verify Automatic Updates
- First, make sure you’re editing the active config. A GUI client may apply local overrides after importing a subscription. If it supports config overrides, put the top-level fields above in a persistent override and reload the current config. Direct edits to a subscription-generated file may be overwritten the next time the subscription refreshes. If the existing config already has
geox-url, merge in its child keys instead of declaring the top-level key again. - Test the config before running the core separately. Put the config under test in a dedicated test directory, then run the command below from its parent directory.
-dspecifies the test working directory;-fspecifies the config file. The test may read or download data required by the rules. Passing only confirms that the config loads under the current test conditions; it does not mean a scheduled update has run successfully. - Check database updates and rule matches separately. After reloading the config, check the core logs for GeoIP and GeoSite download, loading, or error messages. If the client has a Geo data update option, use it to trigger a test update, then make a new connection and check which rule matched. A successful subscription refresh, node latency test, or
rule-providersupdate does not prove that the databases were updated.
mihomo -v
mihomo -t -d ./mihomo-test -f ./mihomo-test/config.yaml
If a download times out, first confirm that the device running the core can reach the full HTTPS URL in the config, as well as the URL it redirects to. Opening a GitHub release page in a browser only confirms that the page is accessible; it does not prove the core can download the asset over its own network path. If the file downloaded but failed to load, check that the key matches the file format, then check whether geodata-mode changed. Shortening the update interval won’t fix a format mismatch.
GEOSITE vs. GEOIP Rule Order
In rule mode, mihomo checks rules from top to bottom, and the first match determines the policy. The example below puts a single-domain suffix rule first, followed by domain categories, then an IP category, and finally a catch-all. PROXY must be the name of an existing policy group or outbound; replace it with the name used in your config. When adapting this for an existing subscription, edit the current rules list rather than adding a second list with the same name.
rules:
- DOMAIN-SUFFIX,example.com,DIRECT
- GEOSITE,cn,DIRECT
- GEOIP,CN,DIRECT,no-resolve
- MATCH,PROXY
DOMAIN-SUFFIX,example.com,DIRECTmatchesexample.comand its subdomains. Since it comes first, it doesn’t depend on whether GeoSite includes the domain. In a real config, put exceptions that need to override broader category policies before those category rules.GEOSITE,cn,DIRECTsends traffic directly based on thecncategory in the selected database. This is not the same asDOMAIN-SUFFIX,cn,DIRECT: the former uses a category list, while the latter matches domain suffixes.GEOIP,CN,DIRECT,no-resolveclassifies the destination IP if one is already available. If neither of the first two rules matches and there’s no destination IP at match time, this rule is skipped. To also try resolving the domain and classifying its IP when no domain rule matches, removeno-resolve—but be aware that this adds DNS queries and may produce different policies depending on the resolution results.MATCH,PROXYcatches connections that didn’t match earlier rules. It belongs at the end; rules added after it won’t change the policy already selected for those connections.
These rules illustrate category precedence; they don’t mean every network should send this traffic directly. If an app or service needs a specific outbound, add an exception for its explicit domain first. A GeoIP exception for a shared CDN address may also change the outbound used by other sites on that address.
Troubleshooting Rule Matches
Start testing with a request whose expected result is known. If the current config uses mixed-port 7890, the listener is reachable through the local loopback address, and the client is in rule mode, send the request below. If the port is different, replace it with the actual port. The command sends the request through the local proxy listener; the connections panel should show the DOMAIN-SUFFIX rule and DIRECT policy. Here, DIRECT means the core chose to connect directly to the destination—not that the request bypassed the local client.
curl --proxy http://127.0.0.1:7890 --max-time 15 https://example.com/
- Even the single-domain rule doesn’t match: First check whether the new request appears in the connections panel, then verify the listening port, rule mode, and active config. If an earlier rule already matched, fix the rule order and retry with a new connection.
- The single-domain rule matches, but GeoSite doesn’t: Choose another domain confirmed to be in the
cncategory of the data source in use, and make sure no earlier rule catches it. Check whether the panel shows a domain or only an IP, and look for errors in the logs indicating that the category wasn’t found. After changing data sources, verify the category name—different datasets may include different domains. - GeoSite works, but GeoIP always falls through: Check whether a destination IP is available at match time and how that address is classified in the current MMDB or DAT file. With
fake-ip, don’t mistake the synthetic address shown on the device for the real address of the destination server. If the rule usesno-resolve, being able to access a domain does not prove that a real destination IP was available when the rule was evaluated.
When comparing results before and after an update, record the request target, matched rule, policy, and data source. Change one variable at a time: verify the single-domain rule first, then the domain category, and finally the IP category. This helps distinguish a data file that wasn’t updated from changed category membership, an earlier rule intercepting the connection, or missing information needed for a match.