I'm at a bit of a loss.
First some context: I've got an AWS EC2 Instance behind an NLB. The NLB is using an Elastic IP. The EC2 Instance is running a DNS server and listening on UDP and TCP 53. The NLB is setup for TCP and UDP port 53. The instance is in a Target Group and healthy in the eyes of the NLB (and serving requests as expected).
Problem I'm trying to solve: I want to ensure I drop all DNS queries for record type ANY
(as well as a few other rules to rate limit and filter) so I've added the following iptables
rules:
$ iptables -t raw -I PREROUTING -p udp --dport 53 -m string \
--hex-string "|0000FF0001|" --algo bm --from 40 -j DROP
$ iptables -t raw -I PREROUTING -p tcp --dport 53 -m string \
--hex-string "|0000FF0001|" --algo bm --from 52 -j DROP
$ iptables -t raw -I PREROUTING -p udp --dport 53 -m string \
--hex-string "|0000FF0001|" --algo bm --from 40 -j LOG \
--log-prefix "BLOCKED ANY: "
$ iptables -t raw -I PREROUTING -p tcp --dport 53 -m string \
--hex-string "|0000FF0001|" --algo bm --from 52 -j LOG \
--log-prefix "BLOCKED ANY: "
Now for the problem...
If I try dig some.domain -t any @public.ip.of.instance
my query is blocked and I see the log entry in /var/log/kern.log
as expected.
If I try dig some.domain -t any @elastic.ip.on.nlb
the request is not blocked and I get a response. No log entry in kern.log
.
The weirdest part for me is that I tried taking the NLB out of the picture and assigned the same Elastic IP to the instance directly. Same result - the ANY
query sent to the EIP
is not dropped even with the above iptables
rules in place. The same ANY
query sent from another instance using the private IP instead of the EIP
is dropped as expected.
I've tried the same rules in the nat
(also using the PREROUTING
chain) and filter
(using the INPUT
chain) tables. Am I missing something obvious in my iptables
rules?
Any other ideas?