解決GitHub網頁githubusercontent地址無法訪問問題


不知道什么時候開始,GitHub里面的圖片也無法加載出來,本來頁面也加載緩慢,這下更是雪上加霜,好在還是有簡單的方式加速GitHub的訪問。

通過設置hosts就是一個低成本的方案, GitHub里面圖片都在githubusercontent.com域名下,我們只需要在hosts里綁定域名和對應的IP。

1. hosts內容

hosts文件內容如下:

# 2020年12月30日更新

# GitHub Start
52.74.223.119     github.com
52.74.223.119   gist.github.com
54.169.195.247   api.github.com
185.199.111.153   assets-cdn.github.com
199.232.96.133    raw.githubusercontent.com
199.232.96.133    gist.githubusercontent.com
199.232.96.133    cloud.githubusercontent.com
199.232.96.133   camo.githubusercontent.com
199.232.96.133   avatars0.githubusercontent.com
199.232.96.133    avatars1.githubusercontent.com
199.232.96.133   avatars2.githubusercontent.com
199.232.96.133    avatars3.githubusercontent.com
199.232.96.133    avatars4.githubusercontent.com
199.232.96.133    avatars5.githubusercontent.com
199.232.96.133    avatars6.githubusercontent.com
199.232.96.133    avatars7.githubusercontent.com
199.232.96.133    avatars8.githubusercontent.com
199.232.96.133  user-images.githubusercontent.com
185.199.109.154   github.githubassets.com
# GitHub End

如果發現沒有作用,或者速度不理想,參考查找IP更新下對應的IP地址。

2. 如何修改 hosts

2.1 Windows

hosts文件位置:C:/windows/system32/drivers/etc/hosts

將前文內容追加到hosts,然后刷新DNS緩存:ipconfig /flushdns

2.2 macOS

hosts文件位置:/etc/hosts

macOS系統下修改需要按照如下方式:

  1. 首先,打開(訪達)Finder。
  2. 使用組合鍵Shift+Command+G打開"前往文件夾",輸入框中輸入/etc/hosts
  3. 然后就會跳轉到hosts文件位置。

復制hosts文件到桌面上,鼠標右鍵右擊它,選擇「打開方式」—「文本編輯」,打開這個hosts文件,然后將你要修改的內容直接在里面修改就好了。

然后把你修改好的hosts文件替換掉:/etc/hosts 文件。

注意:如果彈出密碼輸入框,你需要輸入你當前電腦登錄賬號的密碼。

最后刷新緩存:sudo killall -HUP mDNSResponder

3. 查找IP

http://tool.chinaz.com/dns
https://site.ip138.com
https://www.ipaddress.com

注:2020年12月30日我實際使用IPAddress才可以生效,前面兩個查詢站點獲取的IP均無法使用,各位可以都嘗試下直到生效。

前面hosts里面域名里分為兩類: http://githubusercontent.com -- http://github.com

*.githubusercontent.com可以使用同一個IP,不需要每個單獨查詢。*.github.com未經測試,目前看是需要單獨查詢對應的IP。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM