自动刷新github hosts

日常工作中经常会发现GitHub的访问会不稳定,有的时候可以有的时候又不可以。实际上GitHub是没有被墙的,只是受到DNS污染,就是无法找到GitHub正确的IP地址,因此我们可以通过修改hosts的方式告诉服务器GitHub的IP是多少。

切换到root

1
su root

手动更新hosts

1
sed -i "/# GitHub520 Host Start/Q" /etc/hosts && curl https://raw.hellogithub.com/hosts >> /etc/hosts

加入cron自动更新,每分钟更新一次

修改/var/spool/cron/crontabs/root

添加:

1
* * * * * sed -i "/# GitHub520 Host Start/Q" /etc/hosts && curl https://raw.hellogithub.com/hosts >> /etc/hosts

刷新

1
2
3
4
$ service cron reload
* Reloading configuration files for periodic command scheduler cron [ OK ]
$ crontab -l
* * * * * sed -i "/# GitHub520 Host Start/Q" /etc/hosts && curl https://raw.hellogithub.com/hosts >> /etc/host

自动刷新github hosts
http://example.com/2022/10/16/自动刷新github hosts/
作者
Wang Jianhua
发布于
2022年10月16日
许可协议