2017年6月

Lede添加dnsmasq去广告等脚本

安装脚本fqad.sh

#!/bin/sh
###仅限LEDE固件使用###

###请将DNS设置为lan网关###

###该脚本只需要运行一次###


# 移动到用户命令文件夹
cd /usr/bin/

# 创建广告规则与更新脚本存放的文件夹
mkdir -p /etc/dnsmasq
mkdir -p /etc/dnsmasq.d

# dnsmasq.conf 添加广告规则路径
cat >> /etc/dnsmasq.conf <<EOF
# 添加监听地址(将192.168.1.1修改为你的lan网关ip)
listen-address=192.168.1.1,127.0.0.1

# 并发查询所有上游DNS
all-servers

# 添加上游DNS服务噿
resolv-file=/etc/dnsmasq/resolv.conf

# 添加额外hosts规则路径
addn-hosts=/etc/dnsmasq/noad.conf

# IP反查域名
bogus-priv

# 添加DNS解析文件
conf-file=/etc/dnsmasq.d/fqad.conf
EOF

# 创建上游DNS配置文件
cat > /etc/dnsmasq/resolv.conf <<EOF
# DNS上游解析服务器
nameserver 127.0.0.1
nameserver 218.30.118.6
nameserver 8.8.4.4
nameserver 182.254.116.116
nameserver 119.29.29.29
nameserver 4.2.2.2
nameserver 114.114.114.114
EOF

# 开始下载扶墙和广告规

# 下载dnsmasq规则
# 下载sy618扶墙规则
/usr/bin/wget-ssl --no-check-certificate -q -O /tmp/sy618.conf https://raw.githubusercontent.com/sy618/hosts/master/dnsmasq/dnsfq

# 下载racaljk规则
/usr/bin/wget-ssl --no-check-certificate -q -O /tmp/racaljk.conf https://raw.githubusercontent.com/racaljk/hosts/master/dnsmasq.conf

# 下载vokins广告规则
/usr/bin/wget-ssl --no-check-certificate -q -O /tmp/ad.conf https://raw.githubusercontent.com/vokins/yhosts/master/dnsmasq/union.conf

# 下载easylistchina广告规则
/usr/bin/wget-ssl --no-check-certificate -q -O /tmp/easylistchina.conf https://c.nnjsx.cn/GL/dnsmasq/update/adblock/easylistchina.txt

# 删除racaljk规则中google相关规则
sed -i '/google/d' /tmp/racaljk.conf
sed -i '/youtube/d' /tmp/racaljk.conf

# 合并dnsmasq缓存
cat /tmp/racaljk.conf /tmp/sy618.conf /tmp/ad.conf /tmp/easylistchina.conf > /tmp/fqad

# 删除dnsmasq缓存
rm -rf /tmp/ad.conf
rm -rf /tmp/sy618.conf
rm -rf /tmp/racaljk.conf
rm -rf /tmp/easylistchina.conf

# 删除dnsmasq重复规则
sort /tmp/fqad | uniq > /etc/dnsmasq.d/fqad.conf

# 删除dnsmasq合并缓存
rm -rf /tmp/fqad

# 删除无用的注释
sed -i '/#/d' /etc/dnsmasq.d/fqad.conf

# 下载hosts规则
# 下载yhosts缓存
/usr/bin/wget-ssl --no-check-certificate -q -O /tmp/yhosts.conf https://raw.githubusercontent.com/vokins/yhosts/master/hosts.txt

# 下载malwaredomainlist规则
/usr/bin/wget-ssl --no-check-certificate -q -O /tmp/malwaredomainlist.conf http://www.malwaredomainlist.com/hostslist/hosts.txt

# 下载adaway规则缓存
/usr/bin/wget-ssl --no-check-certificate -q -O /tmp/adaway.conf http://77l5b4.com1.z0.glb.clouddn.com/hosts.txt

# 合并hosts缓存
cat /tmp/yhosts.conf /tmp/adaway.conf /tmp/malwaredomainlist.conf > /tmp/noad

# 删除hosts缓存
rm -rf /tmp/yhosts.conf
rm -rf /tmp/adaway.conf
rm -rf /tmp/malwaredomainlist.conf

# 删除hosts重复规则
sort /tmp/noad | uniq > /etc/dnsmasq/noad.conf

