DHCP Client and Server

Document revision:2.7 (Mon Apr 18 22:24:18 GMT 2005)
Applies to: V2.9

General Information

Summary

The DHCP (Dynamic Host Configuration Protocol) is needed for easy distribution of IP addresses in a network. The MikroTik RouterOS implementation includes both - server and client parts and is compliant with RFC2131.

General usage of DHCP:

IP addresses can be bound to MAC addresses using static lease feature.

DHCP server can be used with MikroTik RouterOS HotSpot feature to authenticate and account DHCP clients. See the HotSpot Manual for more information.

Quick Setup Guide

This example will show you how to setup DHCP-Server and DHCP-Client on MikroTik RouterOS.

Specifications

Packages required: dhcp
License required: Level1
Submenu level: /ip dhcp-client, /ip dhcp-server, /ip dhcp-relay
Standards and Technologies: DHCP

Description

The DHCP protocol gives and allocates IP addresses to IP clients. DHCP is basically insecure and should only be used in trusted networks. DHCP server always listens on UDP 67 port, DHCP client - on UDP 68 port. The initial negotiation involves communication between broadcast addresses (on some phases sender will use source address of 0.0.0.0 and/or destination address of 255.255.255.255). You should be aware of this when building firewall.

Additional Resources

DHCP Client Setup

Submenu level: /ip dhcp-client

Description

The MikroTik RouterOS DHCP client may be enabled on any Ethernet-like interface at a time. The client will accept an address, netmask, default gateway, and two dns server addresses. The received IP address will be added to the interface with the respective netmask. The default gateway will be added to the routing table as a dynamic entry. Should the DHCP client be disabled or not renew an address, the dynamic default route will be removed. If there is already a default route installed prior the DHCP client obtains one, the route obtained by the DHCP client would be shown as invalid.

Property Description

address (IP address/netmask) - IP address and netmask, which is assigned to DHCP Client from the Server

add-default-route (yes | no; default: yes) - whether to add the default route to the gateway specified by the DHCP server

client-id (text) - corresponds to the settings suggested by the network administrator or ISP. Commonly it is set to the client's MAC address, but it may as well be any test string

dhcp-server (IP address) - IP address of the DHCP Server

enabled (yes | no; default: no) - whether the DHCP client is enabled

expires-after (time) - time, which is assigned by the DHCP Server, after which the lease expires

gateway (IP address) - IP address of the gateway which is assigned by DHCP Server

host-name (text) - the host name of the client as sent to a DHCP server

interface (name) - any Ethernet-like interface (this includes wireless and EoIP tunnels) on which the DHCP Client searches the DHCP Server

primary-dns (IP address) - IP address of the primary DNS server, assigned by the DHCP Server

secondary-dns (IP address) - IP address of the secondary DNS server, assigned by DHCP Server

primary-ntp - IP address of the primary NTP server, assigned by the DHCP Server

secondary-ntp - IP address of the secondary NTP server, assigned by the DHCP Server

status (bound | error | rebinding... | renewing... | requesting... | searching... | stopped) - shows the status of DHCP Client

use-peer-dns (yes | no; default: yes) - whether to accept the DNS settings advertized by DHCP server (they will be ovverriden in /ip dns submenu)

use-peer-ntp (yes | no; default: yes) - whether to accept the NTP settings advertized by DHCP server (they will override the settings put in the /system ntp client submenu)

Command Description

release - release current binding and restart DHCP client

renew - renew current leases. If the renew operation was not successful, client tries to reinitialize lease (i.e. it starts lease request procedure (rebind) as if it had not received an IP address yet)

Notes

If host-name property is not specified, client's system identity will be sent in the respective field of DHCP request.

If client-id property is not specified, client's MAC address will be sent in the respective field of DHCP request.

If use-peer-dns property is enabled, the DHCP client will unconditionally rewrite the settings in /ip dns submenu. In case two or more DNS servers were received, first two of them are set as primary and secondary servers respectively. In case one DNS server was received, it is put as primary server, and the secondary server is left intact.

Example

To add a DHCP client on ether1 interface:

