I have media box in my network that hard coded to use specific DNS servers like Google DNS. But I want force this device to use my own DNS servers instead of hard coded DNS. Only way I think this is possible to mangle the DNS request coming from that media box IP to DNAT to my DNS server IP. but I'm not quite sure how do I put rule with mentioning source port and source ip at the same time

I use openwrt router with openwrt 15.0 chaos calmer on it.

iptables -t nat -A PREROUTING -p tcp --sport 53 -j DNAT --to-destination

Above query will do the job but it will mangle all the port 53 request. how can I specify this rule with IP address. or is there any other way to do it ?

2 Answers 2


I use

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

The redirect just redirects the requests to the router.


Just add -d a.b.c.d immediately after tcp, to restrict the rule to packets with destination address a.b.c.d.

And add -s e.f.g.h to also restrict by source address.

  • Thanks for the answer.. But it will mangle all the packet go to that I only need to mangle packet from certain device
    – sameera
    Apr 16, 2018 at 7:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .