在国内,有时候使用 git clone 的速度实在太慢而让人难以承受,或者 git pull/git push 一点反应都没有,这里整理了一下解决方法,亲测有效。
总的来说,这是因为 github.global.ssl.fastly.net 域名被限制了。只要找到这个域名对应的 ip 地址,然后在 hosts 文件中加上 ip–>域名 的映射,刷新 DNS 缓存便可。
1.查找域名对应的 ip 地址
在网站 https://www.ipaddress.com/ 分别搜索 github.global.ssl.fastly.net 和 github.com
或者在本地的终端中如下键入:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15$ nslookup github.global.ssl.fastly.Net
Server: 127.0.0.53
Address: 127.0.0.53#53
Non-authoritative answer:
Name: github.global.ssl.fastly.Net
Address: 151.101.229.194
$ nslookup github.com
Server: 127.0.0.53
Address: 127.0.0.53#53
Non-authoritative answer:
Name: github.com
Address: 13.229.188.59
- 修改 hosts 文件
- Windows 上的 hosts 文件路径在: C:\Windows\System32\drivers\etc\hosts
在 hosts 文件末尾添加两行1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23# 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:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
199.232.69.194 github.global.ssl.fastly.net - Linux 的 hosts 文件路径在 /etc/hosts 中:
1
$ sudo vim /etc/hosts
- 刷新 DNS 缓存
- windows
1
ipconfig /flushdns
- linux
1
$ sudo /etc/init.d/networking restart