Firewall custom rules DNS rewrite

Hi,

At this time I've got AdGuard Home running on my OpenWRT, but I wish to migrate it to a different machine. For devices not using the DNS server provided by option 6 of DHCP I implemented the following custom rules in the firewall (to make sure that Google DNS is intercepted and ads are blocked):

iptables -t nat -A PREROUTING -i br-lan -p tcp --dport 53 -j DNAT --to 192.168.1.1:53
iptables -t nat -A PREROUTING -i br-lan -p udp --dport 53 -j DNAT --to 192.168.1.1:53

I altered the destination IP address to new machine, but it caused a DNS loop.
How can I redirect/rewrite all DNS queries destined for other DNS servers (like Google DNS) to my new device (192.168.1.10) and just allow/forward all DNS queries coming from 192.168.1.10?

Thanks in advance!

Kind regards

config redirect 'dns_int'
        option name 'Intercept-DNS'
        option src 'lan'
        option src_dport '53'
        option proto 'tcp udp'
        option family 'any'
        option target 'DNAT'
        option enabled '0'

Add this fragment to /etc/config/firewall then find (desactivated) rule in luci/network/firewall/port forwards.

If you want ip4 and ip6 on other host than this router you need 2 rules.

Slight optimization for generated rule https://github.com/openwrt/firewall4/pull/77

1 Like

The line with the ! is the important one :slight_smile:

2 Likes

Thanks for the pointer, added to PR :wink:

Thanks! That dit it!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.