Thank you for the reply. I have too many containers in my raspberry with their own static IP using macvlan, So, excluded the different subnet. So, I had this dhcp-server network setup with the nat rule you provided:
/ip dhcp-server network
add address=192.168.88.0/24 dns-server=192.168.88.5 gateway=192.168.88.1
add address=192.168.88.5/32 dns-server=192.168.88.1 gateway=192.168.88.1
/ip firewall nat
add action=dst-nat chain=dstnat dst-address=192.168.88.5 dst-port=53 protocol=tcp to-address=192.168.88.1 comment=pihole_bypass disabled=yes
add action=dst-nat chain=dstnat dst-address=192.168.88.5 dst-port=53 protocol=udp to-address=192.168.88.1 comment=pihole_bypass disabled=yes
And then schedule the script as follow:
:if ([/ip firewall nat get [find where comment=pihole_bypass] disabled]=yes) do={:do {resolve google.com server=192.168.88.5} on-error={/ip firewall nat enable [find where comment=pihole_bypass]}} else={:do {resolve google.com server=192.168.88.5; /ip firewall nat disable [find where comment=pihole_bypass]}}
But, the issue is that the script is running but not enabling the nat rules. Also, from my previous tries on redirecting through nat rules doesn’t yield any results. though nat rules catch some traffics and send them to pihole. Pihole can resolve them by its own dns, but cant forward those queries when the dns on pihole is set to the router.
So, I enabled the nat rules manually and turned off my pihole, but those rules showing 0B traffic. Then I added the
/ip route
add dst-address=192.168.88.5 gateway=bridge
But, without any luck.
Currently , the only solution I was able to partially make work is:
/ip dhcp-server network
add address=192.168.88.0/24 dns-server=192.168.88.5 gateway=192.168.88.1
add address=192.168.88.5/32 dns-server=192.168.88.1 gateway=192.168.88.1
Scheduler script:
:local currentDNS "192.168.88.5"
:local gateway "192.168.88.1"
:local piholeDNS "192.168.88.5"
:local testDomain "www.google.com"
:if ([/ip dhcp-server network get [find dns-server=$piholeDNS]]) do={
:do {
:resolve $testDomain server $piholeDNS
} on-error={
/ip dhcp-server network remove [find comment="defconf"]
/ip dhcp-server network add address=192.168.88.0/24 comment=defconf gateway=$gateway netmask=24
}
} else={
:do {
:resolve $testDomain server $piholeDNS
/ip dhcp-server network set 0 address=192.168.88.0/24 dns-server=$piholeDNS comment=defconf gateway=$gateway netmask=24
} on-error={}
}
The issue with this script is that it stops working after [ code] } else={[/code] . Breakdown of the code:
Line 1 :
:local currentDNS "192.168.88.5"
I really love to have some rules like
[/ip dns get servers]
and tried
[/ip dhcp-server network address=192.168.88.0/24 comment=defconf get dns-servers]
but didn’t get any results. Closest I found is that
:local currentDHCPDNS [/ip dhcp-server network print count-only where dns-server=$piholeDNS]
. But couldn’t make that work with
Line 6:
:if ($currentDNS = $piholeDNS) do={
, so I ended up with
Line 6:
::if (/ip dhcp-server network get [find dns-server=$piholeDNS]) do={
Line 9 :
/ip dhcp-server network set 0 address=192.168.88.0/24 dns-server=$piholeDNS comment=defconf dns-none=yes gateway=$gateway netmask=24
This code executed correctly. But had some difficulties understanding what it does and also reverse command at line 16
/ip dhcp-server network set 0 address=192.168.88.0/24 dns-server=$piholeDNS comment=defconf dns-none=no gateway=$gateway netmask=24
after
} else={
doesn’t work and seems buggy.

The Dns address should be in the first field. not the second line.
So, I added
Line 10:
/ip dhcp-server network remove [find comment="defconf"]
Line 11:
/ip dhcp-server network add address=192.168.88.0/24 comment=defconf gateway=$gateway netmask=24
Where, line 10 removes the address and line 11 adds a line without the DNS server.
Line 13:
} else={
After, this nothing works.
Line 16:
/ip dhcp-server network set 0 address=192.168.88.0/24 dns-server=$piholeDNS comment=defconf gateway=$gateway netmask=24
Does not adds the dns value in the field.
Any elegant working solution will be very much appreciated and helpful.