一、原因分析
GitHub的服务器远在美国,直接通过域名访问其资源。将经过
- 本地DNS服务器
- DNS根服务器
- .com域服务器
- githubusercontent.com域服务器
等四个步骤才可以获取到真正的公网IP地址,所以容易产生timeout。
若对网络流程感兴趣可以看看这篇文章:
二、解决办法
1.找到IP地址查询网址
The Best IP Address, Email and Networking Tools - IPAddress.comhttps://www.ipaddress.com在该网站输入raw.githubusercontent.com,查询结果显示IP address有4个IPv4和4个IPv6。
往下寻找,找到实际的IP address
2.更新host文件
使用终端命令打开host文件:
#还可以在finder中选择前往文件夹:/etc/hosts
open ~/../../private/etc/hosts
在host文件末尾添加以下内容(左边的IP地址请填入IP address查询到的实际地址)
185.199.108.133 raw.githubusercontent.com
185.199.109.133 raw.githubusercontent.com
185.199.110.133 raw.githubusercontent.com
185.199.111.133 raw.githubusercontent.com
2606:50c0:8000::154 raw.githubusercontent.com
2606:50c0:8001::154 raw.githubusercontent.com
2606:50c0:8002::154 raw.githubusercontent.com
2606:50c0:8003::154 raw.githubusercontent.com