GitHub 訪問加速方法

國內的 GitHub 無論是打開,還是下載都挺慢,我參考網上的方法修改 host 文件,提升了速度(這是 2020/6/12 寫的,目前有效)

1. 打開 hosts 文件

首先打開路徑 C:\Windows\System32\drivers\etc 下的 hosts 文件(可以右擊以管理員身份打開,保存不了可以右擊修改 hosts 的讀寫屬性),等會兒我們會修改該文件。

注意:

windows系統的hosts文件的位置如下:C:\Windows\System32\drivers\etc\hosts

mac/linux系統的hosts文件的位置如下:/etc/hosts在這裏插入圖片描述

2. 查詢 IP

然後打開網頁 https://www.ipaddress.com/ip-lookup

在輸入框分別輸入下面五個名稱,查詢它們對應的 IP 地址:

github.com
gist.github.com
github.global.ssl.fastly.net
assets-cdn.github.com
raw.githubusercontent.com

比如查詢 github.com 的地址,輸入後點擊 Look up
在這裏插入圖片描述
網頁會返回 IP:在這裏插入圖片描述
把這個 IP 記下來,當前頁面下拉到最底下,可以接着查詢下一個。

在這裏插入圖片描述
❗要注意:查詢第四個 assets-cdn.github.com 的 IP 時會返回四個,我們得一個個試一下哪個能用:在這裏插入圖片描述
方法是 Windows +R 打開運行,然後輸入 cmd ,點擊回車,在 cmd 裏面依次 ping 四個 IP(輸入 ping ,後面跟 IP,如果訪問太慢,ctrl + C 結束 ping),返回超時的不選,可以多試幾次,選穩定的平均時間最短的那個:在這裏插入圖片描述
最後我們就得到了五個 IP ,這都是一個個查出來的,複製別人的沒用哈:

在這裏插入圖片描述

3. 修改 hosts 文件

回到我們剛剛打開的 host 文件:

把剛剛查到的五個IP 複製到文件最末端

140.82.112.4 github.com
140.82.113.3 gist.github.com
199.232.69.194 github.global.ssl.fastly.net
185.199.111.153 assets-cdn.github.com
199.232.68.133 raw.githubusercontent.com

除了這五個,還要再加上下面的 IP,它們和第五個 IP 地址是一樣的:

199.232.68.133 cloud.githubusercontent.com
199.232.68.133 camo.githubusercontent.com
199.232.68.133 avatars0.githubusercontent.com
199.232.68.133 avatars1.githubusercontent.com
199.232.68.133 avatars2.githubusercontent.com
199.232.68.133 avatars3.githubusercontent.com
199.232.68.133 avatars4.githubusercontent.com
199.232.68.133 avatars5.githubusercontent.com
199.232.68.133 avatars6.githubusercontent.com
199.232.68.133 avatars7.githubusercontent.com
199.232.68.133 avatars8.githubusercontent.com

最後我們的 hosts 文件添加如下內容,點擊保存(保存不了就右擊文件,打開屬性修改 hosts 的讀寫權限)
在這裏插入圖片描述

4. 刷新 DNS

打開 cmd 輸入下代碼刷新 DNS:

ipconfig /flushdns

最後刷新自己的 GitHub,打開各個頁面會快一些~

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章