How to Manually and Automatically Modify the Hosts File to Speed Up GitHub Access
This guide explains why GitHub is slow in China due to DNS latency, shows how to manually edit the hosts file on various platforms, and demonstrates using the SwitchHosts tool to automate hosts updates, refresh DNS caches, and ensure reliable access to GitHub resources.
GitHub access in China is often hindered by slow DNS resolution, so editing the local hosts file to map github.com to a fast IP is a common workaround.
The article first describes manual modification of the hosts file for Windows ( C:\Windows\System32\drivers\etc\hosts ), Linux ( /etc/hosts ), macOS ( /etc/hosts ), Android ( /system/etc/hosts ), and iOS ( /etc/hosts ), instructing users to append the provided entries to the file.
After editing, the changes usually take effect immediately; if not, the DNS cache can be flushed using platform‑specific commands:
Windows: ipconfig /flushdns
Linux: sudo rcnscd restart
macOS: sudo killall -HUP mDNSResponder
If flushing does not work, a system reboot is recommended.
For a more convenient solution, the article recommends the SwitchHosts tool. Install it from the official release page or via a package manager, e.g., on Manjaro: paru -S switchhosts-bin .
After installation, add a new rule in SwitchHosts with a title, type Remote , and the URL https://cdn.jsdelivr.net/gh/521xueweihan/GitHub520@main/hosts . Set the auto‑refresh interval (initially 1 minute, then 1 hour).
When launching SwitchHosts from the menu, adding new rules may fail due to permission issues. Running it with sudo resolves this: sudo switchhosts . If it still fails, add the --no-sandbox flag: sudo switchhosts --no-sandbox . Ensure any previous non‑sudo instance is closed to avoid port conflicts.
Once SwitchHosts runs with elevated privileges, it can modify the hosts file automatically without further password prompts.
After configuration, DNS queries for GitHub are resolved quickly, allowing normal access to GitHub images and resources.
The article concludes with a brief note that an alternative automated DNS solution, AdGuard Home, is also mentioned in the referenced repository.
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.