How can I change default DNS servers?

May 4, 2014 1.6k views
How to block dns requests from google (8.8.8.8) and level3 (4.2.2.1, etc)? I tried this with iptables but nothing happens: iptables -A INPUT -s 8.8.8.8 -j DROP iptables -A OUTPUT -d 8.8.8.8 -j DROP iptables -A INPUT -s 8.8.4.4 -j DROP iptables -A OUTPUT -d 8.8.4.4 -j DROP iptables -A INPUT -s 4.2.2.1 -j DROP iptables -A OUTPUT -d 4.2.2.1 -j DROP iptables -A INPUT -s 4.2.2.2 -j DROP iptables -A OUTPUT -d 4.2.2.2 -j DROP iptables -A INPUT -s 4.2.2.3 -j DROP iptables -A OUTPUT -d 4.2.2.3 -j DROP iptables -A INPUT -s 4.2.2.4 -j DROP iptables -A OUTPUT -d 4.2.2.4 -j DROP iptables -A INPUT -s 4.2.2.5 -j DROP iptables -A OUTPUT -d 4.2.2.5 -j DROP iptables -A INPUT -s 4.2.2.6 -j DROP iptables -A OUTPUT -d 4.2.2.6 -j DROP
3 Answers
Empty your iptables rules using
iptables -F

iptables -X

and try to block the port and ip with
iptables -A INPUT -i eth0 -p tcp --destination-port 53 -s 8.8.8.8 -j DROP
I just remembered that there is also in /etc/network/interfaces for Ubuntu/Debian. You can remove the last line
dns-nameservers 8.8.4.4 8.8.8.8 209.244.0.3
Port 53 was blocked and /etc/network/interfaces also was configured with other DNS nameservers, but still receiving google and level 3 nameservers.

Have another answer? Share your knowledge.