Can a DHCP give to a specific MAC a different IP/mask/gateway?

Hi, I’ve a client which needs to keep devices connected to a specific IP subnetm between them there is a TV, connected to a remote Layer2 switch, which needs lot of bandwith. The client has a second internet connection for guests, I would use that bandwith for the TV, my idea is to create on LAN mikrotik interface a second IP address, so I can eventually configure a static IP to the TV, but how can eventually give it by DHCP? Is it possible?
Or should I create 2 different DHCP, assign them to the same bridge, black list that MAC to the main DCHP and white list it on the second DHCP?
Thanks

DHCP server in ROS is a bit flexible, so you may be able to do what you are after.

You can set up a static lease, based on client-id (which most of times closely resembles MAC address). Static lease includes allocated IP address. As to the rest of lease information (addresses of gateway, DNS server, NTP server, etc.), they are set in network section of DHCP server setup. There can be multiple network entries with different (non-overlapping) address/mask settings. When DHCP server selects address to lease, it adds other parameters from matching network entry. So if the allocated address for special device is differrnt enough from “defaults”, it can then come with different set of parameters.


/ip pool
add name=pool ranges=192.168.41.10-192.168.41.127
/ip dhcp-server
add address-pool=pool interface=bridge name=dhcp-bridge
/ip dhcp-server lease
add address=192.168.41.249 client-id=1:0:4:30:99:ad:e2 mac-address=00:04:30:99:AD:E2 server=dhcp-bridge
/ip dhcp-server network
add address=192.168.41.0/25 gateway=192.168.41.1 netmask=24 dns-server=8.8.8.8
add address=192.168.41.128/25 comment="settings for upper half of subnet"  \
    gateway=192.168.41.1 netmask=24 ntp-server=192.168.41.1 dns-server=1.1.1.1

To make sure that client-id and mac-address properties of static lease are correct, I always let device obtain a dynamic lease, then convert that lease to static and adjust properties ad needed (change address, etc.).

thanks for help, I?ve followed your example but I added a second IP subnet, so I proceed in this way:

  • I’ve created a second IP address with mask and assigned to the main bridge
  • I’ve added a network address to the DHCP (under Networks) according that subnet
  • I’ve made the lease for my phone static and I’ve changed it to the second subnet, then I’ve turned off and on WiFi on my phone and yes, I got the desidered address, mask and gateway as desidered.

Thobelm then is solved, but I’ve a dubt: will I be sure the dinamic clients will get always the first subnet when connecting? is the logic of mikrotik to choose the first/on top networks always?
I can’t find a way to force disable the second address for dynamics, for example writing something under DHCP options.
Thank you

DHCP server hands out either

  1. statically set addresses if client-id matches
  2. addresses from configured pool

in this order. So if you only set one address pool within original IP subnet, then DHCP server will not hand out addresses from second subnet to “unknown” clients. And the rest of parameters are always taken from matching “network” settings. But DHCP server will never pull IP addresses for offers “out of thin air”.

Thank you, so to be sure I just don’t create a pool for second network.
Can you please write me with outer words “But DHCP server will never pull IP addresses for offers “out of thin air”.” I’m not sur I’ve understood it, thanks

I meant that DHCP server wil only offer leases with addresses which are either statically set (for static leases) or from (pre-)configured pool.

For example: if new DHCP client doesn’t match any of static leases and pool of addresses is exhausted (all addresses are occupied), then DHCP server will not offer a lease to that client.

thanks, in few words is just necessary to don’t configure a pool for the second subnet, in this case a dynamic device will never get the second subnet address, as desidered.
The second subnet will be assigned only to static leases, according to what is specified on that static lease
Thank you