找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
广告投放联系QQ68610888
查看: 15824|回复: 268

[k2p] 教程,纯净版K2P Padavan添加软件,无需U盘,安装entware,安装smartdns过滤广告,满足幻想

 火... [复制链接]
本帖最后由 lanrone 于 2024-2-21 20:10 编辑



以下新内容2024年2月21日更新
#98楼的内容丢失
我把shell代码更新到主贴,方便大家查看
  1. ###使用镜像加速安装entware环境
  2. until ping -c 1 223.5.5.5 >/dev/null 2>&1; do sleep 1; done
  3. logger "internet已接通"
  4. if [ ! -f /opt/bin/opkg ]; then
  5.   mount -t tmpfs tmpfs /opt -o size=30M
  6.   for folder in bin etc lib/opkg tmp var/lock var/run; do
  7.     [ ! -d "/opt/$folder" ] && mkdir -p /opt/$folder
  8.   done
  9.   wget http://mirrors.bfsu.edu.cn/entware/mipselsf-k3.4/installer/opkg -O /opt/bin/opkg
  10.   chmod 755 /opt/bin/opkg
  11.   wget http://mirrors.bfsu.edu.cn/entware/mipselsf-k3.4/installer/opkg.conf -O /opt/etc/opkg.conf
  12.   sed -i 's|bin.entware.net|mirrors.bfsu.edu.cn/entware|g' /opt/etc/opkg.conf
  13.   /opt/bin/opkg update
  14.   ###Fix for multiuser environment
  15.   chmod 777 /opt/tmp
  16.   for file in passwd group shells shadow; do
  17.     cp /etc/$file /opt/etc/$file
  18.   done
  19.   cp /etc/TZ /opt/etc/TZ
  20.   logger "entware环境创建完成"
  21. fi

  22. ###安装smartdns
  23. /opt/bin/opkg install smartdns
  24. cat >/opt/etc/smartdns/smartdns.conf <<"EOF"
  25. user nobody
  26. server-name smartdns-padavan
  27. #log-level info
  28. #log-size 128K
  29. #log-num 0
  30. bind [::]:60053
  31. #audit-enable yes
  32. #audit-size 128K
  33. #audit-num 0
  34. force-qtype-SOA 65
  35. #@@@@@@@@@@@
  36. #@@@@@@@@@@@
  37. server-https https://223.5.5.5/dns-query
  38. server-https https://223.6.6.6/dns-query
  39. server-https https://1.12.12.12/dns-query
  40. server-https https://120.53.53.53/dns-query
  41. server-https https://doh.360.cn/dns-query
  42. server-https https://1.0.0.1/dns-query
  43. server-https https://dns.adguard.com/dns-query
  44. server-tls 223.6.6.6
  45. server-tls 120.53.53.53
  46. #@@@@@@@@@@@
  47. #@@@@@@@@@@@
  48. conf-file /opt/etc/smartdns/anti-ad-smartdns.conf
  49. EOF
  50. ###安装wget-ssl,下载anti-ad规则
  51. /opt/bin/opkg install wget-ssl ca-certificates
  52. /opt/libexec/wget-ssl https://raw.githubusercontents.com/privacy-protection-tools/anti-AD/master/anti-ad-smartdns.conf -O /opt/etc/smartdns/anti-ad-smartdns.conf --no-check-certificate
  53. killall smartdns
  54. /opt/sbin/smartdns &
  55. logger "smartdns pid is $(pidof smartdns)"
  56. logger "smartdns过滤广告规则已加载"

  57. ###如果smartdns启动失败,dnsmasq继续以默认配置运行
  58. if test -n "$(pidof smartdns)"; then
  59.   ###禁用dnsmasq缓存
  60.   cp /etc/dnsmasq.conf /opt/etc/dnsmasq.conf
  61.   sed -i '/cache-size=/d' /opt/etc/dnsmasq.conf
  62.   cat >>/opt/etc/dnsmasq.conf <<"EOF"
  63. no-resolv
  64. no-hosts
  65. cache-size=0
  66. query-port=65353
  67. server=127.0.0.1#60053
  68. EOF
  69.   killall dnsmasq
  70.   dnsmasq -C /opt/etc/dnsmasq.conf
  71.   logger "dnsmasq pid is $(pidof dnsmasq)"
  72.   logger "dnsmasq已重启并禁用缓存"
  73.   logger "smartdns已启用,开始转发dnsmasq的dns解析请求"
  74. else
  75.   logger "smartdns启动异常,dnsmasq以默认配置继续运行"
  76. fi
复制代码




考虑到还有坛友不会操作的,我再更新一下本贴,再降低一点难度,说实话难度已经降到最低了。
https://www.right.com.cn/forum/forum.php?mod=redirect&goto=findpost&ptid=8310114&pid=19497413

直接点击上面链接看#98楼(2024年2月21日更新,不明原因98楼的内容丢失)

脚本进行了更新:降低了设置的难度,优化了脚本的稳定性,主要是检测到entware软件安装异常时确保不影响路由器正常工作(因为用到了软件源的镜像链接,虽然我没遇到镜像源出现故障,但是但是万一呢,所以我在脚本逻辑上做了安全防范,就算出现下载链接失效,路由器也不会受到任何影响,任何情况下脚本所做的操作都是在内存中进行的不会涉及闪存,不会影响路由器任何设置,敬请放心。)
为什么要这样做呢?
我的k2p,为了尽可能降低运行内存占用,几年前刷了精简版的padavan,虽然这些年运行一直挺稳定的,但是抵不住折腾带来的快乐呀。继续折腾吧,由之前稳定变得又不稳定了,再排错修复脚本bug,又变得稳定好用了。所以要分享一下,既可以分享一下喜悦,又可以分享些有用的知识点。
这台k2p到时啥情况呀?
编译固件时去掉了一些功能,例如,dropbear,你不会不知道这是啥吧,这是ssh呀(原固件保留了telnet),还去掉了各种增强插件,wget也不能下载https链接。有时精简也会带来很多不便。

后来,我发现了entware,但是我没有硬改啊,没有usb接口,怎么办呀,那后面再慢慢说吧。
如果安装了entware环境,这里面好多软件包可以适当的拿来用哦,如果你不会写配置文件或简单脚本,这些软件也是很难驾驭的。

我的想法是:我在k2p豪华的128mb内存中 划出来50mb空间(空间是共享的,不会一下子少50mb空间的,放心吧),挂载到 /opt 然后使用wget 下载opkg和它的配置文件(这玩意应该是静态编译的,要不为啥opkg可以免库直接运行呢),然后你发现entware(opkg)的官方网站下载速度好慢啊(接近断流),好吧我只能在配置文件中把官方软件源替换为镜像源进行加速了。差不多entware环境就好了。
剩下就是脚本的事情了。

下面是更新后的脚本内容,(你要做的就是,复制下面脚本,填到自定义脚本》在路由器启动后执行》下面框框里,然后点击应用设置,然后点击padavan首页右上方重启按钮,不要拔电重启路由器,路由器开机时一定要能联网,不然不起作用)
  1. ###使用镜像加速安装entware环境
  2. until ping -c 1 223.5.5.5 >/dev/null;do sleep 10;done
  3. if [ ! -f /opt/bin/opkg ];then
  4.   mount -t tmpfs tmpfs /opt -o size=50M
  5.   for folder in bin etc lib/opkg tmp var/lock var/run
  6.     do
  7.     [ ! -d "/opt/$folder" ] && mkdir -p /opt/$folder
  8.     done
  9.   wget http://mirrors.bfsu.edu.cn/entware/mipselsf-k3.4/installer/opkg -O /opt/bin/opkg
  10.   chmod 755 /opt/bin/opkg
  11.   wget http://mirrors.bfsu.edu.cn/entware/mipselsf-k3.4/installer/opkg.conf -O /opt/etc/opkg.conf
  12.   sed -i 's|bin.entware.net|mirrors.bfsu.edu.cn/entware|g' /opt/etc/opkg.conf
  13.   /opt/bin/opkg update
  14. ###Fix for multiuser environment
  15.   chmod 777 /opt/tmp
  16.   for file in passwd group shells shadow
  17.      do
  18.      cp /etc/$file /opt/etc/$file
  19.      done
  20. fi
  21. logger "entware环境创建完成"
复制代码
  1. ###安装smartdns
  2. /opt/bin/opkg install smartdns
  3. cat > /opt/etc/smartdns/smartdns.conf <<EOF
  4. server-name smartdns-k2p
  5. log-level off
  6. log-num 1
  7. bind [::]:60053
  8. #audit-enable yes
  9. #audit-num 1
  10. force-qtype-SOA 65
  11. server 223.5.5.5
  12. server 119.29.29.29
  13. server 180.76.76.76
  14. server 180.184.1.1
  15. server 114.114.114.114
  16. server 101.226.4.6
  17. server 1.2.4.8
  18. server 1.0.0.1
  19. server 1.1.8.8
  20. server 202.96.128.166 -bootstrap-dns
  21. server 202.96.134.133 -bootstrap-dns
  22. conf-file /opt/etc/smartdns/anti-ad-smartdns.conf
  23. EOF
  24. ###安装wget-ssl,下载anti-ad规则
  25. /opt/bin/opkg install wget-ssl
  26. /opt/libexec/wget-ssl https://raw.githubusercontents.com/privacy-protection-tools/anti-AD/master/anti-ad-smartdns.conf -O /opt/etc/smartdns/anti-ad-smartdns.conf --no-check-certificate
  27. /opt/sbin/smartdns &
  28. logger "smartdns已启动,过滤广告规则已加载,等待dnsmasq重新配置"
