Resolve domains by latency, not CDN zones.
This tool retrieves DNS records from Globalping, selects IPs with lowest latency, and updates the hosts file.
-
Download from Releases.
For example:
sudo wget https://github.com/Zhousiru/opti-hosts/releases/download/latest/opti-hosts-x86_64-unknown-linux-gnu -O /usr/local/bin/opti-hosts sudo chmod +x /usr/local/bin/opti-hosts
-
Add directives in your
/etc/hosts
:# ... # OPTI-HOSTS example.com [Beijing, HK * 2, AS6939] # HINT: Record for example.com will be generated here. # ...
-
Run:
sudo opti-hosts sudo opti-hosts --dry-run # Preview changes
-
Add to your crontab (recommend):
0 */12 * * * opti-hosts
# OPTI-HOSTS <Domain> [<Location> * <Limit>, <Location>, ...]
-
Domain
The domain you want to resolve.
-
Location
The geographic location or network from which you want to resolve the domain.
See Globalping Network, or try it on Globalping.
-
Limit
The maximum number of nodes to use for a particular location.
Defaults to 1.
opti-hosts [OPTIONS]
Options:
--dry-run Preview outputs without making any changes to hosts file
--file <FILE> Hosts file path [default: /etc/hosts]
-h, --help Print help
-V, --version Print version