本帖最后由 八戒有点帅 于 2024-2-11 22:26 编辑
首先说明我的自定义hosts里有为了屏蔽电视广告而写的地址,如127.0.0.1 ad.mi.com 。之前网上的教程都是直接删除原有文件再重新写入,这个与我的需求有偏差,在恩山借鉴了https://www.right.com.cn/forum/thread-8296226-1-1.html这位的格式,然后还借鉴https://hosts.gitcdn.top/这个项目,(这个项目现如今每个小时都更新github的最新地址)
#Pandavan中命令打开浏览器进入路由器的管理页面找到:【高级设置->系统管理->服务栏】里面的计划任务 (Crontab),然后重启下设备 46 * * * * sed -i "/# fetch-github-hosts begin/q" /etc/storage/dnsmasq/hosts && curl https://hosts.gitcdn.top/hosts.txt >> /etc/storage/dnsmasq/hosts;restart_dhcpd
#Ubuntu 18.04下 输入crontab -l,然后添加下列,然后重启下设备 46 * * * * sed -i "/# fetch-github-hosts begin/q" /etc/hosts && curl https://hosts.gitcdn.top/hosts.txt >> /etc/hosts;systemctl restart systemd-resolved
#F大的Openwrt下 输入crontab -l,然后添加下列,然后重启下设备 46 * * * * sed -i "/# fetch-github-hosts begin/q" /etc/hosts && curl https://hosts.gitcdn.top/hosts.txt >> /etc/hosts;systemctl status networking.service 在里面添加一下订阅信息代码即可
代码解释: 前面的46 * * * *是代表每个点的46分更新一次,该项目一般是44分左右更新完成。当然时间自己也可以改,第一个46的位置是分,第二个*的位置是小时,如果你想改为每天6点更新,那么46 * * * *可改为,0 6 * * *。 cd /etc/storage/dnsmasq;这是切换到hosts所在的目录,有些人可能会有疑问:hosts不是在/etc下面吗,但是话说老毛子固件提供了用户自定义的hosts。 sed -i "/# fetch-github-hosts begin/q" /etc/storage/dnsmasq/hosts && curl https://hosts.gitcdn.top/hosts.txt >> /etc/storage/dnsmasq/hosts;restart_dhcpd 这个是替换自定义有关github的地址
restart_dhcpd 这是重启dhcp服务加载新的hosts
|