解决方案
在Gitee上找到了一个项目,其中就有GitHub的IP-域名映射清单:https://gitee.com/klmahuaw/GitHub520,然后,我们将下面的内容复制添加到hosts文件下即可,打开文件 /etc/hosts,并赋予读写权限:
# GitHub520 Host Start
140.82.114.25 alive.github.com
140.82.113.5 api.github.com
185.199.110.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.112.22 central.github.com
185.199.111.133 cloud.githubusercontent.com
140.82.114.9 codeload.github.com
140.82.113.22 collector.github.com
185.199.111.133 desktop.githubusercontent.com
185.199.111.133 favicons.githubusercontent.com
140.82.112.3 gist.github.com
52.216.163.147 github-cloud.s3.amazonaws.com
52.217.124.1 github-com.s3.amazonaws.com
52.216.144.83 github-production-release-asset-2e65be.s3.amazonaws.com
52.217.121.249 github-production-repository-file-5c1aeb.s3.amazonaws.com
52.217.206.57 github-production-user-asset-6210df.s3.amazonaws.com
192.0.66.2 github.blog
140.82.114.4 github.com
140.82.113.18 github.community
185.199.110.154 github.githubassets.com
151.101.1.194 github.global.ssl.fastly.net
185.199.110.153 github.io
185.199.111.133 github.map.fastly.net
185.199.110.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.253.40 vscode.dev
140.82.112.21 education.github.com
# Update time: 2023-08-01T14:06:06+08:00
# Update url: https://raw.hellogithub.com/hosts
# Star me: https://github.com/521xueweihan/GitHub520
# GitHub520 Host End
刷新 DNS 缓存:
sudo killall -HUP mDNSResponder
-
sudo
: 这是一个在Unix和类Unix操作系统中允许普通用户以超级用户的身份执行命令的命令。sudo
允许具有适当权限的用户执行受限制的命令,例如重启网络服务或更改系统设置。 -
killall
: 这个命令用于终止指定名称的进程。它通过发送信号给指定的进程来实现这一点。 -
-HUP
: 这是killall
命令中的一个选项,表示要发送HUP
信号。HUP
是 SIGHUP(Hangup)信号的缩写,通常用于通知进程重新加载其配置文件或进行某些其他类型的清理工作。 -
mDNSResponder
: 这是一个运行在 macOS 和其他基于BSD内核的系统上的服务,它允许设备在没有传统DNS服务器的情况下通过名称发现其他设备和服务,在这个命令中,killall
将向名为mDNSResponder
的进程发送HUP
信号,触发该进程重新加载其配置文件。
要求其重新加载其配置文件和刷新DNS缓存,从而使hosts文件的更改生效。
如果上面的域名失效了,利用网络上的ping
工具:多个地点ping[github.com]服务器-网站测速-站长工具 (chinaz.com)https://ping.chinaz.com/github.com检测网址、IP 地址的通讯情况。输入要检测的网址
github.com
,点击Ping 检测。工具提供的服务是利用自己分布在各地的网络节点的本机ping
工具,执行对网址的ping
操作,汇总结果,统计响应网址的服务器 IP,然后再更新 hosts 文件。
原因分析
DNS 污染:通过篡改DNS响应,将GitHub的域名解析结果指向非预期的IP地址,使用户无法正常访问GitHub。由于网络审查和过滤,一些国外的网站和服务可能会受到限制或屏蔽。为了绕过这些限制,人们可以通过修改本地的 hosts 文件来实现对特定网站的访问。