4

GitHub无法访问?访问慢?一招即可搞定

 3 years ago
source link: https://www.tianheyu.top/archives/github520
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

GitHub无法访问?访问慢?一招即可搞定

武培轩 2021年03月24日 17次浏览

GitHub 是一个面向开源及私有软件项目的托管平台,程序员可以在上面探索感兴趣的项目,几乎是程序员的圣地。

最近听群里朋友说 GitHub 无法访问或者访问速度极其慢,经常打开 GitHub 变成这样:

这怎么能行呢?无疑妨碍了我们的学习之路呀。

下面我就来把我的解决方法和大家说下:

下载 SwitchHosts

首先下载 SwitchHosts,可以更方便的切换 hosts,下载地址:https://github.com/oldj/SwitchHosts/releases

考虑到 GitHub 访问不稳定,可以公众号【武培轩】回复【hosts】获取软件安装包。

下面就需要用到 GitHub 上的一个项目:GitHub520,他可以定时提供最新的 hosts 配置来使访问 GitHub 更加顺畅。

添加 hosts 规则

接下来打开 SwitchHosts,然后添加 hosts 规则:

  • 方案名(Title)随便写
  • 类型(Type)选择远程
  • URL 地址栏输入 https://cdn.jsdelivr.net/gh/521xueweihan/GitHub520@main/hosts
  • 自动更新建议选择 1 小时一更新

若不想下载 SwitchHosts 等类似软件,可以手动修改 hosts 文件,针对各个系统的文件位置是不同的,具体位置如下:

  • Windows 系统:C:\Windows\System32\drivers\etc\hosts
  • Mac 系统:/etc/hosts

在 hosts 文件中添加如下内容:

185.199.108.154 github.githubassets.com140.82.114.21 central.github.com185.199.108.133 desktop.githubusercontent.com185.199.108.153 assets-cdn.github.com185.199.108.133 camo.githubusercontent.com185.199.108.133 github.map.fastly.net199.232.69.194 github.global.ssl.fastly.net140.82.112.3 gist.github.com185.199.108.153 github.io140.82.113.3 github.com140.82.112.5 api.github.com185.199.108.133 raw.githubusercontent.com185.199.108.133 user-images.githubusercontent.com185.199.108.133 favicons.githubusercontent.com185.199.108.133 avatars5.githubusercontent.com185.199.108.133 avatars4.githubusercontent.com185.199.108.133 avatars3.githubusercontent.com185.199.108.133 avatars2.githubusercontent.com185.199.108.133 avatars1.githubusercontent.com185.199.108.133 avatars0.githubusercontent.com185.199.108.133 avatars.githubusercontent.com140.82.113.10 codeload.github.com52.217.78.204 github-cloud.s3.amazonaws.com52.216.162.99 github-com.s3.amazonaws.com52.217.96.204 github-production-release-asset-2e65be.s3.amazonaws.com52.217.97.236 github-production-user-asset-6210df.s3.amazonaws.com52.217.194.41 github-production-repository-file-5c1aeb.s3.amazonaws.com185.199.108.153 githubstatus.com64.71.168.201 github.community185.199.108.133 media.githubusercontent.com

如果已经失效,可以公众号【武培轩】回复【hosts】获取最新的 hosts。

大部分情况下是直接生效,如未生效可尝试下面的办法,刷新 DNS:

  1. Windows:在 CMD 窗口输入:ipconfig /flushdns
  2. Linux 命令:sudo rcnscd restart
  3. Mac 命令:sudo killall -HUP mDNSResponder

相信大家通过上述方法配置后,就可以顺畅地访问 GitHub 了!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK