openwrt 域名过滤功能通过dnsmasq实现

张开发
2026/4/10 21:32:19 15 分钟阅读

分享文章

openwrt 域名过滤功能通过dnsmasq实现
OpenWrt中配置dnsmasq的域名过滤功能,主要是配置/etc/dnsmasq.conf文件中增加conf-file=/etc/data/blocklist.conf 这个配置我们过滤的域名文件用脚本/usr/sbin/domain_blocklist.sh实现对blocklist.conf的域名设置如下:=======================================================#!/bin/shBLOCKLIST_FILE="/etc/data/blocklist.conf"DOMAINS=$(uci get firewall.blocklist.domains 2/dev/null) #从firewall.blocklist.domains配置获取需要过滤的域名echo "# Domain blacklist generated on $(date)" $BLOCKLIST_FILEfor domain in $DOMAINS; do domain=$(echo "$domain" | xargs) if [ -z "$domain" ]; then continue fi if echo "$domain" | grep -qE '^[a-zA-Z0-9-]+\.[a-zA-Z]{2,}$' ! echo "$domain" | grep -qE '\.[a-zA-Z0-9-]+\.[a-zA-Z]{2,}$'; then echo "address=/.$domain/0.0.0.0" "$BLOCKLIST_FILE" echo "address=/.$

更多文章