# 删除hosts合并缓存
rm -rf /tmp/noad

# 删除无用的注释
sed -i '/#/d' /etc/dnsmasq/noad.conf
sed -i '/@/d' /etc/dnsmasq/noad.conf

# 扶墙和广告屏蔽规则下载结束

# 重启dnsmasq服务
killall dnsmasq
/etc/init.d/dnsmasq restart
#/usr/sbin/dnsmasq

# 创建规则更新脚本
cat > /etc/dnsmasq/fqad_update.sh <<EOF
#!/bin/sh
# 移动到用户命令文件夹
cd /usr/bin/

# 开始更新dnsmasq规则
# 下载sy618扶墙规则
/usr/bin/wget-ssl --no-check-certificate -q -O /tmp/sy618.conf https://raw.githubusercontent.com/sy618/hosts/master/dnsmasq/dnsfq

# 下载racaljk规则
/usr/bin/wget-ssl --no-check-certificate -q -O /tmp/racaljk.conf https://raw.githubusercontent.com/racaljk/hosts/master/dnsmasq.conf

# 下载vokins广告规则
/usr/bin/wget-ssl --no-check-certificate -q -O /tmp/ad.conf https://raw.githubusercontent.com/vokins/yhosts/master/dnsmasq/union.conf

# 下载easylistchina广告规则
/usr/bin/wget-ssl --no-check-certificate -q -O /tmp/easylistchina.conf https://c.nnjsx.cn/GL/dnsmasq/update/adblock/easylistchina.txt

# 删除racaljk规则中google相关规则
sed -i '/google/d' /tmp/racaljk.conf
sed -i '/youtube/d' /tmp/racaljk.conf

# 合并dnsmasq缓存
cat /tmp/racaljk.conf /tmp/sy618.conf /tmp/ad.conf /tmp/easylistchina.conf > /tmp/fqad

# 删除dnsmasq缓存
rm -rf /tmp/ad.conf
rm -rf /tmp/sy618.conf
rm -rf /tmp/racaljk.conf
rm -rf /tmp/easylistchina.conf

# 删除dnsmasq重复规则
sort /tmp/fqad | uniq > /etc/dnsmasq.d/fqad.conf

# 删除dnsmasq合并缓存
rm -rf /tmp/fqad

# 删除无用的注释
sed -i '/#/d' /etc/dnsmasq.d/fqad.conf
# dnsmasq规则更新结束

# 开始更新hosts规则
# 下载yhosts缓存
/usr/bin/wget-ssl --no-check-certificate -q -O /tmp/yhosts.conf https://raw.githubusercontent.com/vokins/yhosts/master/hosts.txt

# 下载malwaredomainlist规则
/usr/bin/wget-ssl --no-check-certificate -q -O /tmp/malwaredomainlist.conf http://www.malwaredomainlist.com/hostslist/hosts.txt

# 下载adaway规则缓存
/usr/bin/wget-ssl --no-check-certificate -q -O /tmp/adaway.conf http://77l5b4.com1.z0.glb.clouddn.com/hosts.txt

# 合并hosts缓存
cat /tmp/yhosts.conf /tmp/adaway.conf /tmp/malwaredomainlist.conf > /tmp/noad

# 删除hosts缓存
rm -rf /tmp/yhosts.conf
rm -rf /tmp/adaway.conf
rm -rf /tmp/malwaredomainlist.conf

# 删除hosts重复规则
sort /tmp/noad | uniq > /etc/dnsmasq/noad.conf

# 删除hosts合并缓存
rm -rf /tmp/noad

# 删除无用的注释
sed -i '/#/d' /etc/dnsmasq/noad.conf
sed -i '/@/d' /etc/dnsmasq/noad.conf
# hosts规则更新结束

# 重启dnsmasq服务
killall dnsmasq
/etc/init.d/dnsmasq restart
#/usr/sbin/dnsmasq
EOF

cat > /etc/dnsmasq/fqad_del.sh <<EOF
# 删除dnsmasq.conf 里 添加广告规则路径
sed -i '/# 添加监听地址/,+16d' /etc/dnsmasq.conf

# 删除注入的每天更新一次的任务
sed -i '/更新dnsmasq和hosts规则/d' /etc/crontabs/root
sed -i '/fqad_update/d' /etc/crontabs/root

killall dnsmasq
/etc/init.d/dnsmasq restart

# 删除创建广告规则与更新脚本存放的文件夹
rm -rf /etc/dnsmasq
rm -rf /etc/dnsmasq.d
EOF

# 注入每天更新一次的任务
chmod 755 /etc/dnsmasq/fqad_update.sh
#http_username=`nvram get http_username`
sed -i '/fqad_update/d' /etc/crontabs/root

cat >> /etc/crontabs/root <<EOF
# 每天5点30分更新dnsmasq和hosts规则
30 5 * * * /bin/sh /etc/fqad_update.sh
EOF

删除脚本fqad_del.sh

# 删除dnsmasq.conf 里 添加广告规则路径
sed -i '/# 添加监听地址/,+16d' /etc/dnsmasq.conf

# 删除注入的每天更新一次的任务
sed -i '/更新dnsmasq和hosts规则/d' /etc/crontabs/root
sed -i '/fqad_update/d' /etc/crontabs/root

killall dnsmasq
/etc/init.d/dnsmasq restart

# 删除创建广告规则与更新脚本存放的文件夹
rm -rf /etc/dnsmasq
rm -rf /etc/dnsmasq.d

Lede的lean版本如下:

安装   wget samzz.tk/tmp/lede_lean/fqad.sh;sh fqad.sh;rm fqad.sh
更新   sh /etc/dnsmasq/fqad_update.sh
删除   sh /etc/dnsmasq/fqad_del.sh

Lede的stones版本如下:

安装fq+ad   wget samzz.tk/tmp/lede_stones/fqad.sh;sh fqad.sh;rm fqad.sh
仅安装ad   wget samzz.tk/tmp/lede_stones/ad.sh;sh ad.sh;rm ad.sh
更新   sh /etc/dnsmasq/fqad_update.sh
删除   sh /etc/dnsmasq/fqad_del.sh

k2p刷breed和op-boot

查询mtd

cat /proc/mtd
dev:    size   erasesize  name
mtd0: 01000000 00010000 "ALL"
mtd1: 00030000 00010000 "Bootloader"
mtd2: 00010000 00010000 "Config"
mtd3: 00010000 00010000 "Factory"
mtd4: 00050000 00010000 "permanent_config"
mtd5: 00f60000 00010000 "firmware"
mtd6: 00c48b96 00010000 "rootfs"
mtd7: 00200000 00010000 "rootfs_data"

得知 mtd1为bootloader

刷op-boot,上传至/tmp然后

mtd -r write /tmp/opboot1.0.4.bin Bootloader

路由器单独添加去广告 hosts+计划任务自动更新

用了yhosts的去广告hosts,解决小米电视的各种广告和视频app的广告

老毛子固件

#30 5 * * * cd /etc/storage/dnsmasq;rm -rf hosts;wget --no-check-certificate https://raw.githubusercontent.com/vokins/yhosts/master/hosts;restart_dhcpd

LEDE

#30 5 * * * cd /etc;rm -rf hosts;wget --no-check-certificate https://raw.githubusercontent.com/vokins/yhosts/master/hosts;/etc/init.d/dnsmasq restart

在LEDE Stones版本中好像长命令无法执行,写了文件yhosts_ad.sh,执行文件后自动添加计划任务
LEDE Stones版本测试ok

#!/bin/sh

#仅添加yhosts的hosts,适用于手机和盒子
cd /etc/
# 删除原有hosts,下载yhosts
rm -rf /etc/hosts
wget --no-check-certificate https://raw.githubusercontent.com/vokins/yhosts/master/hosts

# 删除想删除的拦截
sed -i '/taobao/d' hosts

# 手动添加想拦截的
cat >> hosts <<EOF
# 手动添加
EOF

#重启服务
/etc/init.d/dnsmasq restart

# 删除旧的每天更新一次,注入新的每天更新一次的任务
sed -i '/更新hosts规则/d' /etc/crontabs/root
sed -i '/yhosts_ad.sh/d' /etc/crontabs/root
cat >> /etc/crontabs/root <<EOF
# 每天5点30分更新hosts规则
30 5 * * * /bin/sh /root/yhosts_ad.sh
EOF

