How to provision a Mikrotik router as a dhcp relay agent.

If you are a Mikrotik user, chances are you have seen the DHCP relay feature severally but do not know what it is used for or how it can be configured. The DHCP relay feature is used to provision a Mikrotitik router to act as a DHCP server on behalf of the real DHCP server. In this piece, we will look it how to configure a DHCP relay to mediate between the dhcp server and dhcp clients.

Network Topology

Mikrotik dhcp relay agent
Image showing a dhcp relay behind a dhcp server


As can be seen in the diagram above, the dhcp server is on the same network with the dhcp relay while the dhcp clients are not on the same network as the dhcp server. The dhcp relay, in turn, is on the same network with the hosts. When a dhcp request is sent from network hosts, the dhcp relay receives it and forwards the request to the dhcp server. The question on most people’s mind at this point is, why do I need a dhcp relay? Why can’t I just configure a dhcp server instead. Well, in a nutshell, a dhcp relay agent is used to forward dhcp requests and replies between a dhcp server and clients who are not on the same subnets.
In this demonstration, I will configure a dhcp server for the two LAN subnets attached to the dhcp relay. Here is how it is done. First, IPs have to be assigned to the interface connecting to the dhcp-relay as shown below.
ip address> print
Flags: X –
disabled, I – invalid, D – dynamic
 0   To-dhcp-Relay
ip address>
Now, we specify the pools for the two networks connected the dhcp-relay. See below:
/ip pool add name=Local1-Pool ranges=

/ip pool add name=Local1-Pool ranges=

ip pool> print
 # NAME                                         RANGES
 0 Local1-Pool                        
 1 Local2-Pool                        

 [admin@DHCP-Server]ip pool>


Next, we create dhcp servers. See below:
/ip dhcp-server add interface=To-dhcp-relay relay= address-pool=Local1-Pool name=DHCP-1 disabled=no
/ip dhcp-server add interface=To-dhcp-relay relay= address-pool=Local2-Pool name=DHCP-2 disabled=no

[admin@DHCP-Server] ip dhcp-server> print
Flags: X – disabled, I – invalid
 #   NAME
 0   DHCP-1
Local1-Pool  3d00:00:00
 1   DHCP-2
Local2-Pool  3d00:00:00
[admin@DHCP-Server] ip dhcp-server>
Next, configure the various networks. See below:
/ip dhcp-server network add address= gateway= dns-server= 
/ip dhcp-server network add address= gateway= dns-server=

[admin@DHCP-Server] ip dhcp-server network> print
[admin@DHCP-Server] ip dhcp-server network>
Finally, we set up a relay agent on the dhcp-relay device. See how it is done below:
/ip dhcp-relay add name=LAN1-relay interface=LAN1 dhcp-server= local-address= disabled=no
/ip dhcp-relay add name=LAN2-relay interface=LAN2 dhcp-server= local-address= disabled=no

[admin@dhcp-relay] ip dhcp-relay> print
Flags: X – disabled, I – invalid
 #   NAME                        INTERFACE      DHCP-SERVER     LOCAL-ADDRESS
 0   LAN1-relay                LAN1
 1   LAN2-relay                LAN2

 [admin@DHCP-Relay] ip dhcp-relay>

Spread the love

Leave a Comment