复制代码
  1. ###如果smartdns启动失败,dnsmasq重启并禁用smartdns
  2. if test -n "`pidof smartdns`";then
  3. ###禁用dnsmasq缓存
  4. cp /etc/dnsmasq.conf /opt/etc/dnsmasq.conf
  5. sed -i '/cache-size=/d' /opt/etc/dnsmasq.conf
  6. cat >> /opt/etc/dnsmasq.conf <<EOF
  7. no-resolv
  8. no-hosts
  9. cache-size=0
  10. server=127.0.0.1#60053
  11. EOF
  12. killall dnsmasq
  13. dnsmasq -C /opt/etc/dnsmasq.conf
  14. logger "dnsmasq已重新配置并禁用缓存,smartdns已启用"
  15. else
  16. logger "smartdns启动异常,dnsmasq以默认配置继续运行"
  17. fi
复制代码

下面隐藏神秘脚本
游客,如果您要查看本帖隐藏内容请回复


顺手再用脚本添加几个可能有用的软件
  1. ###安装dropbear
  2. /opt/bin/opkg install dropbear
  3. /opt/sbin/dropbear -p 22 &
  4. logger "dropbear已启动"

  5. ###安装vsftpd
  6. /opt/bin/opkg install vsftpd
  7. cat > /opt/etc/vsftpd/vsftpd.conf <<EOF
  8. anonymous_enable=NO
  9. local_enable=YES
  10. write_enable=YES
  11. local_umask=022
  12. use_localtime=YES
  13. connect_from_port_20=YES
  14. listen=YES
  15. pam_service_name=vsftpd
  16. EOF
  17. /opt/sbin/vsftpd &
  18. logger "vsftpd已启动"
复制代码
  1. ###安装ttyd
  2. /opt/bin/opkg install ttyd
  3. /opt/bin/ttyd -p 8080 login &
  4. logger "ttyd已启动,地址ip:8080"
复制代码


搞完这些后,重启一下路由器,你的k2p可以高性能的过滤广告喽
下面说重点,其实这篇帖子,是手动为padavan添加smartdns的教程。当然有些padavan固件集成了smartdns,如果你不想刷机,你可以像我一样手动安装。
特别说明一下,dnsmasq.conf中如果定义port=0,表示禁用dnsmasq dns转发功能,并保留dhcp功能,这时在smartdns.conf中定义bind [::]:53,就相当于用smartdns代替了dnsmasq的dns功能。为啥我没这样搞,因为我遇到bug了(padavan首页已连接设备都是星号,显不出设备名称,我也不知道为啥),我才搞了smartdns做上游dns(我还配置了阿里、腾讯、字节跳动、百度、cnnic、cloudflare,还有运营商dns等做上游查询),使用dnsmasq转发路由器请求。
smartdns是啥,是国内宽带,特别是移动宽带用户的福音,但是你竟然还不知道,哦no,github上有库,可以查看一下。




本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×

评分

参与人数 2恩山币 +2 收起 理由
lew*** + 1 路由器断电后,所有安装的都失效。.
twt*** + 1 搞个安装AdGuard Home 的.

查看全部评分

我的恩山、我的无线 The best wifi forum is right here.
厉害了
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

虽然不懂但感觉很厉害的样子
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

感谢分享辛苦
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

你真的好厉害,entware是个好东西
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

来自手机 | 显示全部楼层
楼主奇思妙想啊,佩服
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

谢谢!!!!!
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

顶顶顶顶顶顶顶顶顶顶顶顶顶顶
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

no,help?
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

bhfddf dfghdrgh
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

我来看看
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

看看好东西
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

谢谢分析
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

有没有“师夷长技以制夷”带Hysteria协议
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

虽然不懂但感觉很厉害的样子
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

有疑问请添加管理员QQ86788181|手机版|小黑屋|Archiver|恩山无线论坛(常州市恩山计算机开发有限公司版权所有) ( 苏ICP备05084872号 )

GMT+8, 2024-4-27 21:08

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

| 江苏省互联网有害信息举报中心 举报信箱:js12377 | @jischina.com.cn 举报电话:025-88802724 本站不良内容举报信箱:68610888@qq.com 举报电话:0519-86695797

快速回复 返回顶部 返回列表