国内github不稳定或不能访问的解决办法(mac/windows)

unimof 2021年03月01日 1,471次浏览

国内偶尔出现 github 访问不稳定,甚至不能访问的情况,怎么解决呢?
根本办法就是修改 hosts 文件

1. windows

打开文件 C:\Windows\System32\drivers\etc\hosts:

‪# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:

# localhost name resolution is handled within DNS itself.
#	127.0.0.1       localhost
#	::1             localhost

# 在最后加上下面两行
140.82.114.4 github.com
199.232.69.194 github.global.ssl.fastly.net

刷新 dns
打开 cmd 命令行,执行 ipconfig /flushdns

C:\Windows\System32>ipconfig /flushdns

Windows IP 配置

已成功刷新 DNS 解析缓存。

C:\Windows\System32>ipconfig /flushdns

Windows IP 配置

已成功刷新 DNS 解析缓存。

C:\Windows\System32>ipconfig /flushdns

Windows IP 配置

已成功刷新 DNS 解析缓存。

C:\Windows\System32>

2. mac

打开/etc/hosts文件
追加一下命令

http://github.com 140.82.114.4
http://gist.github.com 107.21.116.220 
http://help.github.com 207.97.227.252 
http://nodeload.github.com 199.27.76.130 
http://raw.github.com 107.22.3.110 
http://status.github.com 204.232.175.78 
http://training.github.com 207.97.227.243