如何更快地访问 Github,修改本地 Hosts 文件
什么是 Hosts 文件?它有什么作用?
Hosts 是一个没有扩展名的系统文件,其作用就是将一些常用的网址域名与其对应的 IP 地址建立一个关联“数据库”,当用户在浏览器中输入一个需要登录的网址时,系统会首先自动从 Hosts 文件中寻找对应的 IP 地址,一旦找到,系统会立即打开对应网页,如果没有找到,则系统会再将网址提交 DNS 域名解析服务器进行 IP 地址的解析。
GitHub Hosts
顾名思义则是通过修改host
的方式加速GitHub
访问,解决图片无法加载以及访问速度慢的问题。
手动配置 Hosts
macOS
hosts
文件位置:/etc/hosts
。
macOS
系统下修改需要按照如下方式:
- 首先,打开(访达)Finder。
Shift + Command + G
打开”前往文件夹”,输入框中输入/etc/hosts
。
使用组合键hosts
文件位置。
然后就会跳转到
复制hosts
文件到桌面上,鼠标右键右击它,选择「打开方式」—「文本编辑」,打开这个hosts
文件,把前面的hosts
内容复制进来。
然后把你修改好的hosts
文件替换掉:/etc/hosts
文件。
最后刷新缓存:
sudo killall -HUP mDNSResponder
Windows
hosts
文件位置:C:/windows/system32/drivers/etc/hosts
。
将前文hosts
内容追加到hosts
文件,然后刷新DNS
缓存:
ipconfig /flushdns
* 另外也有自动同步更新的方案,这里推荐使用 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,在此感谢分享!
感谢