github一些基友的分享
-
https://github.com/maxiaof/github-hosts
-
https://hosts.gitcdn.top/hosts.txt
-
https://raw.githubusercontent.com/maxiaof/github-hosts/master/hosts
-
这些基友本身已经写好工具定期更新了 直接使用即可 可手工也可用工具自动
自动化工具体验
-
地址 -
https://github.com/Licoy/fetch-github-hosts -
https://github.com/Licoy/fetch-github-hosts/releases
-
使用方法
-
curl获取所有hosts
-
脚本更新/etc/hosts文件
-
重启nscd
-
汇总后的脚本
#!/bin/bash
# 拉起githubhosts 检查文件中是否存在指定字样 校验是否拉取成功
curl -s https://hosts.gitcdn.top/hosts.txt >/tmp/githubhosts.txt
if grep -q "fetch-github-hosts" /tmp/githubhosts.txt; then
echo "hello"
else
exit 0
fi
# 删除/etc/hosts文件中旧的github记录
# 指定开始和结束标记
begin_marker="# fetch-github-hosts begin"
end_marker="# fetch-github-hosts end"
# 临时文件路径
temp_file="/tmp/hosts_temp"
# 复制除了指定行之外的所有行到临时文件
sed "/$begin_marker/,/$end_marker/d" /etc/hosts > "$temp_file"
# 将临时文件复制回原始文件
sudo cp "$temp_file" /etc/hosts
# 删除临时文件
rm "$temp_file"
#追加最新的hosts
sudo sh -c 'cat /tmp/githubhosts.txt >> /etc/hosts'
#刷新 DNS
sudo systemctl restart nscd -
添加crontab每小时执行一次
-
0 * * * * /home/ubuntu/shell/updateGithubHosts.sh > /home/ubuntu/shell/updateGithubHosts.log 2>&1
-
本文由 mdnice 多平台发布