Running smartdns at Padavan
在Padavan上运行smartdns

0x00: 准备

首先编译带有smartdns的Padavan固件。

基于 hanwckf/rt-n56u

调整配置文件

trunk/configs/templates/PSG1218.config

CONFIG_VENDOR=Ralink
CONFIG_PRODUCT=MT7620

### Target ProductID (board select, max 12 symbols)
CONFIG_FIRMWARE_PRODUCT_ID="PSG1218"

### Linux kernel and toolchain
CONFIG_LINUXDIR=linux-3.4.x

CONFIG_FIRMWARE_INCLUDE_HTTPS=y
CONFIG_FIRMWARE_INCLUDE_SMARTDNS=y

开始编译

cd trunk
./clear_tree
fakeroot ./build_firmware_modify PSG1218

0x01: 配置

方案1, smartdns直接接管UDP 53

建立配置文件:/etc/storage/smartdns.conf

smartdns不支持bootstrap,所以需要设置一个group来对DoH进行bootstrap.

log-level info
log-file /tmp/smartdns.log
bind []:53
server-https https://1.12.12.12/dns-query -bootstrap-dns
server-https https://dns.alidns.com/dns-query
dnsmasq-lease-file /tmp/dnsmasq.leases
cache-size 0

更改dnsmasq的DNS服务监听端口,避免冲突:/etc/storage/dnsmasq/dnsmasq.conf

port=531
PSG1218:/home/root # netstat -anp | grep dns
tcp 0 0 127.0.0.1:531    0.0.0.0:*  LISTEN   4824/dnsmasq
tcp 0 0 192.168.2.1:531  0.0.0.0:*  LISTEN   4824/dnsmasq
tcp 0 0 ::1:531          :::*       LISTEN   4824/dnsmasq
udp 0 0 :::5353          :::*                526/smartdns

方案2, smartdns作为dnsmasq的上游服务器

建立配置文件:/etc/storage/smartdns.conf

与方案1不同的是,监听端口为非53,其余一样。

log-level info
log-file /tmp/smartdns.log
bind []:5353
server-https https://223.5.5.5/dns-query -bootstrap-dns
server-https https://dns.alidns.com/dns-query
dnsmasq-lease-file /tmp/dnsmasq.leases
cache-size 0

指定dnsmasq的上游服务器:/etc/storage/dnsmasq/dnsmasq.conf

server=127.0.0.1#5353

日志显示:Feb 19 17:52:32 dnsmasq[4697]: using nameserver 127.0.0.1#5353

0x02 保存更改

在crontab写入启动命令,实现开机后自动启动。

crontab -e

* * * * * /usr/bin/smartdns -c /etc/storage/smartdns.conf
PSG1218:/home/root # mtd_storage.sh save
Save storage files to MTD partition "/dev/mtdblock5"
Unlocking 'Storage' ...
Writing from '/tmp/storage.tar.bz2' to MTD 'Storage' ...  [ok]
Done.

0x03 测试

nslookup

> google.com
服务器:  lan
Address:  192.168.2.1

非权威应答:
名称:    google.com
Addresses:  2404:6800:4005:805::200e
          172.217.25.14

dig

; <<>> DiG 9.16.36 <<>> smartdns PTR
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 5941
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;smartdns.                      IN      PTR

;; ANSWER SECTION:
smartdns.               30      IN      PTR     lan.

;; Query time: 5 msec
;; SERVER: 192.168.2.1#53(192.168.2.1)
;; WHEN: Sun Feb 19 18:46:48 ;; MSG SIZE  rcvd: 51

参考资料:

  1. https://github.com/pymumu/smartdns
  2. https://pymumu.github.io/smartdns/
  3. https://wiki.archlinux.org/title/dnsmasq

最后修改于 Sat, 18 Feb 2023