以上是写法,使用时直接运行这段命令即可,默认目录/root/

cd /root; wget samzz.tk/tmp/lede_stones/yhosts_ad.sh;sh yhosts_ad.sh

老毛子路由器添加dnsmasq去广告等

hiboy 老毛子 潘多拉固件 (荒野无灯在尾部)

一、手动添加

手动添加到自定义脚本的【在 WAN 上行/下行启动后执行】里,实现网络连接上时自动更新。也可以直接在命令行里直接运行。

#自由上网dnsmasq:
wget --no-check-certificate https://raw.githubusercontent.com/sy618/hosts/master/dnsmasq/dnsfq -O /etc/storage/dnsmasq/dnsmasq.d/dnsfq.conf;sed -i "1 i\## update:$(date "+%Y-%m-%d %H:%M:%S")" /etc/storage/dnsmasq/dnsmasq.d/dnsfq.conf;restart_dhcpd

#去广告hosts:
wget --no-check-certificate https://raw.githubusercontent.com/vokins/yhosts/master/hosts -O /etc/storage/dnsmasq/hosts;sed -i "1 i\## update:$(date "+%Y-%m-%d %H:%M:%S")" /etc/storage/dnsmasq/hosts;restart_dhcpd

手动添加到定时任务crontab(在 系统管理 - 服务 -计划任务 (Crontab) 里)

#自由上网dnsmasq:
01 00 * * * wget --no-check-certificate https://raw.githubusercontent.com/sy618/hosts/master/dnsmasq/dnsfq -O /etc/storage/dnsmasq/dnsmasq.d/dnsfq.conf;restart_dhcpd

#去广告hosts
02 00 * * * wget --no-check-certificate https://raw.githubusercontent.com/vokins/yhosts/master/hosts  -O /etc/storage/dnsmasq/hosts;restart_dhcpd

当然用SS的可以只添加yhosts的去广告

二、自动化脚本,不会手动添加的用以下一键脚本命令 适用 hiboy大和荒野无灯大的【padavan固件】

固件地址:http://www.right.com.cn/forum/thread-161324-1-1.html

一键运行命令fq+ad:

mkdir -p /etc/storage/dnsmasq/dns;wget --no-check-certificate https://raw.githubusercontent.com/sy618/hosts/master/dnsmasq/sh/setting.sh -O /etc/storage/dnsmasq/dns/setting.sh;sh /etc/storage/dnsmasq/dns/setting.sh

一键运行命令ad(在start.sh里把下载dnsmasq文件的部分注释掉了):

mkdir -p /etc/storage/dnsmasq/dns;wget --no-check-certificate http://www.samzz.tk/tmp/laomaozi/ad/ad.sh -O /etc/storage/dnsmasq/dns/setting.sh;sh /etc/storage/dnsmasq/dns/setting.sh

一键还原命令相同:

sh /etc/storage/dnsmasq/dns/del.sh

详细看https://github.com/sy618/hosts/tree/master/dnsmasq/sh

荒野无灯 潘多拉固件

因dnsmasq配置文件里conf-dir目录和hiboy的不同,添加计划任务略有不同,见下

#自由上网dnsmasq:
01 00 * * *wget --no-check-certificate https://raw.githubusercontent.com/sy618/hosts/master/dnsmasq/dnsfq -O /etc/storage/dnsmasq/conf.d/dnsfq.conf;restart_dhcpd

#去广告hosts:
02 00 * * * wget --no-check-certificate https://raw.githubusercontent.com/vokins/yhosts/master/hosts -O /etc/storage/dnsmasq/hosts;restart_dhcpd

重点是一键脚本也完全适用荒野无灯!!原因是一键脚本是在配置文件里指定了新的规则文件目录,都是/etc/storage/dnsmasq/dns

来源

去广告项目:
https://github.com/vokins/yhosts

FQ项目:
https://github.com/sy618/hosts

18luck 365bet 888zhenren aomenduchang aomenjinshayule baijiale bbin beplay bet007 betvictor betway bifa bst hg0088 bwin fenghuangyule jinbobao lebaijia long8 manbet quanxunwang shenbotaiyangcheng tengbohui ule vwin w88 wellbet WilliamHill yulepingtai laohuji