Github访问超时 or 连接不上解决方法(mac)


问题原因

Github 服务器在国外,所以国内访问 Github 域名的时候 DNS 解析阶段会花费比较长时间。我们可以通过修改本地 host 文件,来绕过域名解析,从而达到加速访问的目的。

解决步骤

  1. Github 域名对应的 IP 地址是会变化的,所以我们需要获取此时 Github 对应的host配置。可以通过访问这个链接:raw.hellogithub.com/hosts 来进行获取。
  2. host 配置下载好后,我们需要复制文件里对应的 IP 配置,如下。
# GitHub520 Host Start
140.82.112.25                 alive.github.com
140.82.112.5                  api.github.com
185.199.108.153               assets-cdn.github.com
185.199.111.133               avatars.githubusercontent.com
185.199.111.133               avatars0.githubusercontent.com
185.199.111.133               avatars1.githubusercontent.com
185.199.111.133               avatars2.githubusercontent.com
185.199.111.133               avatars3.githubusercontent.com
185.199.111.133               avatars4.githubusercontent.com
185.199.111.133               avatars5.githubusercontent.com
185.199.111.133               camo.githubusercontent.com
140.82.114.22                 central.github.com
185.199.111.133               cloud.githubusercontent.com
140.82.112.10                 codeload.github.com
140.82.112.22                 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.217.34.20                  github-cloud.s3.amazonaws.com
54.231.193.161                github-com.s3.amazonaws.com
54.231.232.41                 github-production-release-asset-2e65be.s3.amazonaws.com
54.231.232.177                github-production-repository-file-5c1aeb.s3.amazonaws.com
52.217.202.169                github-production-user-asset-6210df.s3.amazonaws.com
192.0.66.2                    github.blog
140.82.112.3                  github.com
140.82.113.17                 github.community
185.199.109.154               github.githubassets.com
151.101.1.194                 github.global.ssl.fastly.net
185.199.108.153               github.io
185.199.111.133               github.map.fastly.net
185.199.108.153               githubstatus.com
140.82.112.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.111.133               raw.githubusercontent.com
185.199.111.133               user-images.githubusercontent.com
13.107.213.40                 vscode.dev
140.82.113.22                 education.github.com


# Update time: 2024-01-18T01:52:41+08:00
# Update url: https://raw.hellogithub.com/hosts
# Star me: https://github.com/521xueweihan/GitHub520
# GitHub520 Host End
  1. mac 下打开终端,输入以下命令用 vim 打开本机 host 文件,并输入开机密码
sudo vim /etc/hosts
  1. 进入 host 文件的查看界面,定位光标至需要写入配置的地方,输入 i 进入编辑模式。将上述找到的 ip 配置粘贴进去。写好后按 esc 键退出编辑模式,并输入 :wq 将刚写入的变动进行保存后退出 host 文件。
    在这里插入图片描述
  2. 完成上述操作后,再次访问 Github 地址进行访问就会快多啦。如果后续发现 Github 地址无法访问,很有可能是 IP 地址变了,需要重新重复上述步骤,更新一下相应的 host 配置.(ps: 如果想在 vim 中删除多行内容,在查看模式下执行命令 :3,5d 即可删除3到5行的内容)

最后,文章借阅自故梦酱,感谢!

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值