/ip dhcp-client add interface=ether1 disabled=no
[admin@MikroTik] ip dhcp-client> print detail
Flags: X - disabled, I - invalid
 0   interface=ether1 add-default-route=no use-peer-dns=no status=bound
     address=192.168.25.100/24 dhcp-server=10.10.10.1 expires-after=2d21:25:12
[admin@MikroTik] ip dhcp-client>
      

DHCP Server Setup

Submenu level: /ip dhcp-server

Description

The router supports an individual server for each Ethernet-like interface. The MikroTik RouterOS DHCP server supports the basic functions of giving each requesting client an IP address/netmask lease, default gateway, domain name, DNS-server(s) and WINS-server(s) (for Windows clients) information (set up in the DHCP networks submenu)

In order DHCP server to work, you must set up also IP pools (do not include the DHCP server's IP address into the pool range) and DHCP networks.

It is also possible to hand out leases for DHCP clients using the RADIUS server, here are listed the parameters for used in RADIUS server.

Access-Request:

Access-Accept:

Property Description

add-arp (yes | no; default: no) - whether to add dynamic ARP entry:
no - either ARP mode should be enabled on that interface or static ARP entries should be administratively defined in /ip arp submenu

address-pool (name | static-only; default: static-only) - IP pool, from which to take IP addresses for clients
static-only - allow only the clients that have a static lease (i.e. no dynamic addresses will be given to clients, only the ones added in lease submenu)

always-broadcast (yes | no; default: no) - always send replies as broadcasts

authoritative (after-10sec-delay | after-2sec-delay | no | yes; default: after-2sec-delay) - whether the DHCP server is the only one DHCP server for the network
after-10sec-delay - to clients request for an address, dhcp server will wait 10 seconds and if there is another request from the client after this period of time, then dhcp server will offer the address to the client or will send DHCPNAK, if the requested address is not available from this server
after-2sec-delay - to clients request for an address, dhcp server will wait 2 seconds and if there is another request from the client after this period of time, then dhcp server will offer the address to the client or will send DHCPNAK, if the requested address is not available from this server
no - dhcp server ignores clients requests for addresses that are not available from this server
yes - to clients request for an address that is not available from this server, dhcp server will send negative acknowledgment (DHCPNAK)

bootp-support (none | static | dynamic; default: static) - support for BOOTP clients
none - do not respond to BOOTP requests
static - offer only static leases to BOOTP clients
dynamic - offer static and dynamic leases for BOOTP clients

delay-threshold (time; default: none) - if secs field in DHCP packet is smaller than delay-threshold, then this packet is ignored
none - there is no threshold (all DHCP packets are processed)

interface (name) - Ethernet-like interface name

lease-time (time; default: 72h) - the time that a client may use an address. The client will try to renew this address after a half of this time and will request a new address after time limit expires

name (name) - reference name

ntp-server (text) - the DHCP client will use these as the default NTP servers. Two comma-separated NTP servers can be specified to be used by DHCP client as primary and secondary NTP servers

relay (IP address; default: 0.0.0.0) - the IP address of the relay this DHCP server should process requests from:
0.0.0.0 - the DHCP server will be used only for direct requests from clients (no DHCP really allowed)
255.255.255.255 - the DHCP server should be used for any incomming request from a DHCP relay except for those, which are processed by another DHCP server that exists in the /ip dhcp-server submenu

src-address (IP address; default: 0.0.0.0) - the address which the DHCP client must send requests to in order to renew an IP address lease. If there is only one static address on the DHCP server interface and the source-address is left as 0.0.0.0, then the static address will be used. If there are multiple addresses on the interface, an address in the same subnet as the range of given addresses should be used

use-radius (yes | no; default: no) - whether to use RADIUS server for dynamic leases

Notes

If using both - Universal Client and DHCP Server on the same interface, client will only receive a DHCP lease in case it is directly reachable by its MAC address through that interface (some wireless bridges may change client's MAC address).

If authoritative property is set to yes, the DHCP server is sending rejects for the leases it cannot bind or renew. It also may (although not always) help to prevent the users of the network to run illicitly their own DHCP servers disturbing the proper way this network should be functioning.

If relay property of a DHCP server is not set to 0.0.0.0 the DHCP server will not respond to the direct requests from clients.

Example

To add a DHCP server to interface ether1, lending IP addresses from dhcp-clients IP pool for 2 hours:

/ip dhcp-server add name=dhcp-office disabled=no address-pool=dhcp-clients \
interface=ether1 lease-time=2h
[admin@MikroTik] ip dhcp-server> print
Flags: X - disabled, I - invalid
 #   NAME             INTERFACE RELAY           ADDRESS-POOL LEASE-TIME ADD-ARP
 0   dhcp-office      ether1                    dhcp-clients 02:00:00
[admin@MikroTik] ip dhcp-server>
      

Store Leases on Disk

Submenu level: /ip dhcp-server config

Description

Leases are always stored on disk on graceful shutdown and reboot. If on every lease change it is stored on disk, a lot of disk writes happen. There are no problems if it happens on a hard drive, but is very bad on Compact Flash (especially, if lease times are very short). To minimize writes on disk, all changes are flushed together every store-leases-disk seconds. If this time will be very short (immediately), then no changes will be lost even in case of hard reboots and power losts. But, on CF there may be too many writes in case of short lease times (as in case of hotspot). If this time will be very long (never), then there will be no writes on disk, but information about active leases may be lost in case of power loss. In these cases dhcp server may give out the same ip address to another client, if first one will not respond to ping requests.

Property Description

store-leases-disk (time-interval | immediately | never; default: 5min) - how frequently lease changes should be stored on disk

DHCP Networks

Submenu level: /ip dhcp-server network

Property Description

address (IP address/netmask) - the network DHCP server(s) will lend addresses from

boot-file-name (text) - Boot file name

dhcp-option (text) - add additional DHCP options from /ip dhcp-server option list. You cannot redefine parameters which are already defined in this submenu:
Subnet-Mask (code 1) - netmask
Router (code 3) - gateway
Domain-Server (code 6) - dns-server
Domain-Name (code 15) - domain
NETBIOS-Name-Server - wins-server

dns-server (text) - the DHCP client will use these as the default DNS servers. Two comma-separated DNS servers can be specified to be used by DHCP client as primary and secondary DNS servers

domain (text) - the DHCP client will use this as the 'DNS domain' setting for the network adapter

gateway (IP address; default: 0.0.0.0) - the default gateway to be used by DHCP clients

netmask (integer: 0..32; default: 0) - the actual network mask to be used by DHCP client
0 - netmask from network address is to be used

next-server (IP address) - IP address of next server to use in bootstrap

wins-server (text) - the Windows DHCP client will use these as the default WINS servers. Two comma-separated WINS servers can be specified to be used by DHCP client as primary and secondary WINS servers

Notes

The address field uses netmask to specify the range of addresses the given entry is valid for. The actual netmask clients will be using is specified in netmask property.

DHCP Server Leases

Submenu level: /ip dhcp-server lease

Description

DHCP server lease submenu is used to monitor and manage server's leases. The issued leases are showed here as dynamic entries. You can also add static leases to issue the definite client (determined by MAC address) the specified IP address.

Generally, the DHCP lease it allocated as follows:

  1. an unused lease is in waiting state
  2. if a client asks for an IP address, the server chooses one
  3. if the client will receive statically assigned address, the lease becomes offered, and then bound with the respective lease time
  4. if the client will receive a dynamic address (taken from an IP address pool), the router sends a ping packet and waits for answer for 0.5 seconds. During this time, the lease is marked testing
  5. in case, the address does not respond, the lease becomes offered, and then bound with the respective lease time
  6. in other case, the lease becomes busy for the lease time (there is a command to retest all busy addresses), and the client's request remains unanswered (the client will try again shortly)

A client may free the leased address. When the dynamic lease is removed, and the allocated address is returned to the address pool. But the static lease becomes busy until the client will reacquire the address.

Note that the IP addresses assigned statically are not probed.

Property Description

active-address (read-only: IP address) - actual IP address for this lease

active-client-id (read-only: text) - actual client-id of the client

active-mac-address (read-only: MAC address) - actual MAC address of the client

active-server (read-only: list) - actual dhcp server, which serves this client

address (IP address) - specify ip address (or ip pool) for static lease
0.0.0.0 - use pool from server

agent-circuit-id (read-only: text) - circuit ID of DHCP relay agent

agent-remote-id (read-only: text) - Remote ID, set by DHCP relay agent

block-access (yes | no; default: no) - block access for this client (drop packets from this client)

client-id (text; default: "") - if specified, must match DHCP 'client identifier' option of the request

expires-after (read-only: time) - time until lease expires

host-name (read-only: text) - shows host name option from last received DHCP request

lease-time (time; default: 0s) - time that the client may use an address
0s - lease will never expire

mac-address (MAC address; default: 00:00:00:00:00:00) - if specified, must match MAC address of the client

radius (read-only: yes | no) - shows, whether this dynamic lease is authenticated by RADIUS or not

rate-limit (read-only: text; default: "") - sets rate limit for active lease. Format is: rx-rate[/tx-rate] [rx-burst-rate[/tx-burst-rate] [rx-burst-threshold[/tx-burst-threshold] [rx-burst-time[/tx-burst-time]]]]. All rates should be numbers with optional 'k' (1,000s) or 'M' (1,000,000s). If tx-rate is not specified, rx-rate is as tx-rate too. Same goes for tx-burst-rate and tx-burst-threshold and tx-burst-time. If both rx-burst-threshold and tx-burst-threshold are not specified (but burst-rate is specified), rx-rate and tx-rate is used as burst thresholds. If both rx-burst-time and tx-burst-time are not specified, 1s is used as default.

rx-rate (integer; default: 0) - maximal receive bitrate to the client (for users it is upload bitrate))
0 - no limitation

server (read-only: name) - server name which serves this client

status (read-only: waiting | testing | authorizing | busy | offered | bound) - lease status:
waiting - not used static lease
testing - testing whether this address is used or not (only for dynamic leases) by pinging it with timeout of 0.5s
authorizing - waiting for response from radius server
busy - this address is assigned statically to a client or already exists in the network, so it can not be leased
offered - server has offered this lease to a client, but did not receive confirmation from the client
bound - server has received client's confirmation that it accepts offered address, it is using it now and will free the address not later, than the lease time will be over

tx-rate (integer; default: 0) - maximal transmit bitrate to the client (for users it is download bitrate))
0 - no limitation

