注意:本博文已同步至本人最新博客,地址:https://www.vincentqin.tech/posts/manage-pc-hosts/
对于经常刷Github的同学而言,是否会经常遇到图片加载不出来/GitHub访问慢等情况?反正我是经常遇到!为了解决这个问题,削微寒公布了解决方案:修改本机hosts
,无需安装任何程序。下面是详细说明以及使用方法(修改自项目README)。
使用方法
复制如下内容
# GitHub520 Host Start
185.199.108.154 github.githubassets.com
199.232.68.133 camo.githubusercontent.com
199.232.68.133 github.map.fastly.net
199.232.69.194 github.global.ssl.fastly.net
140.82.112.3 github.com
140.82.112.6 api.github.com
52.136.127.111 raw.githubusercontent.com
199.232.68.133 favicons.githubusercontent.com
199.232.68.133 avatars5.githubusercontent.com
199.232.68.133 avatars4.githubusercontent.com
199.232.68.133 avatars3.githubusercontent.com
199.232.68.133 avatars2.githubusercontent.com
199.232.68.133 avatars1.githubusercontent.com
199.232.68.133 avatars0.githubusercontent.com
# GitHub520 Host End
上面内容会自动定时更新,这里是最新地址,保证最新有效。
手动方式
修改 hosts 文件
hosts 文件在每个系统的位置不一,详情如下:
- Windows 系统:
C:\Windows\System32\drivers\etc\hosts
- Linux 系统:
/etc/hosts
- Mac(苹果电脑)系统:
/etc/hosts
- Android(安卓)系统:
/system/etc/hosts
- iPhone(iOS)系统:
/etc/hosts
修改方法,把第一步的内容复制到文本末尾:
- Windows 使用记事本。
- Linux、Mac 使用 Root 权限:
sudo vi /etc/hosts
。 - iPhone、iPad 须越狱、Android 必须要 root。
激活生效
大部分情况下是直接生效,如未生效可尝试下面的办法,刷新 DNS:
-
Windows:在 CMD 窗口输入:
ipconfig /flushdns
-
Linux 命令:
sudo rcnscd restart
-
Mac 命令:
sudo killall -HUP mDNSResponder
Tips: 上述方法无效可以尝试重启机器。
自动方式
下载Hosts切换工具
Tip:推荐 SwitchHosts 工具管理 hosts
。根据自己的系统选择对应的版本进行下载,[下载页面]。
配置工具
以SwitchHosts为例,看一下怎么使用的,配置参考下面:
{% note default %}
Title: 随意
Type: Remote
URL: https://raw.githubusercontent.com/521xueweihan/GitHub520/master/hosts
Auto Refresh: 最好选 1 hour
{%endnote%}
配置页面如下图:
配置好的页面是这样的:
这样每次 hosts
有更新都能及时进行更新,免去手动更新。