国内网络访问 Github 速度过慢的原因有许多,但其中最直接和原因是其 CND 域名遭到 DNS 污染,导致我们无法连接使用 GitHub 的加速服务,因此访问速度缓慢。简单理解:CDN「Content Delivery Network」,即内容分发网络,依靠部署在各地的边缘服务器,平衡中心服务器的负荷,就近提供用户所需内容,提高响应速度和命中率。DNS 污染,是指一些刻意或无意制造出来的数据包,把域名指向不正确的 IP 地址,阻碍了网络访问。我们默认从目标网址的最近 CDN 节点获取内容,但当节点过远或 DNS 指向错误时,就会操成访问速度过慢或无法访问的问题。
2023-04-16T04:16:32.png

方案一:修改本地Hosts文件
1.打开Hosts文件
hosts 文件在每个系统的位置不一,详情如下:

Windows 系统:C:\Windows\System32\drivers\etc\hosts
Linux 系统:/etc/hosts
Mac(苹果电脑)系统:/etc/hosts
Android(安卓)系统:/system/etc/hosts
iPhone(iOS)系统:/etc/hosts

2023-04-16T04:16:51.png

Windows 使用记事本编辑。
Linux、Mac 使用 Root 权限:sudo vi /etc/hosts。
iPhone、iPad 须越狱、Android 必须要 root。
2.修改方法,把下方的内容复制到文本末尾(需要管理员权限修改):

hosts最新代码链接:https://raw.hellogithub.com/hosts(ps:代码不定时更新),获取最新对应的host配置。
如果需要工具自动更新的话,链接:https://github.com/oldj/SwitchHosts

# GitHub520 Host Start
140.82.113.4                  alive.github.com
140.82.113.4                  live.github.com
35.89.211.130                 github.githubassets.com
140.82.113.4                  central.github.com
35.91.205.163                 desktop.githubusercontent.com
140.82.113.4                  assets-cdn.github.com
54.187.119.73                 camo.githubusercontent.com
151.101.1.6                   github.map.fastly.net
151.101.1.6                   github.global.ssl.fastly.net
140.82.113.4                  gist.github.com
185.199.108.153               github.io
140.82.113.4                  github.com
192.0.66.2                    github.blog
140.82.113.4                  api.github.com
54.187.192.31                 raw.githubusercontent.com
18.237.195.231                user-images.githubusercontent.com
52.25.220.42                  favicons.githubusercontent.com
35.90.114.155                 avatars5.githubusercontent.com
35.91.205.163                 avatars4.githubusercontent.com
54.187.119.73                 avatars3.githubusercontent.com
34.217.211.252                avatars2.githubusercontent.com
54.68.45.78                   avatars1.githubusercontent.com
35.90.114.155                 avatars0.githubusercontent.com
52.25.220.42                  avatars.githubusercontent.com
140.82.113.4                  codeload.github.com
72.21.206.80                  github-cloud.s3.amazonaws.com
72.21.206.80                  github-com.s3.amazonaws.com
72.21.206.80                  github-production-release-asset-2e65be.s3.amazonaws.com
72.21.206.80                  github-production-user-asset-6210df.s3.amazonaws.com
72.21.206.80                  github-production-repository-file-5c1aeb.s3.amazonaws.com
185.199.108.153               githubstatus.com
140.82.114.18                 github.community
52.224.38.193                 github.dev
140.82.113.4                  collector.github.com
54.202.167.66                 pipelines.actions.githubusercontent.com
35.92.254.178                 media.githubusercontent.com
54.214.143.191                cloud.githubusercontent.com
54.214.169.83                 objects.githubusercontent.com
13.107.219.40                 vscode.dev


# Update time: 2022-10-09T14:09:11+08:00
# Update url: https://raw.hellogithub.com/hosts
# Star me: https://github.com/521xueweihan/GitHub520
# GitHub520 Host End

2023-04-16T04:17:18.png
3.刷新 DNS(大部分情况下是直接生效,未生效则尝试本办法)
Windows:在 CMD 窗口输入:ipconfig /flushdns
Linux 命令:sudo nscd restart,如报错则须安装:sudo apt install nscd 或 sudo /etc/init.d/nscd restart
Mac 命令:sudo killall -HUP mDNSResponder
2023-04-16T04:17:38.png
Tips: 上述方法无效可以尝试重启机器。
PS:若无法修改hosts则需要修改权限:
对hosts文件右击点属性,(保证常规/属性/只读取消勾选)安全/高级/更改权限/添加/选择主体/高级/查找(可WIN+R cmd查看你的账户名)然后选择你的账户名,剩下就是应用和确定了。
方案二:使用Github镜像或加速网站
通过GitHub 镜像访问。这里提供几个最常用的镜像地址:

https://gitclone.com/ (此镜像是直接搜索相关仓库,然后克隆)
https://ghproxy.com/ (GitHub 文件 , Releases , archive , gist , raw.githubusercontent.com 文件代理加速下载服务)
https://toolwa.com/github/ (GitHub 加速下载)
https://ghproxy.qystudio.ml/
https://ghdl.feizhuqwq.cf/
https://pd.zwc365.com/
https://gh.api.99988866.xyz/

2023-04-16T04:17:57.png

也就是说上面的镜像就是一个克隆版的 GitHub,你可以访问上面的镜像网站,网站的内容跟 GitHub 是完整同步的镜像,然后在这个网站里面进行下载克隆等操作。
注意是否已失效,当然也可搜索其他的镜像网址或加速网站。

方案三:安装浏览器Github 插件
①FasterHosts 是个 Chrome 插件,主要原理是拦截浏览器的某些请求,将 domain 替换成访问速度较快的那个。hosts 资源来自 GitHub520,每 1 小时更新一次。
1.下载 FasterHosts(https://github.com/gauseen/faster-hosts/archive/master.zip )然后解压,找到 extension 子目录
2.打开 Chrome,输入: chrome://extensions/
3.打开「开发者模式」
4.选择「加载已解压的扩展程序」,然后定位到刚才解压的文件夹里面的 extension 目录,确定
这就安装好了,关闭「开发者模式」
②FAST-GitHub插件
1.进入官网地址:https://fhefh2015.github.io/Fast-GitHub/
2.选择对应浏览器安装插件。
2023-04-16T04:18:22.png
3.添加拓展即可使用。

方案四:通过 Gitee 中转 fork 仓库下载。
1.先访问要下载的仓库的地址,点击fork (fork会把这个仓库复制一份到你的github账号的名下)。
2023-04-16T04:18:44.png
2.访问 gitee 网站:https://gitee.com/ 并登录,在顶部选择“从 GitHub/GitLab 导入仓库”。在导入页面中粘贴你的Github仓库地址,导入即可。
2023-04-16T04:19:12.png
3.接着选择我们需要下载或浏览的项目导入,等待几十秒一般就从GitHub上复制过来了,然后我们就可以浏览代码或者下载仓库文件了。

方案五:使用FastGithub加速器
项目GitHub地址:https://github.com/dotnetcore/FastGithub
下载releases地址:https://github.com/dotnetcore/fastgithub/releases
2023-04-16T04:19:33.png

解压后双击运行FastGithub.UI.exe,即可享受加速。
2023-04-16T04:20:33.png

与其埋怨世界,不如改变自己。管好自己的心,做好自己的事,比什么都强。人生无完美,曲折亦风景。

发表评论