国内github访问慢

@wanqiuz 2018-04-24 01:19:45发表于 wanqiuz/blog-articles GithubSoftware

github的某些域名的dns解析被污染了。需要绕过dns解析,在本地直接绑定host。打开dns查询工具网站http://tool.chinaz.com/dns 查询域名github.global.ssl.fastly.net解析获取其IP.

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:
#
#      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
172.16.15.10 epdm
151.101.88.249 github.global.ssl.fastly.net

在最后面加上如下一行,保存关闭,即可体验飞一般的感觉。

151.101.88.249 github.global.ssl.fastly.net

mac

在 /etc/hosts找到hosts文件。所以先打开终端。然后输入如下命令,打开hosts文件。

vi /etc/hosts

将如下github的host放到hosts文件中。在 vim 编辑中,按 “i”建进入插入模式,就可以将下面的 hosts 修改粘贴进入到hosts文件中。

http://github.com 204.232.175.94 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 http://www.github.com
然后按 “ESC”键,输入 “shift + ;”,将vim切换到保存模式。然后输入 “wq” 保存hosts文件。

linux

linux的hosts文件路径在:/etc/hosts

hosts文件输入命令

sudo vim /etc/hosts

在hosts文件末尾添加两行

151.101.72.249 http://global-ssl.fastly.Net
192.30.253.112 http://github.com

重启电脑,让hosts文件生效