如何修改hosts文件解决遇到GitHub网站打不开或网站的图片无法加载或者加载速度较慢的情况 2020年08月23日 Vanish 2336 最近打开GitHub总是遇到用户头像无法显示,页面也加载缓慢。心情很糟糕超级爽! GitHub里面图片都在githubusercontent.com域名上,我们只需要在hosts里面加上相关地址即可。如果你有代理(fanq墙工具),把域名加入到许可名单也可以的。 这里介绍不需要代理(fanq墙工具)就可以正常访问GitHub的方法,通过修改hosts的方式是实现正常访问,把以下内容添加到hosts文件中。 ### 1. 修改hosts内容如下: # GitHub Start 52.74.223.119 github.com 192.30.253.119 gist.github.com 54.169.195.247 api.github.com 185.199.111.153 assets-cdn.github.com 151.101.76.133 raw.githubusercontent.com 151.101.76.133 gist.githubusercontent.com 151.101.76.133 cloud.githubusercontent.com 151.101.76.133 camo.githubusercontent.com 151.101.76.133 avatars0.githubusercontent.com 151.101.76.133 avatars1.githubusercontent.com 151.101.76.133 avatars2.githubusercontent.com 151.101.76.133 avatars3.githubusercontent.com 151.101.76.133 avatars4.githubusercontent.com 151.101.76.133 avatars5.githubusercontent.com 151.101.76.133 avatars6.githubusercontent.com 151.101.76.133 avatars7.githubusercontent.com 151.101.76.133 avatars8.githubusercontent.com # GitHub End > 注意 : 这里域名对应的ip是通过dns查询工具查询得到的,你应当选择的是延时相对较小且比较稳定的ip。 如果发现不起作用,或者速度不理想,参考"查找域名IP"。 ### 2. 如何修改 #### 2.1 Windows修改方法 hosts文件位置:C:/windows/system32/drivers/etc/hosts。 将前文内容追加到hosts,然后刷新DNS缓存: `ipconfig /flushdns` #### 2.2 Mac修改方法 hosts文件位置:/etc/hosts。 Mac系统下修改需要按照如下方式: 1:首先,打开(访达)Finder。 2:使用组合键Shift+Command+G打开"前往文件夹",在输入框输入/etc/hosts。 3:然后就会跳转到hosts文件位置。 复制hosts文件到桌面上,鼠标右键点击/右击它,选择「打开方式」—「文本编辑」,打开这个hosts文件,然后将你要修改的内容直接在里面修改就好了。 然后把你修改好的hosts文件在复制回hosts文件的所在(文件夹下)路径:/etc/hosts 之下替换原始的hosts文件就好了。 > 注意:如果弹出密码输入框,你需要输入你当前电脑登录账号的密码。 最后刷新下缓存: `sudo killall -HUP mDNSResponder` #### 3.查找域名IP 前面hosts里面域名里分为两类: - http://githubusercontent.com http://github.com *.githubusercontent.com可以使用同一个IP,不需要每个单独查询。*.github.com未经测试,目前看是需要单独查询对应的IP。过一段时间如果遇到同样问题的小伙伴,查询一下新的ip地址替换上就好用了https://github.com.ipaddress.com/ 版权声明:本文为原创文章,版权归 V-ZONE 所有,允许非商业转载,转载请用链接注明出处。 本文地址:https://vzone.me/898/ 如果对本文有什么问题或疑问都可以在评论区留言,我看到后会尽量解答。 学习 hosts GitHub
这篇文章不错