赞
踩
最近经常需要使用github,但不知出于什么原因,我这里的有线宽带有时可以访问,也有时不行,经过网上一顿搜索,我发现修改hosts可以大大提高访问github成功率,我同时还查到了两个自动更新提供hosts文件的网站,只需要将这个网页上的内容填入hosts文件即可,综上,我使用了下面的方法来实现自动更新。经测试,github访问成功率从原来不到一成现在可以达到八成左右,虽然不是每次都行,但可以确保你总能成功几次。
复制下面代码,将其保存为hostsUpdate.sh
文件。
# wget -q https://raw.githubusercontent.com/racaljk/hosts/master/hosts -O /tmp/hostsNew2.txt --no-check-certificate
wget -q https://gitlab.com/ineo6/hosts/-/raw/master/next-hosts -O /tmp/hostsNew1.txt --no-check-certificate
# cat /tmp/hostsNew1.txt /tmp/hostsNew2.txt /etc/hosts_origin > /tmp/hostsNewAll.txt
cat /tmp/hostsNew1.txt /etc/hosts_origin > /tmp/hostsNewAll.txt
cp /tmp/hostsNewAll.txt /etc/hosts
chmod 664 /etc/hosts
/etc/init.d/dnsmasq restart
在OpenWRT路由器管理页面的系统-文件传输中,将本文件上传。
在OpenWRT路由器管理页面的系统-TTYD中断中登录路由器账号,输入下面命令将本文件移动到家目录;
mv /tmp/upload/hostsUpdate.sh /root
修改脚本运行权限;
chmod 777 hostsUpdate.sh
复制原hosts,使其更新时不破坏原有hosts文件信息;
cp /etc/hosts /etc/hosts_origin
修改复制的hosts文件的权限;
chmod 664 /etc/hosts_origin
到这里就基本成功了,可以运行脚本尝试是否可用;
/root/hostsUpdate.sh
待运行完成后,查看hosts,若内容非常多,则表示已成功;
cat /etc/hosts
若成功,则可以在OpenWRT路由器管理页面的系统-计划任务中添加下面的代码,添加后点提交,最后在系统-启动项中将cron重启即可。下面代码表示每小时运行该脚本更新hosts文件。
01 * * * * /root/hostsUpdate.sh
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。