Script DNS Blocker DNSMASQ

If you tested pihole, you perhaps look for a smaller Command Line version?
Install dnsmasq by:

 sudo apt-get install dnsmasq

Here DNS Rule Injector Script (copy & paste):

# 2019
# DNS Blocker for Small Linux with dnsmasq


# goto tmp (tmpfs)
cd /tmp/  

# get URL-Blocklists
wget -O blocklist.txt  # get Templates

#SET Variables
IP=''  # set to or to a Webserver with "white Page" showing Text "URL-blocked!! 

#merge URLs and redirect to wanted IP - Rule creation
n=1; while read line; do echo 'address=/'$line'/$IP '>> 02-blocked1.conf ; n=$((n+1)); done < $txt #remove old rules rm -rf /etc/dnsmasq.d/02-blocked.conf # 1 Sec to sync disks sleep 1 #inject new rules to DNSMASQ cat 02-blocked1.conf | head -n -1 > /etc/dnsmasq.d/02-blocked.conf  #inject new rules
# reload !!
/etc/init.d/dnsmasq restart # reload !!



  • Please mail me Errors!
  • Slow Run for Test as „sh -x“ (slow output to Terminal ~10000 URLs!)
  • Fast Run „sh“ without output to Screen in some Seconds
  • Can be used for cron Timer!
Impressum Datenschutz-DSGVO-GDPR

Last Update 08.10.2023 - Nonprofit Linux PC & Server Support since 2004 Tags: Linux Online Help, Linuxonlinehelp, Linux Support, Linux Hilfe