Mikrotik – splitting your local LAN so you can assign different gateways and DNS servers by the DHCP server
Posted by jpluimers on 2017/06/09
When you want your Mikrotik DHCP Server handout different gateways (or DNS/WINS/NTP/.. servers and other settings), many of the answers tell you to fiddle with the DHCP networks like DHCP Server different gateways – MikroTik RouterOS [WayBack] but lack concrete examples, so here we go elaborating a lot on DHCP server with static leases – MikroTik RouterOS [WayBack]:
DHCP on a Mikrotik starts with one or more DHCP servers each services on a certain interface from an address pool:
In my case, the pool spans most of a /24 network leaving some room for non-DHCP configured hosts at the bottom and top of the /24 range:
The DHCP server hands out addresses from that pool either static or dynamic as you can make each entry static using the Make Static button:
With a static entry, you can change other options (and revert to dynamic by pressing the Remove button) like the Address or Server:
Back to the DHCP server: it matches the address handed out by the pool (either static or dynamic) with the configured DHCP networks and based on the match the DHCP server will send specific information the gateway/DNS/WINS/NTP servers and other options from the DHCP network to the client.
Most configurations start out with just one configured DHCP network which means they have one set of gateway/DNS/WINS/NTP servers and other options:
The trick to get multiple sets of gateway/DNS/WINS/NTP servers and other DHCP options is two-fold:
- Split the DHCP network into multiple subnets
- Use static DHCP leases to force certain hosts in certain subnets
An important thing to remember here: be sure to care for IP addresses that were handed out but after the split fall into the “reserved” part of a network (the network address at the bottom and broadcast address at the top of each subnet) and re-assign any of those addresses
So i used wanted to split my 192.168.71.128/24 local network into a few sub-networks: one /25 and two /26 networks.
For this I used ipcalc (an online version is at IP Calculator / IP Subnetting aka http://jodies.de/ipcalc) which I mentioned before in Getting the IP addresses of gmail MX servers – via Super User – dig isn’t enough.
I used these to split up the network
- http://jodies.de/ipcalc?host=192.168.71.0&mask1=24&mask2=26 [WayBack]
- http://jodies.de/ipcalc?host=192.168.71.0&mask1=24&mask2=25 [WayBack]
Note I could have split them in four /26 subnets but that meant going from 254 hosts back to 248 (62+62+62+62). Now I go back to 250 (126 + 62 + 62) hosts:
Subnet:Address: 192.168.71.0 11000000.10101000.01000111 .00000000 Netmask: 255.255.255.0 = 24 11111111.11111111.11111111 .00000000 Wildcard: 0.0.0.255 00000000.00000000.00000000 .11111111 => Network: 192.168.71.0/24 11000000.10101000.01000111 .00000000 (Class C) Broadcast: 192.168.71.255 11000000.10101000.01000111 .11111111 HostMin: 192.168.71.1 11000000.10101000.01000111 .00000001 HostMax: 192.168.71.254 11000000.10101000.01000111 .11111110 Hosts/Net: 254 (Private Internet)Subnets Netmask: 255.255.255.128 = 25 11111111.11111111.11111111.1 0000000 Wildcard: 0.0.0.127 00000000.00000000.00000000.0 1111111 Network: 192.168.71.0/25 11000000.10101000.01000111.0 0000000 (Class C) Broadcast: 192.168.71.127 11000000.10101000.01000111.0 1111111 HostMin: 192.168.71.1 11000000.10101000.01000111.0 0000001 HostMax: 192.168.71.126 11000000.10101000.01000111.0 1111110 Hosts/Net: 126 (Private Internet)Netmask: 255.255.255.192 = 26 11111111.11111111.11111111.11 000000 Wildcard: 0.0.0.63 00000000.00000000.00000000.00 111111 Network: 192.168.71.128/26 11000000.10101000.01000111.10 000000 (Class C) Broadcast: 192.168.71.191 11000000.10101000.01000111.10 111111 HostMin: 192.168.71.129 11000000.10101000.01000111.10 000001 HostMax: 192.168.71.190 11000000.10101000.01000111.10 111110 Hosts/Net: 62 (Private Internet) Network: 192.168.71.192/26 11000000.10101000.01000111.11 000000 (Class C) Broadcast: 192.168.71.255 11000000.10101000.01000111.11 111111 HostMin: 192.168.71.193 11000000.10101000.01000111.11 000001 HostMax: 192.168.71.254 11000000.10101000.01000111.11 111110 Hosts/Net: 62 (Private Internet)Subnets: 3 Hosts: 250
Since ipcalc cannot do that in one step, I’ve done 2 steps.
Going from 254 to 250 hosts means these addresses cannot be used any more:
- 192.168.71.127
- 192.168.71.128
- 192.168.71.191
- 192.168.71.192
Luckily I didn’t have these in use, so now my DHCP networks are these:
Which now I can experiment getting the second gateway working correctly by moving a static DHCP lease into the 3rd network (192.168.71.192/26), in this case from dynamic into static:
And after some waiting:
Turned into:
–jeroen
PS: one of my external nets: http://jodies.de/ipcalc?host=37.153.243.242&mask1=29&mask2=
$ ipcalc 37.153.243.242/29 Address: 37.153.243.242 00100101.10011001.11110011.11110 010 Netmask: 255.255.255.248 = 29 11111111.11111111.11111111.11111 000 Wildcard: 0.0.0.7 00000000.00000000.00000000.00000 111 => Network: 37.153.243.240/29 00100101.10011001.11110011.11110 000 HostMin: 37.153.243.241 00100101.10011001.11110011.11110 001 HostMax: 37.153.243.246 00100101.10011001.11110011.11110 110 Broadcast: 37.153.243.247 00100101.10011001.11110011.11110 111 Hosts/Net: 6 Class A
Address: 37.153.243.242 00100101.10011001.11110011.11110 010 Netmask: 255.255.255.248 = 29 11111111.11111111.11111111.11111 000 Wildcard: 0.0.0.7 00000000.00000000.00000000.00000 111 => Network: 37.153.243.240/29 00100101.10011001.11110011.11110 000 (Class A) Broadcast: 37.153.243.247 00100101.10011001.11110011.11110 111 HostMin: 37.153.243.241 00100101.10011001.11110011.11110 001 HostMax: 37.153.243.246 00100101.10011001.11110011.11110 110 Hosts/Net: 6
















Leave a comment