由于某些原因,國(guó)內(nèi)訪問(wèn)Github會(huì)異常緩慢吊圾,在clone倉(cāng)庫(kù)時(shí)甚至只有10k以下的速度达椰,下載半天有時(shí)還會(huì)失敗需要從頭再來(lái),甚是讓人惱火项乒。
本文介紹通過(guò)修改系統(tǒng)hosts文件的辦法啰劲,繞過(guò)國(guó)內(nèi)dns解析,直接訪問(wèn)GitHub的CDN節(jié)點(diǎn)檀何,從而達(dá)到加速的目的蝇裤。不需要科學(xué)上網(wǎng),也不需要海外的服務(wù)器輔助频鉴。
1 獲取GitHub官方CDN地址
打開(kāi)https://www.ipaddress.com/
查詢(xún)以下三個(gè)鏈接的DNS解析地址
- github.com
- assets-cdn.github.com
- github.global.ssl.fastly.net
記錄下查詢(xún)到的IP地址栓辜。
2 修改系統(tǒng)Hosts文件
打開(kāi)系統(tǒng)hosts文件(需管理員權(quán)限)。
路徑:C:\Windows\System32\drivers\etc
在末尾添加三行記錄并保存垛孔。(需管理員權(quán)限藕甩,注意IP地址與域名間需留有空格)
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
192.30.253.112 github.com
151.101.72.133 assets-cdn.github.com
151.101.193.194 github.global.ssl.fastly.net
3 刷新系統(tǒng)DNS緩存
Windows+X 打開(kāi)系統(tǒng)命令行(管理員身份)或powershell
運(yùn)行 ipconfig /flushdns 手動(dòng)刷新系統(tǒng)DNS緩存。
現(xiàn)在打開(kāi)Github周荐,clone一個(gè)項(xiàng)目到本地試試吧狭莱。