Skip to content

Instantly share code, notes, and snippets.

@romuald
Last active February 22, 2022 15:58
Show Gist options
  • Save romuald/4a96195702bf535be9c0 to your computer and use it in GitHub Desktop.
Save romuald/4a96195702bf535be9c0 to your computer and use it in GitHub Desktop.
Drop DNS queries for specific domain names only
#!/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