WangQiFei

蒸 馏 器


思想提纯
  • 首页
  • 归档
  • 标签
  • 关于
  •     

© 2024  by  Wangqifei

openwrt定时更新host文件的方案

发布于 2023-06-14 17:06 openwrt 

需求

openwrt 安装以后一直没办法解决 github DNS 污染的问题,raw 和 github 图片都不能访问,导致大量的文件不能更新,或者只能访问凭运气。于是就需要配置 github 的 host 来解决 DNS 污染,写了个脚本来实现。

步骤

  • 备份现有 host 文件到 hosts_origin(注意如无则新建,如有则覆盖),并调整本分文件权限
1
2
cp /etc/hosts /etc/hosts_origin
chmod 664 /etc/hosts_origin
  • 在 root 目录下新建 hostsUpdate.sh 文件
1
2
3
4
5
6
# !/bin/sh
wget -q https://hosts.gitcdn.top/hosts.txt -O /tmp/hostsNew.txt --no-check-certificate
cat /tmp/hostsNew.txt /etc/hosts_origin > /tmp/hostsNewAll.txt
cp /tmp/hostsNewAll.txt /etc/hosts
chmod 664 /etc/hosts
/etc/init.d/dnsmasq restart
  • 修改 hostsUpdate.sh 文件权限
1
chmod 777 hostsUpdate.sh
  • 执行 hostsUpdate.sh 文件
1
/root/hostsUpdate.sh
  • 设置定时任务
    在 openwrt 中添加定时任务,保存定时任务后在系统启动项中重启 cron。
    每天 3 点定时更新
1
0 3 * * * /root/update_hosts.sh

 上一篇: 华为Mate30 Pro安装Google框架 

下一篇: 快柠檬的节点提取和转换 

© 2024  by  Wangqifei