Both servers (relay and landing) run as proxy endpoints. Clients are already configured to route China traffic directly via Surge rules. Any China-destined traffic that reaches the servers is unwanted. We need server-side enforcement to drop outbound connections to CN IP ranges.
Goals:
Non-Goals:
Use ipset to store the China CIDR list as a hash:net set, then a single iptables rule referencing the set. This is far more efficient than thousands of individual iptables rules.
Why over nftables: iptables + ipset is universally available on Ubuntu/Debian and simpler to manage via Ansible. nftables sets would also work but add migration complexity.
Use https://www.ipdeny.com/ipblocks/data/aggregated/cn-aggregated.zone for the China CIDR list. It's a widely-used, frequently updated, plain-text list of CIDR blocks.
Why over MaxMind GeoLite2: No account/license required. Plain text format is trivial to load into ipset. Aggregated format minimizes the number of entries.
A daily cron job downloads the latest CN zone file and reloads the ipset. The update script is idempotent — it creates a temporary set, swaps it atomically, then destroys the old one.
The iptables rule is inserted in the OUTPUT chain to block traffic originating from the server itself (proxy daemon forwarding). A corresponding FORWARD chain rule is not needed since these servers don't act as network routers.