Command Description

check-status - Check status of a given busy dynamic lease, and free it in case of no response

make-static - convert a dynamic lease to static one

Notes

If rate-limit is specified, a simple queue is added with corresponding parameters when lease enters bound state. Arp entry is added right after adding of queue is done (only if add-arp is enabled for dhcp server). To be sure, that client cannot use his ip address without getting dhcp lease and thus avoiding rate-limit, reply-only mode must be used on that ethernet interface.

Even though client address may be changed (with adding a new item) in lease print list, it will not change for the client. It is true for any changes in the DHCP server configuration because of the nature of the DHCP protocol. Client tries to renew assigned IP address only when half a lease time is past (it tries to renew several times). Only when full lease time is past and IP address was not renewed, new lease is asked (rebind operation).

the deault mac-address value will never work! You should specify a correct MAC address there.

Example

To assign 10.5.2.100 static IP address for the existing DHCP client (shown in the lease table as item #0):

[admin@MikroTik] ip dhcp-server lease> print
Flags: X - disabled, H - hotspot, D - dynamic
  #   ADDRESS         MAC-ADDRESS       EXPIRES-AFTER SERVER         STATUS
  0 D 10.5.2.90       00:04:EA:C6:0E:40 1h48m59s      switch         bound
  1 D 10.5.2.91       00:04:EA:99:63:C0 1h42m51s      switch         bound
[admin@MikroTik] ip dhcp-server lease> add copy-from=0 address=10.5.2.100
[admin@MikroTik] ip dhcp-server lease> print
Flags: X - disabled, H - hotspot, D - dynamic
  #   ADDRESS         MAC-ADDRESS       EXPIRES-AFTER SERVER         STATUS
  1 D 10.5.2.91       00:04:EA:99:63:C0 1h42m18s      switch         bound
  2   10.5.2.100      00:04:EA:C6:0E:40 1h48m26s      switch         bound
[admin@MikroTik] ip dhcp-server lease>
       

DHCP Alert

Submenu level: /ip dhcp-server alert

Description

To find any rogue DHCP servers as soon as they appear in your network, DHCP Alert tool can be used. It will monitor ethernet for all DHCP replies and check, whether this reply comes from a valid DHCP server. If reply from unknown DHCP server is detected, alert gets triggered:

[admin@MikroTik] ip dhcp-server alert>/log print
00:34:23 dhcp,critical,error,warning,info,debug dhcp alert on Public:
    discovered unknown dhcp server, mac 00:02:29:60:36:E7, ip 10.5.8.236
[admin@MikroTik] ip dhcp-server alert>

When the system alerts about a rogue DHCP server, it can execute a custom script.

As DHCP replies can be unicast, rogue dhcp detector may not receive any offer to other dhcp clients at all. To deal with this, rogue dhcp server acts as a dhcp client as well - it sends out dhcp discover requests once a minute

Property Description

alert-timeout (none/time; default: none) - time, after which alert will be forgotten. If after that time the same server will be detected, new alert will be generated
none - infinite time

interface (name) - interface, on which to run rogue DHCP server finder

invalid-server (read-only: text) - list of MAC addresses of detected unknown DHCP servers. Server is removed from this list after alert-timeout

on-alert (text) - script to run, when an unknown DHCP server is detected

valid-server (text) - list of MAC addresses of valid DHCP servers

Notes

All alerts on an interface can be cleared at any time using command: /ip dhcp-server alert reset-alert <interface>

Note, that e-mail can be sent, using /system logging action add target=email

DHCP Option

Submenu level: /ip dhcp-server option

Description

With help of DHCP Option, it is possible to define additional custom options for DHCP Server.

Property Description

code (integer: 1..254) - dhcp option code. All codes are available at http://www.iana.org/assignments/bootp-dhcp-parameters

name (name) - descriptive name of the option

value (text) - parameter's value in form of a string. If the string begins with "0x", it is assumed as a hexadecimal value

Notes

The defined options you can use in /ip dhcp-server network submenu

According to the DHCP protocol, a parameter is returned to the DHCP client only if it requests this parameter, specifying the respective code in DHCP request Parameter-List (code 55) attribute. If the code is not included in Parameter-List attribute, DHCP server will not send it to the DHCP client.

Example

This example shows how to set DHCP server to reply on DHCP client's Hostname request (code 12) with value Host-A.

Add an option named Option-Hostname with code 12 (Hostname) and value Host-A:

[admin@MikroTik] ip dhcp-server option> add name=Hostname code=12 \
value="Host-A"
[admin@MikroTik] ip dhcp-server option> print
 # NAME                                CODE VALUE
 0 Option-Hostname                     12   Host-A
[admin@MikroTik] ip dhcp-server option>

Use this option in DHCP server network list:

[admin@MikroTik] ip dhcp-server network> add address=10.1.0.0/24 \
\... gateway=10.1.0.1 dhcp-option=Option-Hostname dns-server=159.148.60.20
[admin@MikroTik] ip dhcp-server network> print detail
 0 address=10.1.0.0/24 gateway=10.1.0.1 dns-server=159.148.60.20
   dhcp-option=Option-Hostname
[admin@MikroTik] ip dhcp-server network>

Now the DHCP server will reply with its Hostname Host-A to DHCP client (if requested)

DHCP Relay

Submenu level: /ip dhcp-relay

Description

DHCP Relay is just a proxy that is able to receive a DHCP request and resend it to the real DHCP server

Property Description

dhcp-server (text) - list of DHCP servers' IP addresses which should the DHCP requests be forwarded to

delay-threshold (time; default: none) - if secs field in DHCP packet is smaller than delay-threshold, then this packet is ignored

interface (name) - interface name the DHCP relay will be working on

local-address (IP address; default: 0.0.0.0) - the unique IP address of this DHCP relay needed for DHCP server to distinguish relays:
0.0.0.0 - the IP address will be chosen automatically

name (name) - descriptive name for relay

Notes

DHCP relay does not choose the particular DHCP server in the dhcp-server list, it just sent to all the listed servers.

Example

To add a DHCP relay named relay on ether1 interface resending all received requests to the 10.0.0.1 DHCP server:

[admin@MikroTik] ip dhcp-relay> add name=relay interface=ether1 \
\... dhcp-server=10.0.0.1 disabled=no
[admin@MikroTik] ip dhcp-relay> print
Flags: X - disabled, I - invalid
  #   NAME                            INTERFACE DHCP-SERVER     LOCAL-ADDRESS
  0   relay                           ether1    10.0.0.1        0.0.0.0

[admin@MikroTik] ip dhcp-relay>
      

Question&Answer-Based Setup

Command name: /ip dhcp-server setup

Questions

addresses to give out (text) - the pool of IP addresses DHCP server should lease to the clients

dhcp address space (IP address/netmask; default: 192.168.0.0/24) - network the DHCP server will lease to the clients

dhcp relay (IP address; default: 0.0.0.0) - the IP address of the DHCP relay between the DHCP server and the DHCP clients

dhcp server interface (name) - interface to run DHCP server on

dns servers (IP address) - IP address of the appropriate DNS server to be propagated to the DHCP clients

gateway (IP address; default: 0.0.0.0) - the default gateway of the leased network

lease time (time; default: 3d) - the time the lease will be valid

Notes

Depending on current settings and answers to the previous questions, default values of following questions may be different. Some questions may disappear if they become redundant (for example, there is no use of asking for 'relay' when the server will lend the directly connected network)

Example

To configure DHCP server on ether1 interface to lend addresses from 10.0.0.2 to 10.0.0.254 which belong to the 10.0.0.0/24 network with 10.0.0.1 gateway and 159.148.60.2 DNS server for the time of 3 days:

[admin@MikroTik] ip dhcp-server> setup
Select interface to run DHCP server on

dhcp server interface: ether1
Select network for DHCP addresses

dhcp address space: 10.0.0.0/24
Select gateway for given network

gateway for dhcp network: 10.0.0.1
Select pool of ip addresses given out by DHCP server

addresses to give out: 10.0.0.2-10.0.0.254
Select DNS servers

dns servers: 159.148.60.20
Select lease time

lease time: 3d
[admin@MikroTik] ip dhcp-server>
      

The wizard has made the following configuration based on the answers above:

[admin@MikroTik] ip dhcp-server> print
Flags: X - disabled, I - invalid
  #   NAME            INTERFACE RELAY           ADDRESS-POOL LEASE-TIME ADD-ARP
  0   dhcp1           ether1    0.0.0.0         dhcp_pool1   3d         no

[admin@MikroTik] ip dhcp-server> network print
  # ADDRESS            GATEWAY         DNS-SERVER      WINS-SERVER     DOMAIN
  0 10.0.0.0/24        10.0.0.1        159.148.60.20

[admin@MikroTik] ip dhcp-server> /ip pool print
  # NAME                                        RANGES
  0 dhcp_pool1                                  10.0.0.2-10.0.0.254

[admin@MikroTik] ip dhcp-server>
      

Application Examples

Dynamic Addressing, using DHCP-Relay

Let us consider that you have several IP networks 'behind' other routers, but you want to keep all DHCP servers on a single router. To do this, you need a DHCP relay on your network which relies DHCP requests from clients to DHCP server.

This example will show you how to configure a DHCP server and a DHCP relay which serve 2 IP networks - 192.168.1.0/24 and 192.168.2.0/24 that are behind a router DHCP-Relay.

IP addresses of DHCP-Server:

[admin@DHCP-Server] ip address> print
Flags: X - disabled, I - invalid, D - dynamic
 #   ADDRESS            NETWORK         BROADCAST       INTERFACE
 0   192.168.0.1/24     192.168.0.0     192.168.0.255   To-DHCP-Relay
 1   10.1.0.2/24	10.1.0.0	10.1.0.255	Public
[admin@DHCP-Server] ip address>

IP addresses of DHCP-Relay:

[admin@DHCP-Relay] ip address> print
Flags: X - disabled, I - invalid, D - dynamic
 #   ADDRESS            NETWORK         BROADCAST       INTERFACE
 0   192.168.0.1/24     192.168.0.0     192.168.0.255   To-DHCP-Server
 1   192.168.1.1/24     192.168.1.0     192.168.1.255   Local1
 2   192.168.2.1/24     192.168.2.0     192.168.2.255   Local2
[admin@DHCP-Relay] ip address>

To setup 2 DHCP Servers on DHCP-Server router add 2 pools. For networks 192.168.1.0/24 and 192.168.2.0:

/ip pool add name=Local1-Pool ranges=192.168.1.11-192.168.1.100
/ip pool add name=Local1-Pool ranges=192.168.2.11-192.168.2.100
[admin@DHCP-Server] ip pool> print
 # NAME                                         RANGES
 0 Local1-Pool                                  192.168.1.11-192.168.1.100
 1 Local2-Pool                                  192.168.2.11-192.168.2.100
[admin@DHCP-Server] ip pool>

Create DHCP Servers:

/ip dhcp-server add interface=To-DHCP-Relay relay=192.168.1.1 \
   address-pool=Local1-Pool name=DHCP-1 disabled=no
/ip dhcp-server add interface=To-DHCP-Relay relay=192.168.2.1 \
   address-pool=Local2-Pool name=DHCP-2 disabled=no
[admin@DHCP-Server] ip dhcp-server> print
Flags: X - disabled, I - invalid
 #   NAME         INTERFACE     RELAY           ADDRESS-POOL LEASE-TIME ADD-ARP
 0   DHCP-1       To-DHCP-Relay 192.168.1.1     Local1-Pool  3d00:00:00
 1   DHCP-2       To-DHCP-Relay 192.168.2.1     Local2-Pool  3d00:00:00
[admin@DHCP-Server] ip dhcp-server>

Configure respective networks:

/ip dhcp-server network add address=192.168.1.0/24 gateway=192.168.1.1 \
   dns-server=159.148.60.20
/ip dhcp-server network add address=192.168.2.0/24 gateway=192.168.2.1 \
   dns-server 159.148.60.20
[admin@DHCP-Server] ip dhcp-server network> print
 # ADDRESS            GATEWAY         DNS-SERVER      WINS-SERVER     DOMAIN
 0 192.168.1.0/24     192.168.1.1     159.148.60.20
 1 192.168.2.0/24     192.168.2.1     159.148.60.20
[admin@DHCP-Server] ip dhcp-server network>

Configuration of DHCP-Server is done. Now let's configure DHCP-Relay:

/ip dhcp-relay add name=Local1-Relay interface=Local1 \
   dhcp-server=192.168.0.1 local-address=192.168.1.1 disabled=no
/ip dhcp-relay add name=Local2-Relay interface=Local2 \
   dhcp-server=192.168.0.1 local-address=192.168.2.1 disabled=no
[admin@DHCP-Relay] ip dhcp-relay> print
Flags: X - disabled, I - invalid
 #   NAME                        INTERFACE      DHCP-SERVER     LOCAL-ADDRESS
 0   Local1-Relay                Local1         192.168.0.1     192.168.1.1
 1   Local2-Relay                Local2         192.168.0.1     192.168.2.1
[admin@DHCP-Relay] ip dhcp-relay>

IP Address assignment, using FreeRADIUS Server

Let us consider that we want to assign IP addresses for clients, using the RADIUS server.

We assume that you already have installed FreeRADIUS. Just add these lines to specified files:

users file:

00:0B:6B:31:02:4B       Auth-Type := Local, Password == ""
        Framed-IP-Address = 192.168.0.55

clients.conf file

client 172.16.0.1 {
    secret = MySecret
    shortname = Server
}

Configure Radius Client on RouterOS:

/radius add service=dhcp address=172.16.0.2 secret=MySecret
[admin@DHCP-Server] radius> print detail
Flags: X - disabled
 0   service=dhcp called-id="" domain="" address=172.16.0.2 secret="MySecret"
     authentication-port=1812 accounting-port=1813 timeout=00:00:00.300
     accounting-backup=no realm=""
[admin@DHCP-Server] radius>

Setup DHCP Server:

  1. Create an address pool:

    /ip pool add name=Radius-Clients ranges=192.168.0.11-192.168.0.100
  2. Add a DHCP server:

    /ip dhcp-server add address-pool=Radius-Clients use-radius=yes interface=Local \
       disabled=no
  3. Configure DHCP networks:

    /ip dhcp-server network add address=192.168.0.0/24 gateway=192.168.0.1 \
    dns-server=159.148.147.194,159.148.60.20

Now the client with MAC address 00:0B:6B:31:02:4B will always receive IP address 192.168.0.55.