Github访问慢?

Github为国外网站,所以域名解析时速度慢的。。解决此问题有俩方法:

  • 挂VPN
  • 修改hosts配置

本文讲的是第二种,修改hosts文件,具体步骤如下:

#1、打开host文件

  • 直接通过Finder

快捷键 command + shift + G,输入“/etc”,回车即可进入etc文件夹,找到hosts文件,直接通过系统的“文本编辑”打开即可。

  • 使用终端打开
1
sudo vi /etc/hosts

输入密码后会看到目前hosts文件的配置信息:

1
2
3
4
5
6
7
8
9
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost

#2、查询Github域名对应的ip地址

在浏览器中访问 此网站,在其搜索框中分别输入“github.com” 与 “github.global.ssl.fastly.net”,查询并记录下其对应的ip地址。我的查询结果如下:

1
2
192.30.253.112 	github.com
151.101.13.194 github.global.ssl.fastly.net

#3、修改hosts文件

通过“文本编辑”工具 或者 终端中使用 vi 命令打开hosts文件,将上面两行记录写入hosts文件,保存并退出。结果如下:

1
2
3
4
5
6
7
8
9
10
11
12
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost

192.30.253.112 github.com
151.101.13.194 github.global.ssl.fastly.net

#4、重新访问 Github.com~

现在,重新访问 Github.com 试试~


相关参考:

#©传送门


Github访问慢?
https://davidlii.cn/2019/07/23/github.html
作者
Davidli
发布于
2019年7月23日
许可协议