去年年底開始GitHub
裏面的用戶頭像無法顯示,頁面也加載緩慢,這下快樂的日子可能一去不復返了,我們需要把相關域名加加速了。
GitHub
裏面圖片都在githubusercontent.com
域名上,我們只需要在hosts
裏面加上相關地址即可。如果你有代理,把域名加入到許可名單也可以的。
這裏我們介紹hosts
方式是如何使用的,把以下內容添加到hosts
文件中。
1. 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是通過dns查詢工具查詢得到的,你應當選擇的是延時相對較小且比較穩定的ip。
如果發現不起作用,或者速度不理想,參考查找域名IP。
2. 如何修改
這裏推薦使用 SwitchHosts!
配置hosts
,操作很簡單,支持跨平臺。
複製前面的hosts內容到軟件裏配置即可,相關介紹參考下面文章。
SwitchHosts! 還能這樣管理hosts,後悔沒早點用
2.1 Windows
hosts文件位置:C:/windows/system32/drivers/etc/hosts
。
將前文內容追加到hosts
,然後刷新DNS
緩存:
ipconfig /flushdns
2.2 Mac
hosts文件位置:/etc/hosts
。
Mac
系統下修改需要按照如下方式:
1:首先,打開(訪達)Finder。
2:使用組合鍵Shift+Command+G
打開"前往文件夾",在輸入框輸入/etc/hosts
。
3:然後就會跳轉到hosts
文件位置。
複製hosts
文件到桌面上,鼠標右鍵點擊/右擊它,選擇「打開方式」—「文本編輯」,打開這個hosts
文件,然後將你要修改的內容直接在裏面修改就好了。
然後把你修改好的hosts
文件在複製回hosts
文件的所在(文件夾下)路徑:/etc/hosts
之下替換原始的hosts
文件就好了。
注意:如果彈出密碼輸入框,你需要輸入你當前電腦登錄賬號的密碼。
最後刷新下緩存:
sudo killall -HUP mDNSResponder
3. 查找域名IP
注:2020年12月30日我實際使用IPAddress
纔可以生效,前面兩個查詢站點獲取的IP
均無法使用,各位可以都嘗試下直到生效。
前面hosts
裏面域名裏分爲兩類:
- *.githubusercontent.com
- *.github.com
*.githubusercontent.com
可以使用同一個IP
,不需要每個單獨查詢。*.github.com
未經測試,目前看是需要單獨查詢對應的IP
。