需求
openwrt 安装以后一直没办法解决 github DNS 污染的问题,raw 和 github 图片都不能访问,导致大量的文件不能更新,或者只能访问凭运气。于是就需要配置 github 的 host 来解决 DNS 污染,写了个脚本来实现。
步骤
- 备份现有 host 文件到 hosts_origin(注意如无则新建,如有则覆盖),并调整本分文件权限
1 | cp /etc/hosts /etc/hosts_origin |
- 在 root 目录下新建 hostsUpdate.sh 文件
1 | # !/bin/sh |
- 修改 hostsUpdate.sh 文件权限
1 | chmod 777 hostsUpdate.sh |
- 执行 hostsUpdate.sh 文件
1 | /root/hostsUpdate.sh |
- 设置定时任务
在 openwrt 中添加定时任务,保存定时任务后在系统启动项中重启 cron。
每天 3 点定时更新
1 | 0 3 * * * /root/update_hosts.sh |