iptables drop negative DNS responses
Solution 1:
Offset for DNS flags in ip packet is 28bytes and you need to check last 2 bits in 2byte field
u32 rule for that is "28&0x000F=0x03"
My test rule is: iptables -A INPUT -m u32 -p udp --sport 53 --u32 "28&0x000F=0x03" -j LOG
BTW I like the idea to use this firewall rule for split horizon DNS, going to test it for some of my networks.
Solution 2:
This drops BIND9 "rejected" replies to the current spoofed UDP queries!
iptables -F OUTPUT
#iptables -A OUTPUT -p udp --sport 53 -j LOG --log-prefix="OUT-UPD-RAW : "
#iptables -A OUTPUT -m u32 -p udp --sport 53 --u32 "28&0xFFFF=0x8105" -j LOG --log-prefix="STOPPED-DNS-REJECTED-REPLY "
iptables -A OUTPUT -m u32 -p udp --sport 53 --u32 "28&0xFFFF=0x8105" -j DROP
iptables -A OUTPUT -p udp --sport 53 -j LOG --log-prefix="OUT-UPD-SENT: "