如何更快地访问 Github,修改本地 Hosts 文件

20,290次阅读
没有评论

共计 1474 个字符,预计需要花费 4 分钟才能阅读完成。

什么是 Hosts 文件?它有什么作用?

Hosts 是一个没有扩展名的系统文件,其作用就是将一些常用的网址域名与其对应的 IP 地址建立一个关联“数据库”,当用户在浏览器中输入一个需要登录的网址时,系统会首先自动从 Hosts 文件中寻找对应的 IP 地址,一旦找到,系统会立即打开对应网页,如果没有找到,则系统会再将网址提交 DNS 域名解析服务器进行 IP 地址的解析。

GitHub Hosts顾名思义则是通过修改 host 的方式加速 GitHub 访问,解决图片无法加载以及访问速度慢的问题。

手动配置 Hosts

macOS

hosts文件位置:/etc/hosts

macOS系统下修改需要按照如下方式:

  1. 首先,打开(访达)Finder。
  2. 使用组合键 Shift + Command + G 打开”前往文件夹”,输入框中输入/etc/hosts
  3. 然后就会跳转到 hosts 文件位置。

复制 hosts 文件到桌面上,鼠标右键右击它,选择「打开方式」—「文本编辑」,打开这个 hosts 文件,把前面的 hosts 内容复制进来。

然后把你修改好的 hosts 文件替换掉:/etc/hosts 文件。

最后刷新缓存:

sudo killall -HUP mDNSResponder
Windows

hosts文件位置:C:/windows/system32/drivers/etc/hosts

将前文 hosts 内容追加到 hosts 文件,然后刷新 DNS 缓存:

* 另外也有自动同步更新的方案,这里推荐使用 SwitchHosts! 配置hosts,操作很简单,支持跨平台。

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
127.0.0.1       activate.navicat.com

185.199.108.154              github.githubassets.com
140.82.114.22                central.github.com
185.199.108.133              desktop.githubusercontent.com

git 仓库有人放出了实时更新的资源 https://gitee.com/ineo6/hosts/raw/master/hosts,在此感谢分享!

    正文完
     0
    Yojack
    版权声明:本篇文章由 Yojack 于1970-01-01发表,共计1474字。
    转载说明:
    1 本网站名称:优杰开发笔记
    2 本站永久网址:https://yojack.cn
    3 本网站的文章部分内容可能来源于网络,仅供大家学习与参考,如有侵权,请联系站长进行删除处理。
    4 本站一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
    5 本站所有内容均可转载及分享, 但请注明出处
    6 我们始终尊重原创作者的版权,所有文章在发布时,均尽可能注明出处与作者。
    7 站长邮箱:laylwenl@gmail.com
    评论(没有评论)