GitHub 无法访问解决方案

2021-05-01 Github

# 前言

GitHub是一个面向开源及私有软件项目的托管平台,因为只支持Git 作为唯一的版本库格式进行托管,故名GitHub。

由于GitHub是一个国外网站,在国内访问速度如何呢?

我们通过浏览器访问下https://github.com,但是页面很久才能打开,要等待一个较长时间,如下图所示:

img

接着我们打开系统工具下的命令提示符,输入 ping github.com,但可惜的是出现了“请求超时”的信息提示,如下图所示:

img

# 解决办法

# 第一步:查看 GitHub 的 IP 地址

进入网址 https://github.com.ipaddress.com (opens new window)

image-20211108133927058

# 第二步:查看 GitHub 的 域名 IP

进入网址 https://fastly.net.ipaddress.com/github.global.ssl.fastly.net (opens new window)

image-20211108134027411

# 第三步: 查看 GitHub 的 静态资源 IP

进入网址 https://github.com.ipaddress.com/assets-cdn.github.com (opens new window)

image-20211108134125425

# 第四步: 修改 Hosts 配置文件

将上面三步所得的 IP 写进 hosts 文件里

  • macOS hosts 文件路径: /etc/hosts

  • Windows hosts 文件路径: C:\Windows\System32\drivers\etc\hosts

# GitHub
140.82.112.3 github.com
199.232.69.194 github.global.ssl.fastly.net
185.199.108.153 assets-cdn.github.com
185.199.109.153 assets-cdn.github.com
185.199.110.153 assets-cdn.github.com
185.199.111.153 assets-cdn.github.com
2606:50c0:8000::153 assets-cdn.github.com
2606:50c0:8001::153 assets-cdn.github.com
2606:50c0:8002::153 assets-cdn.github.com
2606:50c0:8003::153 assets-cdn.github.com
1
2
3
4
5
6
7
8
9
10
11

# 注意事项

  1. 这些 IP 过一段时间会变动,所以网上很多教程都是直接复制第四步,却没有效果,这时候一定记得要查一下 IP 是否一样。
  2. 如果在浏览器开着 GitHub (无法访问状态)的时候修改了 hosts 文件需要重启浏览器。

参考博客来自我的前端导师

博客:OG-Liu's Blog (opens new window)

更新时间: 2022-8-2 5:53:05 ├F10: PM┤
大鱼-钢琴版
赵海洋