Last active
February 22, 2022 15:58
-
-
Save romuald/4a96195702bf535be9c0 to your computer and use it in GitHub Desktop.
Drop DNS queries for specific domain names only
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Drop DNS queries for specific domain names only | |
for DOMAIN in $@; do | |
HEX=$(perl -e 'print map {chr(length($_)).$_} split /\./, "'$DOMAIN'"' | xxd -p) | |
iptables -A OUTPUT -p udp --dport 53 \ | |
-m string --hex-string "|$HEX|" --algo bm -j DROP | |
# Alternatively, drop responses only | |
# Note that this is NOT correct and will drop any response *containing* this name, | |
# not only responses for this name | |
# iptables -A INPUT -p udp --sport 53 \ | |
# -m string --hex-string "|$HEX|" --algo bm -j DROP | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment