🔥彻底解决 github 无法访问或者访问慢的问题

426 阅读3分钟

前言

最近有小伙伴在后台给我私信说通过我的这篇文章🔥如何使用 github 安装 ohmyzsh讲解,也去尝试了其中的方法,但是在访问 github 时出现了访问不了的问题,git clone 时出现了超时问题,尝试访问 github 网站也访问不了,偶尔能加载出来也是要等很长时间。

原因

首先我们要明白是什么原因造成了访问不了或者访问慢的问题:

  • DNS解析问题DNS 解析不稳定或者被污染,导致无法正常解析 github 的域名。可以通过 ping github.com 命令获取 githubIP 地址,并在本地 hosts 文件中进行配置。
  • 网络限制问题:某些地区,网络限制可能导致无法访问 github 。可以尝试在合理合法合规的前提下使用 VPN 或者代理服务器进行访问。
  • GitHub服务端问题:有时 github 的服务器可能出现故障或维护,导致无法访问或者访问过慢的问题。可以管制 github 的官方状态页面以获取最新消息。
  • Hosts文件问题Hosts 文件可能被意外修改或者损坏,导致无法正确映射到 github 域名。可以尝试重新配置 Hosts 文件。
  • 客观原因github 服务器主要位于国外尤其是美国,由于实际距离就比较远,且也受限与网络环境是否拥堵以及网络路由节点是否繁忙或者稳定,也会造成不可访问或者访问较慢。可以尝试使用国内的教育机构或组织提供的 github 镜像服务。

解决方法

简单看了下网上有很多解决方法,比如:

  • 使用 fastgithub 工具:下载并运用 fastgithub,它会自动启动反向代理,可以显著改善 github 的访问速度。
  • 修改 Hosts 文件:在命令行工具中使用 ping github.com 命令获取githubIP 地址,并在本地 hosts 文件中进行配置 IP地址 github.com
  • 使用网络加速器:有很多网络加速器也可以加速 github 的访问,推荐比较多的是 Watt Toolkit

推荐的方法 github520

比较推荐的方式是修改 Hosts 的方式,个人觉得是最简单的方式也比较好操作的方式。其中在 github520 这个仓库有详细的介绍。这里可能有些小伙伴因为无法访问 github 看不到具体的操作方法,我这边将操作步骤整理一下:

  1. 下载 switchhosts 工具

打开下载地址 https://switchhosts.vercel.app/zh,下载指定系统版本的 switchhosts 并安装运行。

image.png

  1. 打开并运行工具添加 github520 的配置
  • Hosts 类型: 远程(Remote
  • Hosts 标题: 自命名即可, 如 GitHub520
  • URLhttps://raw.hellogithub.com/hosts
  • 自动刷新: 推荐是 1 小时

image.png

如上操作之后就可以访问 github 了。

如果有小伙伴不想安装 switchhosts 这个工具,也可以直接修改 Hosts 文件。直接访问 https://raw.hellogithub.com/hosts 会下载一个 github520 的配置 hosts 文件。内容如下:

# GitHub520 Host Start
140.82.112.26                 alive.github.com
140.82.114.6                  api.github.com
185.199.110.153               assets-cdn.github.com
185.199.109.133               avatars.githubusercontent.com
185.199.111.133               avatars0.githubusercontent.com
185.199.108.133               avatars1.githubusercontent.com
185.199.111.133               avatars2.githubusercontent.com
185.199.108.133               avatars3.githubusercontent.com
185.199.108.133               avatars4.githubusercontent.com
185.199.111.133               avatars5.githubusercontent.com
185.199.111.133               camo.githubusercontent.com
140.82.113.21                 central.github.com
185.199.111.133               cloud.githubusercontent.com
140.82.112.10                 codeload.github.com
140.82.112.21                 collector.github.com
185.199.109.133               desktop.githubusercontent.com
185.199.111.133               favicons.githubusercontent.com
140.82.112.4                  gist.github.com
52.216.144.211                github-cloud.s3.amazonaws.com
16.182.107.17                 github-com.s3.amazonaws.com
16.182.37.57                  github-production-release-asset-2e65be.s3.amazonaws.com
52.216.54.185                 github-production-repository-file-5c1aeb.s3.amazonaws.com
52.216.37.105                 github-production-user-asset-6210df.s3.amazonaws.com
192.0.66.2                    github.blog
140.82.113.3                  github.com
140.82.113.18                 github.community
185.199.110.154               github.githubassets.com
151.101.193.194               github.global.ssl.fastly.net
185.199.109.153               github.io
185.199.111.133               github.map.fastly.net
185.199.109.153               githubstatus.com
140.82.114.25                 live.github.com
185.199.111.133               media.githubusercontent.com
185.199.111.133               objects.githubusercontent.com
13.107.42.16                  pipelines.actions.githubusercontent.com
185.199.108.133               raw.githubusercontent.com
185.199.111.133               user-images.githubusercontent.com
13.107.246.51                 vscode.dev
140.82.114.22                 education.github.com
185.199.108.133               private-user-images.githubusercontent.com


# Update time: 2024-11-24T15:53:06+08:00
# Update url: https://raw.hellogithub.com/hosts
# Star me: https://github.com/521xueweihan/GitHub520
# GitHub520 Host End

可以直接追加到本地 hosts 文件内,Windows 系统追加到 C:\Windows\System32\drivers\etc\hosts 文件中,Mac 系统追加到 /etc/hosts 文件中。

写在最后

希望各位小伙伴都能流畅的访问和使用 GitHub。让 GitHub为个人的学习和开发之路添砖加瓦。