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):

blocker.sh

# www.linuxonlinehelp.eu 2019
# DNS Blocker for Small Linux with dnsmasq
#

#!/bin/bash

# goto tmp (tmpfs)
cd /tmp/  

# get URL-Blocklists
wget -O blocklist.txt https://v.firebog.net/hosts/Kowabit.txt  # get Templates

#SET Variables
txt='blocklist.txt'
IP='0.0.0.0'  # set to 0.0.0.0 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 !!

#info
echo OK-TEST-NOW

Remark:

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

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