Is there an easier way to route certain IP's to different DNS servers?

I run an AdGuard server where some IP DNS are routed to.
But I wanted to know if there is a slicker way of doing this?
At the moment I set devices with static IP’s then in the DNS options, available when you set devices with a static IP, I set the IP for the AdGuard server.
Below is the current config…


/ip dhcp-server option
add code=6 name=AdGuard_Home value="'192.168.50.99'"

/ip pool
add name=dhcp ranges=192.168.50.100-192.168.50.254
/ip dhcp-server
add address-pool=dhcp interface=bridge lease-time=1h name=defconf

/ip address
add address=192.168.50.1/24 interface=bridge network=192.168.50.0

/ip dhcp-server lease
add address=192.168.50.3 client-id=1:00:00:00:00 mac-address=\
    88:88:88:88:88:88 server=defconf
add address=192.168.50.12 client-id=1:00:00:00:00 dhcp-option=\
    AdGuard_Home mac-address=88:88:88:88:88:88 server=defconf
add address=192.168.50.11 client-id=1:00:00:00:00 dhcp-option=\
    AdGuard_Home mac-address=88:88:88:88:88:88 server=defconf
add address=192.168.50.58 dhcp-option=AdGuard_Home mac-address=\
    88:88:88:88:88:88 server=defconf
add address=192.168.50.15 client-id=1:00:00:00:00 mac-address=\
    88:88:88:88:88:88 server=defconf
add address=192.168.50.16 client-id=1:00:00:00:00 mac-address=\
    88:88:88:88:88:88 server=defconf
add address=192.168.50.2 client-id=1:00:00:00:00 mac-address=\
    08:55:31:26:F8:1D server=defconf
add address=192.168.50.63 client-id=1:00:00:00:00 dhcp-option=\
    AdGuard_Home mac-address=88:88:88:88:88:88 server=defconf
add address=192.168.50.44 client-id=1:00:00:00:00 mac-address=\
    88:88:88:88:88:88 server=defconf
add address=192.168.50.43 client-id=1:00:00:00:00 mac-address=\
    88:88:88:88:88:88 server=defconf
add address=192.168.50.42 client-id=1:00:00:00:00 mac-address=\
    88:88:88:88:88:88 server=defconf
add address=192.168.50.18 client-id=1:00:00:00:00 mac-address=\
    88:88:88:88:88:88 server=defconf
add address=192.168.50.17 client-id=1:00:00:00:00 mac-address=\
    88:88:88:88:88:88 server=defconf
add address=192.168.50.5 client-id=1:00:00:00:00 mac-address=\
    88:88:88:88:88:88 server=defconf
add address=192.168.50.4 client-id=1:00:00:00:00 mac-address=\
    88:88:88:88:88:88 server=defconf
add address=192.168.50.6 client-id=1:00:00:00:00 mac-address=\
    88:88:88:88:88:88 server=defconf
add address=192.168.50.51 client-id=1:00:00:00:00 dhcp-option=\
    AdGuard_Home mac-address=88:88:88:88:88:88 server=defconf
add address=192.168.50.52 client-id=1:00:00:00:00 dhcp-option=\
    AdGuard_Home mac-address=88:88:88:88:88:88 server=defconf
add address=192.168.50.55 client-id=1:00:00:00:00 dhcp-option=\
    AdGuard_Home mac-address=88:88:88:88:88:88 server=defconf
add address=192.168.50.59 dhcp-option=AdGuard_Home mac-address=\
    88:88:88:88:88:88 server=defconf
add address=192.168.50.62 client-id=1:00:00:00:00 dhcp-option=\
    AdGuard_Home mac-address=88:88:88:88:88:88 server=defconf
add address=192.168.50.61 client-id=1:00:00:00:00 dhcp-option=\
    AdGuard_Home mac-address=88:88:88:88:88:88 server=defconf
add address=192.168.50.71 client-id=1:00:00:00:00 comment=shield_TV \
    dhcp-option=AdGuard_Home mac-address=88:88:88:88:88:88 server=defconf
add address=192.168.50.60 client-id=1:00:00:00:00 dhcp-option=\
    AdGuard_Home mac-address=88:88:88:88:88:88 server=defconf
add address=192.168.50.65 client-id=1:00:00:00:00 dhcp-option=\
    AdGuard_Home mac-address=88:88:88:88:88:88 server=defconf
add address=192.168.50.41 client-id=1:00:00:00:00 mac-address=\
    88:88:88:88:88:88 server=defconf
add address=192.168.50.67 client-id=1:00:00:00:00 comment=small_TV \
    dhcp-option=AdGuard_Home mac-address=88:88:88:88:88:88 server=defconf
add address=192.168.50.57 client-id=1:00:00:00:00 dhcp-option=\
    AdGuard_Home mac-address=88:88:88:88:88:88 server=defconf
add address=192.168.50.53 client-id=1:00:00:00:00 dhcp-option=\
    AdGuard_Home mac-address=88:88:88:88:88:88 server=defconf
add address=192.168.50.69 client-id=1:00:00:00:00 dhcp-option=\
    AdGuard_Home mac-address=88:88:88:88:88:88 server=defconf
add address=192.168.50.70 client-id=1:00:00:00:00 mac-address=\
    88:88:88:88:88:88 server=defconf
add address=192.168.50.68 dhcp-option=AdGuard_Home mac-address=\
    88:88:88:88:88:88 server=defconf
add address=192.168.50.45 client-id=1:00:00:00:00 dhcp-option=\
    AdGuard_Home mac-address=88:88:88:88:88:88 server=defconf
add address=192.168.50.46 client-id=1:00:00:00:00 dhcp-option=\
    AdGuard_Home mac-address=88:88:88:88:88:88 server=defconf
add address=192.168.50.10 client-id=1:00:00:00:00 mac-address=\
    88:88:88:88:88:88 server=defconf
add address=192.168.50.64 client-id=1:00:00:00:00 dhcp-option=\
    AdGuard_Home mac-address=88:88:88:88:88:88 server=defconf
add address=192.168.50.47 client-id=1:00:00:00:00 mac-address=\
    88:88:88:88:88:88 server=defconf

/ip dhcp-server network
add address=192.168.50.0/24 comment=defconf dns-server=1.1.1.2,1.0.0.2 \
    gateway=192.168.50.1 netmask=24

/ip dns
set allow-remote-requests=yes servers=1.1.1.2,1.0.0.2
/ip dns static
add address=192.168.50.1 comment=defconf name=router.lan

So it achieves what I want it to but want to know how others would achieve the same result.

I thought about setting 2 DHCP pools in the same subnet, if possible. Like 192.168.50.1 - 99 & 192.168.50.100 - 254, then set the 1st pool with DNS of 1.1.1.2, and the second pool with a DNS of 192.168.50.99. Then just static IP devices in the relevant pool.

Stick to subnets defined by netmasks and you can have e.g.:

/ip dhcp-server network
add address=192.168.50.10/32 dns-server=8.8.4.4 netmask=24 <other options>
add address=192.168.50.64/26 dns-server=192.168.50.99 netmask=24 <other options>
add address=192.168.50.128/26 dns-server=8.8.8.8 netmask=24 <other options>
add address=192.168.50.0/24 dns-server=1.1.1.2 <other options>

These will cover:

192.168.50.10 (single host)
192.168.50.64 - 192.168.50.127
192.168.50.128 - 192.168.50.191
all other 192.168.50.x

That is a much neater way that I will use.

Just one thing, which may not be necessary. Can I use 2 DNS servers? I.E.


/ip dhcp-server network
add address=192.168.50.10/32 dns-server='8.8.4.4,8.8.8.8' netmask=24 <other options>

Yes, but like this:

dns-server=8.8.4.4,8.8.8.8

Thanks for your help

Although the suggestion worked, a few days later I had issues with wireless devices not able to access the DHCP server. And access to the Emby server was slow from my phone.

Can you explain the netmask command in the code…


/ip dhcp-server network
add address=192.168.50.10/32 dns-server=8.8.4.4 netmask=24 <other options>
add address=192.168.50.64/26 dns-server=192.168.50.99 netmask=24 <other options>
add address=192.168.50.128/26 dns-server=8.8.8.8 netmask=24 <other options>
add address=192.168.50.0/24 dns-server=1.1.1.2 <other options>

Also I set the DHCP pool from .129 - .254.

Server by default takes mask from address. But you don’t want that, so you can override it with netmask parameter.