Score:0

iptables redirect hardcoded DNS requests

in flag

I'm slowly trying to learn iptables and would like to redirect all DNS (port 53) requests not coming from/to a list of IPs (from 192.168.2.1, 192.168.2.29 or to 1.1.1.1). I figured I can use chains. It does not work though. Could you please give me a hint:

iptables -N dnsrewrite
iptables -A dnsrewrite -s 192.168.2.1 -j RETURN
iptables -A dnsrewrite -s 192.168.2.29 -j RETURN
iptables -A dnsrewrite -d 1.1.1.1 -j RETURN
iptables -t nat -A dnsrewrite -j DNAT --to-destination 192.168.2.29
iptables -t nat -A POSTROUTING -p tcp --dport 53 -j MASQUERADE
iptables -t nat -A POSTROUTING -p udp --dport 53 -j MASQUERADE
iptables -A PREROUTING -p tcp --dport 53 -j dnsrewrite
iptables -A PREROUTING -p udp --dport 53 -j dnsrewrite
Michael Hampton avatar
cz flag
It said: `Run \`dmesg' for more information.`
John Smith avatar
in flag
There was no more info there really.
Score:0
in flag
iptables -t nat -N dnsrewrite
iptables -t nat -A dnsrewrite -j DNAT --to-destination 192.168.2.29

iptables -t nat -N whitelist
iptables -t nat -A whitelist -s 192.168.2.1 -j RETURN
iptables -t nat -A whitelist -s 192.168.2.29 -j RETURN
iptables -t nat -A whitelist -d 1.1.1.1 -j RETURN
iptables -t nat -A whitelist -j dnsrewrite

iptables -t nat -A PREROUTING -p tcp --dport 53 -j whitelist
iptables -t nat -A PREROUTING -p udp --dport 53 -j whitelist

Whether these suit you needs depends.

iptables -t nat -A POSTROUTING -p tcp --dport 53 -j MASQUERADE
iptables -t nat -A POSTROUTING -p udp --dport 53 -j MASQUERADE
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.