Hero Image
Mosdns-X

Mosdns-X 讓 Linux 系統的 DNS 更快更乾淨:部署 Mosdns-X 安裝 bash <(curl -sL https://raw.githubusercontent.com/lidebyte/bashshell/refs/heads/main/mosdns-x-manager.sh) 設定 sudo tee /etc/mosdns-x/config.yaml > /dev/null <<'EOF' # mosdns-x 并发查询(无分流)配置 log: level: info file: /var/log/mosdns-x/mosdns-x.log plugins: # 缓存插件 - tag: cache type: cache args: size: 1024 lazy_cache_ttl: 1800 # 并发上游:取最先返回的可用答案 - tag: forward_all type: fast_forward args: upstream: # 阿里 - addr: "udp://223.5.5.5" - addr: "tls://dns.alidns.com" # DNSPod / doh.pub - addr: "udp://119.29.29.29" - addr: "tls://dot.pub" # Cloudflare - addr: "udp://1.1.1.1" - addr: "tls://cloudflare-dns.com" # Google - addr: "udp://8.8.8.8" - addr: "tls://dns.google" # 主流水线:小缓存 → 并发优选 - tag: main type: sequence args: exec: - cache - forward_all # 监听(双栈 UDP/TCP 53) servers: - exec: main listeners: - addr: :53 protocol: udp - addr: :53 protocol: tcp EOF systemd sudo tee /etc/systemd/system/mosdns.service > /dev/null <<'EOF' [Unit] Description=Mosdns-X DNS Accelerator After=network.target [Service] Type=simple User=root Group=root ExecStart=/usr/local/bin/mosdns-x start --as-service -d /usr/local/bin -c /etc/mosdns-x/config.yaml Restart=always RestartSec=5 StandardOutput=journal StandardError=journal SyslogIdentifier=mosdns [Install] WantedBy=multi-user.target EOF sudo systemctl daemon-reload sudo systemctl enable --now mosdns # 备份系统 DNS sudo cp -n /etc/resolv.conf /etc/resolv.conf.mosdns-backup # 改为使用本地 Mosdns-X echo -e "nameserver 127.0.0.1\noptions edns0" | sudo tee /etc/resolv.conf # 若 53 端口被 systemd-resolved 占用,可禁用它 sudo systemctl disable --now systemd-resolved 2>/dev/null || true # 如果想顺便加锁(防止被 DHCP 修改),加上 chattr 一起执行: echo -e "nameserver 127.0.0.1\n" > /etc/resolv.conf && chattr +i /etc/resolv.conf # 查看进程状态 sudo systemctl status mosdns --no-pager # 测试解析速度(第二次命中缓存更快) dig +stats www.google.com dig +stats www.baidu.com # 查看实时日志 tail -f /var/log/mosdns-x/mosdns-x.log

Hero Image
Go 文章

學會 gin 參數校驗之 validator 函式庫,看這一篇就夠了 字串約束 excludesall:不包含參數中任意的 UNICODE 字元,例如 excludesall=ab excludesrune:不包含參數表示的 rune 字元,excludesrune=asong startswith:以參數子字串為前綴,例如 startswith=hi endswith:以參數子字串為後綴,例如 endswith=bye。 contains=:包含參數子字串,例如 contains=email containsany:包含參數中任意的 UNICODE 字元,例如 containsany=ab containsrune:包含參數表示的 rune 字元,例如 containsrune=asong excludes:不包含參數子字串,例如 excludes=email 範圍約束 範圍約束的欄位型別分為三種: 對於數值,我們可以約束其值 對於切片、陣列和 map,我們可以約束其長度 對於字串,我們可以約束其長度 常用 tag 介紹: ne:不等於參數值,例如 ne=5 gt:大於參數值,例如 gt=5 gte:大於等於參數值,例如 gte=50 lt:小於參數值,例如 lt=50 lte:小於等於參數值,例如 lte=50 oneof:只能是列舉出的值其中之一,這些值必須是數值或字串,以空格分隔;如果字串中有空格,請用單引號包起來,例如 oneof=male female。 eq:等於參數值,注意與 len 不同。對於字串,eq 約束字串本身的值,而 len 約束字串長度。例如 eq=10 len:等於參數值,例如 len=10 max:小於等於參數值,例如 max=10 min:大於等於參數值,例如 min=10 欄位約束 eqfield:定義欄位間相等約束,用於約束同一結構體中的欄位。例如:eqfield=Password eqcsfield:約束同一結構體中欄位等於另一個欄位(相對),確認密碼時可以使用,例如:eqcsfield=ConfirmPassword nefield:用來約束兩個欄位是否不同,確認兩種顏色是否一致時可以使用,例如:nefield=Color1 necsfield:約束兩個欄位是否不同(相對) 常用約束 unique:指定唯一性約束,不同型別處理不同: