The Problem: When GitHub Forgets the Future
Your computer uses DNS (the internet's phonebook) to translate a friendly name like github.com
into an IP address (the actual location). The problem is, sometimes the IPv6 address (2a00:...
) that the phonebook gives out for GitHub's services is either slow, misconfigured, or just broken.
When your computer tries the broken IPv6 route first and fails, it takes a long time to give up and fall back to the older, reliable IPv4 address. This causes those frustrating timeouts.
The Solution? We cut out the middleman. We'll manually tell your computer the correct IPv6 addresses for all of GitHub's key services, bypassing the faulty public DNS.
The Fix: Editing Your Hosts File
The hosts
file is a simple text file on your computer that maps hostnames to IP addresses. Your system checks this file before it asks a DNS server, so we can use it to override the broken records.
Here’s how to do it, step-by-step.
Step 1: Get the Addresses
A helpful community member has already done the legwork to find the current, working IPv6 addresses for GitHub's entire ecosystem. Here's the block of code you'll need to add to your hosts
file:
# GitHub IPv6 Workaround
2a01:4f8:c010:d56::2 github.com
2a01:4f8:c010:d56::3 api.github.com
2a01:4f8:c010:d56::4 codeload.github.com
2a01:4f8:c010:d56::6 ghcr.io
2a01:4f8:c010:d56::7 pkg.github.com npm.pkg.github.com maven.pkg.github.com nuget.pkg.github.com rubygems.pkg.github.com
2a01:4f8:c010:d56::8 uploads.github.com
2606:50c0:8000::133 objects.githubusercontent.com www.objects.githubusercontent.com release-assets.githubusercontent.com gist.githubusercontent.com repository-images.githubusercontent.com camo.githubusercontent.com private-user-images.githubusercontent.com avatars0.githubusercontent.com avatars1.githubusercontent.com avatars2.githubusercontent.com avatars3.githubusercontent.com cloud.githubusercontent.com desktop.githubusercontent.com support.github.com
2606:50c0:8000::154 support-assets.githubassets.com github.githubassets.com opengraph.githubassets.com github-registry-files.githubusercontent.com github-cloud.githubusercontent.com
Step 2: Edit the Hosts File
On Windows:
- Press
Windows Key + S
and type Notepad. - Right-click the Notepad result and select Run as administrator.
- In Notepad, click
File > Open
. - Navigate to
C:\Windows\System32\drivers\etc\
. - In the bottom-right dropdown, select All Files (.) instead of Text Documents.
- Open the file named
hosts
(with no extension). - Paste the code above at the bottom of the file.
- Save the file and close Notepad.
On macOS & Linux:
- Open your Terminal.
- Type the following command to open the hosts file with a text editor (like
nano
):sudo nano /etc/hosts
- Enter your password when prompted.
- Paste the code above at the bottom of the file.
- Press
Ctrl+X
to exit, thenY
to confirm saving, andEnter
to confirm the filename.
Step 3: Flush Your DNS Cache
The final step is to tell your computer to clear its old DNS lookups and recognize the new entries.
- Windows (Admin Command Prompt):
ipconfig /flushdns
- macOS:
sudo killall -HUP mDNSResponder
- Linux:
sudo systemctl resolvectl flush-caches
(orsudo /etc/init.d/nscd restart
on some systems)
That's it! Try accessing github.com
again. It should be snappy and responsive.
A Few Important Reality Checks
This is a fantastic band-aid, but it's not a permanent solution. Keep these points in mind:
- It's a Temporary Workaround: These IP addresses could change in the future. If GitHub updates their infrastructure, this fix might break and you'll need to find updated addresses.
- You're Bypassing DNS: The whole point of DNS is to automatically point you to the right place. By doing this, you're taking on the responsibility of maintenance.
- It's a Local Fix: This only fixes the problem on your machine. You'd need to do this on every computer where you're experiencing the issue.
This trick is a powerful example of how understanding the basics of networking gives you the tools to solve problems yourself. It’s a little bit of digital self-reliance.
Now, go forth and git commit
in peace.