个人技术空间关于本站

SmartDNS部署

部署环境:Ubuntu 24.04

#创建专属用户
useradd -u 5000 -s /usr/sbin/nologin  -M smartdns

mkdir -p /data/app/smartdns
cd /data/app/smartdns
wget -c https://github.com/pymumu/smartdns/releases/download/Release47.1/smartdns-x86_64
chown -R smartdns:smartdns smartdns-x86_64
chmod 700 smartdns-x86_64

#创建其他相关目录
mkdir -p config
chown -R smartdns:smartdns  config
mkdir -p /run/smartdns/
chown -R smartdns:smartdns  /run/smartdns/
mkdir -p /var/log/smartdns/
chown -R smartdns:smartdns  /var/log/smartdns/

配置文件
具体查看官网:https://pymumu.github.io/smartdns/config/basic-config/
这里只是简单列举一些配置

tee /data/app/smartdns/config/smartdns.conf <<EOF
bind [::]:53

#是否持久化缓存
cache-size 32768
cache-persist yes
cache-file /tmp/smartdns_cache
serve-expired-reply-ttl 3

#过期缓存
serve-expired yes
serve-expired-ttl 259200
serve-expired-reply-ttl 3
prefetch-domain yes
serve-expired-prefetch-time 21600

# 启用 Ping 测速(默认开启)
speed-check-mode ping,tcp:80,tcp:443

#双栈优选
dualstack-ip-selection yes

#日志
log-console yes
log-level debug
log-file /var/log/smartdns/smartdns.log
log-size 100M
log-num 5

#chinaDNS
server-https https://doh.pub/dns-query

# 配置基础的 UDP DNS 用于解析 DoH 域名
server 119.29.29.29 -bootstrap-dns
EOF

开机启动

tee /etc/systemd/system/smartdns.service <<EOF
[Unit]
Description=SmartDNS Service
After=network.target nss-lookup.target

[Service]
Type=simple
User=smartdns
RuntimeDirectory=smartdns
WorkingDirectory=/data/app/smartdns
ExecStart=/data/app/smartdns/smartdns-x86_64 -f -c /data/app/smartdns/config/smartdns.conf -p /run/smartdns/smartdns.pid
Restart=always
RestartSec=3s
LimitNOFILE=51200
AmbientCapabilities=CAP_NET_RAW CAP_NET_BIND_SERVICE
CapabilityBoundingSet=CAP_NET_RAW CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable smartdns
systemctl restart smartdns

查看运行状态

journalctl -u smartdns.service -f
journalctl -u smartdns.service -n 50

默认会把日志输出到syslog里,影响看其他日志。
这里加个过滤

tee /etc/rsyslog.d/30-smartdns.conf <<EOF
if $programname == 'smartdns-x86_64' then /var/log/syslog
& stop
EOF
systemctl restart rsyslog
CreateBy:2026-04-17,UpdateBy:2026-04-17

评论

还没有评论,欢迎第一个留言。
← 请输入您的姓名
← 请输入常用邮箱(不会公开)
← 请输入个人网站(可选)
← 请输入评论内容,文明交流
← 请先完成人机验证