Howto configure a Mikrotik as central DHCP server with switches as DHCP relays

April 27, 2013

I’ve found many articles about how to configure a Mikrotik RouterOS as DHCP relay or as simple DHCP server, but I didn’t find an article about following setup:

  • central Mikrotik DHCP Server (e.g. in the data center)
  • multiple VLANs/subnets for clients which are connected via a Layer3 Switch (or even more hops) to the central data center

According to the Mikrotik Wiki and the described options it is possible but there is no example shown and everyone uses the setup wizard to configure a DHCP Server. I’ll get most people don’t know what happens in the background … I’ll show this the old fashioned way. 😉

Setup for this example/howto

For this example we assume that we’ve 4 VLANs with following subnets:

  • 10.88.0.0/24 (data center VLAN for the servers and the DHCP server)
  • 10.88.10.0/24 (clients network location 1)
  • 10.88.11.0/24 (clients network location 2)
  • 10.88.12.0/24 (clients network location 3)

The Mikrotik has the IP 10.88.0.100 and connected via ether1 to the data center VLAN. The Layer3 switches use always the .1 IP address in the clients networks.

Layer3 Switches / DHCP Relay

Most (if not all) switches which are able to perform at least simple layer 3 tasks (often also labeled as Layer2+ switches) are able to forward DHCP requests. Check the manual of the switch for this. One setting I came across sometimes leads to problems. It is called “DHCP Relay delay” and is sometimes set to 1 or 2 seconds in the the default configuration. This setting allows a local DHCP Server to answer faster, but sometimes (specially embedded clients) don’t wait that long and run into an error. If there is no local DHCP server set this timer to 0 seconds.

You’ll need to set the DHCP Server IP on the switch to the IP of the Mikrotik.

Mikrotik as DHCP Server

First we configure our pools of the client networks, the mikrotik will give out IPs from this ranges:

/ip pool
add name=poolClientsLocation1 ranges=10.88.10.10-10.88.10.250
add name=poolClientsLocation2 ranges=10.88.11.10-10.88.11.250
add name=poolClientsLocation3 ranges=10.88.12.10-10.88.12.250

Now we need to set the configuration the DHCP Server will handout the clients:

/ip dhcp-server network
add address=10.88.10.0/24 dns-server=10.88.0.100 gateway=10.88.10.1
add address=10.88.11.0/24 dns-server=10.88.0.100 gateway=10.88.11.1
add address=10.88.11.0/24 dns-server=10.88.0.100 gateway=10.88.12.1

And at last we configure which DHCP Relay gets which configuration/pool:

/ip dhcp-server
add address-pool=poolClientsLocation1 authoritative=yes disabled=no interface=ether1 lease-time=1w name=dhcpClientsLocation1 relay=10.88.10.1
add address-pool=poolClientsLocation2 authoritative=yes disabled=no interface=ether1 lease-time=1w name=dhcpClientsLocation2 relay=10.88.11.1
add address-pool=poolClientsLocation3 authoritative=yes disabled=no interface=ether1 lease-time=1w name=dhcpClientsLocation3 relay=10.88.12.1

This is all … 😉

12 Comments »

RSS feed for comments on this post. TrackBack URI

  1. Just a heads-up, you named all the pools the same thing in the creation command example 😉

    Comment by NewEvolution — June 18, 2013 #

  2. Been looking for a tutorial like this for a while. Would rather use an Avaya ERS for inter-VLAN routing but needed a DHCP server and didn’t want to use a Windows or Linux box. Thanks so much for posting this!

    Comment by quicky2g — June 19, 2013 #

  3. Awesome… see more http://mikrotik routersetup.blo gspot. com

    Comment by laxmi — March 27, 2014 #

  4. laxmi, your example is worst! if we have 1Gbit-per-port L3 powerfull switches, this scenario is much more better for the internal network performance :), because of the inter-vlan routing will be performed by non-blocking matrices of the switches.
    as for the scheme proposed in http://mikrotik routersetup.blog spot.com/, we get the inter-vlan routing have been performing by Mikrotik routerboard device through it’s single ethernet port… very narrow bottlneck, i think..

    Comment by ilya — May 31, 2014 #

  5. Did you really read the article? The Mikrotik can just provide the DHCP server service and no traffic must being forwarded over it. Or only the much lower internet traffic. The purpose of this article is to show how to configure the Mikrotik DHCP server to work in a setup where Layer3 Switches are being used as the default gateway for the client networks.

    Comment by robert — June 1, 2014 #

  6. Example is good, Laxmi you must firat comprehend the case which is being discussed. you wont get this case being discussed so clearly any where !

    Comment by Haroon — June 3, 2014 #

  7. Good day,

    Technically, concept is great.

    I want to know, how can we make two or more IP Pools with large number of ranges-in thousands. in such a way, dhcp server assigns IPs to perticular VLANs.
    Lets say in my scenario:

    2000 IPs on VLAN100
    and another
    2000 IPs on VLAN200

    most importantly, all hopes (L3/L2 switches)- 5 Hopes each VLAN. instead of limited to locations and assigns IPs in between 253 IPs of perticular subnets, they assign IPs available in range of 2000 IPs for associate VLANs.

    Comment by Ahmed — March 20, 2015 #

  8. Appoligize, i thing concern here. how can a Pool of 2000 IPs show as 1 pool for that VLAN instead of showing available differnet subnets for that pool. Thanx.

    Comment by Ahmed — March 20, 2015 #

  9. thanks alot for the info.

    may you please let me know which commands are going to add to mikrotik cloud switch.

    Comment by mike — February 26, 2016 #

  10. thank you for this info.

    may you please add more commands on howto configure l3 switches.

    thanks

    Comment by mike — March 1, 2016 #

  11. Thank You for sharing this great tutorial however could You please post the information how to configure Mikrotik ether port? I do not have bridge on Mikrotik and L3 switch is connected with ether1 Mikrotik.

    Ether1 has got IP address 10.88.0.244 belonging to data center VLAN. DHCP server works OK for all networks but the problem is that from Mikrotik (10.88.0.244) I can only ping clients in data center vlan. If I try to ping clients from other networks:
    10.88.10.0/24 10.88.11.0/24 10.88.12.0/24 Mikrotik says: ‘no route to host’. Also in IP/ARP I can only see MAC addressess from data center vlan.

    IP route on Mikrotik is dynamically added:
    ADC DST-ADDRESS: 10.88.0.0/24 PREF-SRC: 10.88.0.244 GATEWAY: ether1

    IP helper on L3 switch is set to 10.88.0.244


    Shall I add new route on MIKROTIK: ip route add dst-address=0.0.0.0/0 gateway=10.88.0.1 ?????

    Comment by Rad — April 7, 2016 #

  12. It depends on your setup. the default gateway is normal the direction to the internet. So maybe adding

    ip route add dst-address=10.88.10.0/24 gateway=10.88.0.1
    ip route add dst-address=10.88.11.0/24 gateway=10.88.0.1
    ip route add dst-address=10.88.12.0/24 gateway=10.88.0.1

    or you combine like this

    ip route add dst-address=10.88.18.0/21 gateway=10.88.0.1

    which is the network range 10.88.8.0 – 10.88.15.255

    is enough. If the 10.88.0.1 is also the next router on the way to the internet adding it as default gateway is ok.

    it really depends on your setup.

    Comment by robert — April 8, 2016 #

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Powered by WordPress
Entries and comments feeds. Valid XHTML and CSS. 36 queries. 0.049 seconds.