Manual:IP/DHCP Server: Difference between revisions

From MikroTik Wiki
Jump to navigation Jump to search
(76 intermediate revisions by 7 users not shown)
Line 9: Line 9:




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 RFC 2131.
The DHCP (Dynamic Host Configuration Protocol) is used for the easy distribution of IP addresses in a network. The MikroTik RouterOS implementation includes both server and client parts and is compliant with RFC 2131.


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)
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 own IP address into the pool range) and DHCP networks.
In order for the DHCP server to work, IP pools must also be configured (do not include the DHCP server's own IP address into the pool range) and the 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.
It is also possible to hand out leases for DHCP clients using the RADIUS server; the supported parameters for a RADIUS server is as follows:




Line 40: Line 40:
<li>Session-Timeout - max lease time (lease-time)
<li>Session-Timeout - max lease time (lease-time)
</ul>
</ul>
{{ Note | DHCP server requires a real interface to receive raw ethernet packets. If the interface is a Bridge interface, then the Bridge must have a real interface attached as a port to that bridge which will receive the raw ethernet packets. It cannot function correctly on a dummy (empty bridge) interface. }}


==Quick Setup Guide==
==Quick Setup Guide==


RouterOS has built in command that lets you easily set up DHCP server. Lets say we want to configure DHCP server on ether1 interface to lend addresses from 192.168.0.2 to 192.168.0.254 which belong to the 192.168.0.0/24 network. The gateway and DNS server is 192.168.0.1.
RouterOS has a built in command that lets you easily set up a DHCP server. Let's say we want to configure DHCP server on ether1 interface to lease addresses from 192.168.0.2 to 192.168.0.254 which belong to the 192.168.0.0/24 network. The gateway and DNS server is 192.168.0.1.


From <code>/ip dhcp-server</code> menu run '''setup''' command and follow instructions:
From <code>/ip dhcp-server</code> menu run '''setup''' command and follow instructions:
Line 59: Line 62:
Select pool of ip addresses given out by DHCP server
Select pool of ip addresses given out by DHCP server


addresses to give out: 192.168.0.2-192.168.0254
addresses to give out: 192.168.0.2-192.168.0.254
Select DNS servers
Select DNS servers


Line 88: Line 91:
[admin@MikroTik] ip dhcp-server>
[admin@MikroTik] ip dhcp-server>
</pre>
</pre>


==IPv6==
==IPv6==


Starting from v5.8 RouterOS supports IPv6 prefix delegation according to RFC 3633.
Starting from v5.8 RouterOS supports IPv6 prefix delegation according to RFC 3315 and RFC 3633.


DHCPv6 server works in parallel with regular DHCP server when <code>address-pool6</code> option is set.
Starting from v5.9, DHCPv6 server configuration was moved to /ipv6 sub-menu. [[M:IPv6/DHCP_Server | <code>Read-more >></code>]]
DHCPv6 uses following options:
* authoritative
* lease-time
* address-pool6
* interface
* name


==General==
==General==
Line 125: Line 121:
|desc=[[M:IP/Pools | IP pool]], from which to take IP addresses for the clients. If set to <b>static-only</b>, then only the clients that have a static lease (added in [[#Leases | lease]] submenu) will be allowed.
|desc=[[M:IP/Pools | IP pool]], from which to take IP addresses for the clients. If set to <b>static-only</b>, then only the clients that have a static lease (added in [[#Leases | lease]] submenu) will be allowed.
}}
}}


{{Mr-arg-table
{{Mr-arg-table
|arg=address-pool6
|arg=allow-dual-stack-queue
|type=string {{!}} static-only
|type=yes {{!}} no
|default=static-only
|default=yes
|desc=[[M:IPv6/Pool | IPv6 pool]], from which to take IPv6 prefix for the clients. If set to <b>static-only</b>, then only the clients that have a static binding (added in [[#Bindings | bindings]] submenu) will be allowed.
|desc=Creates a single simple queue entry for both IPv4 and IPv6 addresses, uses the MAC address and DUID for identification. Requires [[ Manual:IPv6/DHCP_Server | IPv6 DHCP Server]] to have this option enabled as well to work properly.
}}
}}


{{Mr-arg-table
{{Mr-arg-table
Line 138: Line 134:
|type=yes {{!}} no
|type=yes {{!}} no
|default=no
|default=no
|desc=Always send replies as broadcasts.
|desc=Always send replies as broadcasts even if destination IP is known. Will add additional load on L2 network.
}}
}}


Line 144: Line 140:
|arg=authoritative
|arg=authoritative
|type=after-10sec-delay {{!}} after-2sec-delay {{!}} yes {{!}} no
|type=after-10sec-delay {{!}} after-2sec-delay {{!}} yes {{!}} no
|default=after-2sec-delay
|default=yes
|desc=Whether the DHCP server is the only one DHCP server for the network:
|desc=Option changes the way how server responds to DHCP requests:
* <var>after-10sec-delay</var> - 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
 
* <var>after-2sec-delay</var> - 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
* <var>yes</var> - replies to clients request for an address that is not available from this server, dhcp server will send negative acknowledgment (DHCPNAK)  
* <var>yes</var> - to clients request for an address that is not available from this server, dhcp server will send negative acknowledgment (DHCPNAK)  
* <var>no</var> - dhcp server ignores clients requests for addresses that are not available from this server  
* <var>no</var> - dhcp server ignores clients requests for addresses that are not available from this server  
* <var>after-10sec-delay</var> - requests with "secs < 10" will be processed as in "no" setting case and requests with "secs >= 10" will be processed as in "yes" case.
* <var>after-2sec-delay</var> - requests with "secs < 2" will be processed as in "no" setting case and requests with "secs >= 2" will be processed as in "yes" case.
If all requests with "secs < x" should be ignored, then '''delay-threshold=x''' setting should be used.
}}
}}


{{Mr-arg-table
{{Mr-arg-table
|arg=boot-support
|arg=bootp-lease-time
|type=forever {{!}} lease-time {{!}} time
|default=
|desc=Accepts two predefined options or time value:
* <var>forever</var> - lease never expires
* <var>lease-time</var> - use time from lease-time parameter
}}
 
{{Mr-arg-table
|arg=bootp-support
|type=none {{!}} static {{!}} dynamic
|type=none {{!}} static {{!}} dynamic
|default=static
|default=static
Line 160: Line 172:
* <var>static</var> - offer only static leases to BOOTP clients  
* <var>static</var> - offer only static leases to BOOTP clients  
* <var>dynamic</var> - offer static and dynamic leases for BOOTP clients  
* <var>dynamic</var> - offer static and dynamic leases for BOOTP clients  
}}
{{Mr-arg-table
|arg=client-mac-limit
|type=integer {{!}} unlimited
|default=unlimited
|desc=Specifies whether to limit specific number of clients per single MAC address or leave <var>unlimited</var>.
Note that this setting should not be used in relay setups.
}}
{{Mr-arg-table
|arg=conflict-detection
|type=yes {{!}} no
|default=
|desc=Allows to disable/enable conflict detection. If option is enabled, then whenever server tries to assign a lease it will send ICMP and ARP messages to detect whether such address in the network already exist. If any of above get reply address is considered already used. Conflict detection must be disabled when any kind of DHCP client limitation per port or per mac is used.
}}
}}


Line 167: Line 194:
|default=none
|default=none
|desc=If secs field in DHCP packet is smaller than delay-threshold, then this packet is ignored. If set to <b>none</b> - there is no threshold (all DHCP packets are processed)  
|desc=If secs field in DHCP packet is smaller than delay-threshold, then this packet is ignored. If set to <b>none</b> - there is no threshold (all DHCP packets are processed)  
}}
{{Mr-arg-table
|arg=dhcp-option-set
|type=name {{!}} none
|default=
|desc=Use custom set of DHCP options defined in option sets menu.
}}
{{Mr-arg-table
|arg=insert-queue-before
|type=bottom {{!}} first {{!}} name
|default=
|desc=Specify where to place dynamic simple queue entries for static DCHP leases with <var>rate-limit</var> parameter set.
}}
}}


Line 175: Line 216:
|desc=Interface on which server will be running.  
|desc=Interface on which server will be running.  
}}
}}
{{Mr-arg-table
|arg=lease-script
|type=string
|default=""
|desc=Script that will be executed after lease is assigned or de-assigned. Internal "global" variables that can be used in the script:
* <var>leaseBound</var> - set to "1" if bound, otherwise set to "0"
* <var>leaseServerName</var> -  dhcp server name
* <var>leaseActMAC</var> -  active mac address
* <var>leaseActIP</var> -  active IP address
* <var>lease-hostname</var> - client hostname
}}


{{Mr-arg-table
{{Mr-arg-table
|arg=lease-time
|arg=lease-time
|type=time
|type=time
|default=72h
|default=10m
|desc=The time that a client may use the assigned 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.
|desc=The time that a client may use the assigned 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.
}}
}}
Line 188: Line 242:
|default=
|default=
|desc=Reference name
|desc=Reference name
}}
{{Mr-arg-table
|arg=parent-queue
|type=string {{!}} none
|default=none
|desc=
}}
}}


Line 195: Line 256:
|default=0.0.0.0
|default=0.0.0.0
|desc=The IP address of the relay this DHCP server should process requests from:
|desc=The IP address of the relay this DHCP server should process requests from:
* <var>0.0.0.0</var> - the DHCP server will be used only for direct requests from clients (no DHCP really allowed)  
* <var>0.0.0.0</var> - the DHCP server will be used only for direct requests from clients (no DHCP relay allowed)  
* <var>255.255.255.255</var> - 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 <code>/ip dhcp-server</code> submenu.
* <var>255.255.255.255</var> - the DHCP server should be used for any incoming request from a DHCP relay except for those, which are processed by another DHCP server that exists in the <code>/ip dhcp-server</code> submenu.
}}
}}


Line 204: Line 265:
|default=0.0.0.0
|default=0.0.0.0
|desc=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.
|desc=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.
}}
{{Mr-arg-table
|arg=use-framed-as-classless
|type=yes {{!}} no
|default=yes
|desc=Forward RADIUS Framed-Route as a DHCP Classless-Static-Route to DHCP-client.  Whenever both Framed-Route and Classless-Static-Route is received Classless-Static-Route is preferred.
}}
}}


{{Mr-arg-table-end
{{Mr-arg-table-end
|arg=use-radius
|arg=use-radius
|type=yes {{!}} no
|type=yes {{!}} no {{!}} accounting
|default=no
|default=no
|desc=Whether to use RADIUS server for dynamic leases
|desc=Whether to use RADIUS server:
* <var>no</var> - do not use RADIUS;
* <var>yes</var> - use RADIUS for accounting and lease;
* <var>accounting</var> - use RADIUS for accounting only.
}}
}}


Line 225: Line 296:
|type=
|type=
|desc=Start DHCP server setup wizard, which guides you through the steps to easily create all necessary configuration. <code> [[#Quick Setup Guide | Read more>>]]</code>
|desc=Start DHCP server setup wizard, which guides you through the steps to easily create all necessary configuration. <code> [[#Quick Setup Guide | Read more>>]]</code>
}}
==Bindings==
<p id="shbox"><b>Sub-menu:</b> <code>/ip dhcp-server bindings6</code></p>
This menu shows IPv6 prefixes assigned to the clients. Static bindings are matched against MAC address not by full DUID.
DUID is used only for dynamic bindings, so if it changes then client will receive different prefix than previously.
{{Mr-arg-table-h
|prop=Property
|desc=Description
}}
{{Mr-arg-table
|arg=address
|type=IPv6 prefix
|default=
|desc=IPv6 prefix that will be assigned to the client
}}
{{Mr-arg-table
|arg=comment
|type=string
|default=
|desc=Short description of an item.
}}
{{Mr-arg-table
|arg=disabled
|type=yes {{!}} no
|default=no
|desc=Whether item is disabled
}}
{{Mr-arg-table
|arg=life-time
|type=time
|default=3d
|desc=Time period after which binding expires/
}}
{{Mr-arg-table
|arg=mac-address
|type=MAC
|default=
|desc=
}}
{{Mr-arg-table-end
|arg=server
|type=string {{!}} all
|default=all
|desc=Name of the server
}}
'''Read-only properties'''
{{Mr-arg-table-h
|prop=Property
|desc=Description
}}
{{Mr-arg-ro-table
|arg=dynamic
|type=yes {{!}} no
|desc=Whether item is dynamically created.
}}
{{Mr-arg-ro-table
|arg=expire-time
|type=time
|desc=Time period after which binding expires.
}}
{{Mr-arg-ro-table
|arg=last-seen
|type=time
|desc=Time period since client was last seen.
}}
{{Mr-arg-ro-table-end
|arg=status
|type=waiting {{!}} offered {{!}} bound
|desc=Three status vales are possible:
* '''waiting''' - Shown for static bindings if it is not used. For dynamic bindings this status is shown if it was used previously, server will wait 10 minutes to allow old client to get this binding, otherwise binding will be cleared and prefix willbe offered to other clients.
* '''offered''' - if '''solicit''' message was received, and server responded with '''advertise''' message, but '''request''' was not received. During this state client have 2 minutes to get this binding, otherwise it is freed or changed status to '''waiting''' for static bindings.
* '''bound''' - currently bound.
}}
For example, dynamically assigned /62 prefix
<pre>
[admin@RB493G] /ip dhcp-server binding> print detail
Flags: X - disabled, D - dynamic
0 D address=2a02:610::/62 mac-address=00:24:1D:17:81:F7 server=local-dhcp
    life-time=3d status=bound expire-time=2d22h46m21s last-seen=1h13m39s
</pre>
===Menu specific commands===
{{Mr-arg-table-h
|prop=Property
|desc=Description
}}
{{Mr-arg-ro-table-end
|arg=make-static
|type=
|desc=Set dynamic binding as static.
}}
}}


Line 346: Line 301:
<p id="shbox"><b>Sub-menu:</b> <code>/ip dhcp-server config</code></p>
<p id="shbox"><b>Sub-menu:</b> <code>/ip dhcp-server config</code></p>


This sub-menu allows to configure how often DHCP leases will be stored on disk. If they would be saved on disk on every lease change, a lot of disk writes would happen which is very bad for Compact Flash (especially, if lease times are very short). To minimize writes on disk, all changes are saved on disk every <code>store-leases-disk</code> seconds.
This sub-menu allows the configuration of how often the DHCP leases will be stored on disk. If they would be saved on disk on every lease change, a lot of disk writes would happen which is very bad for Compact Flash (especially, if lease times are very short). To minimize writes on disk, all changes are saved on disk every <code>store-leases-disk</code> seconds.
Additionally leases are always stored on disk on graceful shutdown and reboot.
Additionally leases are always stored on disk on graceful shutdown and reboot.


{{Note| Manual changes to leases - addition/removal of static lease, removal of dynamic lease will cause changes to be pushed for this lease to storage.}}


This sub-menu has only one configurable property:
This sub-menu has only one configurable property:
Line 374: Line 330:
<tr>
<tr>
     <td><var><b>address</b></var> (<em>IP/netmask</em>; Default: <b></b>)</td>
     <td><var><b>address</b></var> (<em>IP/netmask</em>; Default: <b></b>)</td>
     <td>the network DHCP server(s) will lend addresses from</td>
     <td>the network DHCP server(s) will lease addresses from</td>
</tr>
</tr>
<tr>
<tr>
     <td><var><b>boot-file-name</b></var> (<em>string</em>; Default: <b></b>)</td>
     <td><var><b>boot-file-name</b></var> (<em>string</em>; Default: <b></b>)</td>
     <td>Boot file name</td>
     <td>Boot file name</td>
</tr>
<tr>
    <td><var><b>caps-manager</b></var> (<em>string</em>; Default: <b></b>)</td>
    <td>Comma-separated list of IP addresses for one or more CAPsMAN system managers. DHCP Option 138 (capwap) will be used.</td>
</tr>
</tr>
<tr>
<tr>
     <td><var><b>dhcp-option</b></var> (<em>string</em>; Default: <b></b>)</td>
     <td><var><b>dhcp-option</b></var> (<em>string</em>; Default: <b></b>)</td>
     <td>Add additional DHCP options from [[#Options | option list]].</td>
     <td>Add additional DHCP options from [[#Options | option list]].</td>
</tr>
<tr>
    <td><var><b>dhcp-option-set</b></var> (<em>string</em>; Default: <b></b>)</td>
    <td>Add additional set of DHCP options.</td>
</tr>
<tr>
    <td><var><b>dns-none</b></var> (<em>yes | no</em>; Default: <b>no</b>)</td>
    <td>If set, then DHCP Server will not pass dynamic DNS servers configured on the router to the DHCP clients if no DNS Server in <var>dns-server</var> is set. By default if there are no DNS Servers configured, then the dynamic DNS Servers will be passed to DHCP clients.</td>
</tr>
</tr>
<tr>
<tr>
     <td><var><b>dns-server</b></var> (<em>string</em>; Default: <b></b>)</td>
     <td><var><b>dns-server</b></var> (<em>string</em>; Default: <b></b>)</td>
     <td>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</td>
     <td>the DHCP client will use these as the default DNS servers. Two comma-separated DNS servers can be specified to be used by the DHCP client as primary and secondary DNS servers</td>
</tr>
</tr>
<tr>
<tr>
Line 406: Line 374:
<tr>
<tr>
     <td><var><b>ntp-server</b></var> (<em>IP</em>; Default: <b></b>)</td>
     <td><var><b>ntp-server</b></var> (<em>IP</em>; Default: <b></b>)</td>
     <td>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</td>
     <td>the DHCP client will use these as the default NTP servers. Two comma-separated NTP servers can be specified to be used by the DHCP client as primary and secondary NTP servers</td>
</tr>
</tr>
<tr>
<tr>
     <td><var><b>wins-server</b></var> (<em>IP</em>; Default: <b></b>)</td>
     <td><var><b>wins-server</b></var> (<em>IP</em>; Default: <b></b>)</td>
     <td>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</td>
     <td>The Windows DHCP client will use these as the default WINS servers. Two comma-separated WINS servers can be specified to be used by the DHCP client as primary and secondary WINS servers</td>
</tr>
</tr>
</table>
</table>
Line 419: Line 387:


<p>
<p>
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 a particular client (identified by MAC address) the desired IP address.
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 a specific IP address to a particular client (identified by MAC address) .
</p>
</p>
<p>
<p>
Line 426: Line 394:
<li>an unused lease is in waiting state
<li>an unused lease is in waiting state
<li>if a client asks for an IP address, the server chooses one
<li>if a client asks for an IP address, the server chooses one
<li>if the client will receive statically assigned address, the lease becomes offered, and then bound with the respective lease time
<li>if the client receives a statically assigned address, the lease becomes offered, and then bound with the respective lease time
<li>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
<li>if the client receives 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
<li>in case, the address does not respond, the lease becomes offered, and then bound with the respective lease time
<li>in the case where the address does not respond, the lease becomes offered and then bound with the respective lease time
<li>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)
<li>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)
</ul>
</ul>
A client may free the leased address. 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.
A client may free the leased address. The dynamic lease is removed, and the allocated address is returned to the address pool. But the static lease becomes busy until the client reacquires the address.
</p>
</p>


{{Note | that the IP addresses assigned statically are not probed. }}
{{Note | IP addresses assigned statically are not probed! }}




Line 445: Line 413:
<tr>
<tr>
     <td><var><b>address</b></var> (<em>IP</em>; Default: <b></b>)</td>
     <td><var><b>address</b></var> (<em>IP</em>; Default: <b></b>)</td>
     <td>Specify ip address (or ip pool) for static lease. If set to <b>0.0.0.0</b> - pool from server will be used</td>
     <td>Specify IP address (or ip pool) for static lease. If set to <b>0.0.0.0</b> - pool from server will be used</td>
</tr>
<tr>
    <td><var><b>address-list</b></var> (<em>string</em>; Default: <b></b>)</td>
    <td>Address list to which address will be added if lease is bound.</td>
</tr>
<tr>
    <td><var><b>allow-dual-stack-queue</b></var> (<em>yes | no</em>; Default: <b>yes</b>)</td>
    <td>Creates a single simple queue entry for both IPv4 and IPv6 addresses, uses the MAC address and DUID for identification. Requires [[ Manual:IPv6/DHCP_Server | IPv6 DHCP Server]] to have this option enabled as well to work properly.</td>
</tr>
</tr>
<tr>
<tr>
     <td><var><b>always-broadcast</b></var> (<em>yes | no</em>; Default: <b></b>)</td>
     <td><var><b>always-broadcast</b></var> (<em>yes | no</em>; Default: <b></b>)</td>
     <td>Send all repies as broadcasts</td>
     <td>Send all replies as broadcasts</td>
</tr>
</tr>
<tr>
<tr>
Line 459: Line 435:
     <td>If specified, must match DHCP 'client identifier' option of the request</td>
     <td>If specified, must match DHCP 'client identifier' option of the request</td>
</tr>
</tr>
<tr>
    <td><var><b>dhcp-option</b></var> (<em>string</em>; Default: <b></b>)</td>
    <td>Add additional DHCP options from [[#Options | option list]].</td>
</tr>
<tr>
    <td><var><b>dhcp-option-set</b></var> (<em>string</em>; Default: <b></b>)</td>
    <td>Add additional set of DHCP options.</td>
</tr>
<tr>
    <td><var><b>insert-queue-before</b></var> (<em>bottom | first | name</em>;; Default: <b></b>)</td>
    <td>Specify where to place dynamic simple queue entries for static DCHP leases with <var>rate-limit</var> parameter set.</td>
</tr>
<tr>
<tr>
     <td><var><b>lease-time</b></var> (<em>time</em>; Default: <b>0s</b>)</td>
     <td><var><b>lease-time</b></var> (<em>time</em>; Default: <b>0s</b>)</td>
Line 468: Line 457:
</tr>
</tr>
<tr>
<tr>
     <td><var><b>src-mac-address</b></var> (<em>MAC</em>; Default: <b></b>)</td>
     <td><var><b>rate-limit</b></var> (<em>integer[/integer] [integer[/integer] [integer[/integer] [integer[/integer]]]];</em>; Default: <b></b>)</td>
     <td>Source MAC address</td>
     <td>Adds a dynamic simple queue to limit IP's bandwidth to a specified rate. Requires the lease to be static. 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.</td>
</tr>
<tr>
    <td><var><b>server</b></var> (<em>string</em>)</td>
    <td>Server name which serves this client</td>
</tr>
</tr>
<tr>
<tr>
     <td><var><b>use-src-mac</b></var> (<em>MAC</em>; Default: <b></b>)</td>
     <td><var><b>use-src-mac</b></var> (<em>yes {{!}} no</em>; Default: <b>no</b>)</td>
     <td>Use this source MAC address instead</td>
     <td>When this option is set server uses source MAC address instead of received CHADDR to assign address.</td>
</tr>
</tr>
</table>
</table>
<br />
<br />
{{ Warning | The <code>always-broadcast</code> parameter will dynamically change. For the initial DHCP discover/offer/request/ack cycle a broadcast MAC address is going to be used, for lease renewal (request and ack) an unicast MAC address will be used. In case the DHCP Server keeps receiving DHCP requests while DHCP offer has been sent, then the <code>always-broadcast</code> parameter will be turned on dynamically until the DHCP lease has been renewed successfully. }}


===Read only properties===
===Read only properties===
Line 502: Line 497:
<tr>
<tr>
     <td><var><b>agent-circuit-id</b></var> (<em>string</em>)</td>
     <td><var><b>agent-circuit-id</b></var> (<em>string</em>)</td>
     <td>Circuit ID of DHCP relay agent</td>
     <td>Circuit ID of DHCP relay agent. If each character should be valid ASCII text symbol or else this value is displayed as hex dump.</td>
</tr>
</tr>
<tr>
<tr>
Line 522: Line 517:
<tr>
<tr>
     <td><var><b>radius</b></var> (<em>yes | no</em>)</td>
     <td><var><b>radius</b></var> (<em>yes | no</em>)</td>
     <td>Shows, whether this dynamic lease is authenticated by RADIUS or not</td>
     <td>Shows if this dynamic lease is authenticated by RADIUS or not</td>
</tr>
<tr>
    <td><var><b>rate-limit</b></var> (<em>string</em>)</td>
    <td>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</td>
</tr>
<tr>
    <td><var><b>server</b></var> (<em>string</em>)</td>
    <td>Server name which serves this client</td>
</tr>
</tr>
<tr>
<tr>
Line 536: Line 523:
     <td>Lease status:
     <td>Lease status:
       <ul class="bullets">
       <ul class="bullets">
             <li> <b>waiting</b> - not used static lease
             <li> <b>waiting</b> - un-used static lease
             <li> <b>testing</b> - testing whether this address is used or not (only for dynamic leases) by pinging it with timeout of 0.5s  
             <li> <b>testing</b> - testing whether this address is used or not (only for dynamic leases) by pinging it with timeout of 0.5s  
             <li> <b>authorizing</b> - waiting for response from radius server  
             <li> <b>authorizing</b> - waiting for response from radius server  
             <li> <b>busy</b> - this address is assigned statically to a client or already exists in the network, so it can not be leased  
             <li> <b>busy</b> - this address is assigned statically to a client or already exists in the network, so it can not be leased  
             <li> <b>offered</b> - server has offered this lease to a client, but did not receive confirmation from the client  
             <li> <b>offered</b> - server has offered this lease to a client, but did not receive confirmation from the client  
             <li> <b>bound</b> - 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
             <li> <b>bound</b> - server has received client's confirmation that it accepts offered address, it is using it now and will free the address no later than the lease time  
       </ul>
       </ul>
     </td>
     </td>
</tr>
<tr>
    <td><var><b>src-mac-address</b></var> (<em>MAC</em>; Default: <b></b>)</td>
    <td>Source MAC address</td>
</tr>
</tr>
</table>
</table>
Line 563: Line 554:
</tr>
</tr>
</table>
</table>
<br />
 
===Rate limiting===
 
It is possible to set a bandwidth to a specific IPv4 address by using DHCPv4 leases. This can be done by setting a rate limit on the DHCPv4 lease itself, by doing this a dynamic simple queue rule will be added for the IPv4 address that corresponds to the DHCPv4 lease. By using the <code>rate-limit</code> parameter you can conveniently limit a user's bandwidth.
 
{{ Note | For any queues to work properly, the traffic must not be [[ Manual:IP/Fasttrack | FastTracked]], make sure your Firewall does not FastTrack traffic that you want to limit. }}
 
First, make the DHCPv4 lease static, otherwise it will not be possible to set a rate limit to a DHCPv4 lease:
<pre>
[admin@MikroTik] > /ip dhcp-server lease print
Flags: X - disabled, R - radius, D - dynamic, B - blocked
#  ADDRESS              MAC-ADDRESS      HOST-NAME              SERVER              RATE-LIMIT              STATUS
0 D 192.168.88.254        6C:3B:6B:7C:41:3E MikroTik                DHCPv4_Server                                bound
 
[admin@MikroTik] > /ip dhcp-server lease make-static 0
 
[admin@MikroTik] > /ip dhcp-server lease print
Flags: X - disabled, R - radius, D - dynamic, B - blocked
#  ADDRESS              MAC-ADDRESS      HOST-NAME              SERVER              RATE-LIMIT              STATUS
0  192.168.88.254        6C:3B:6B:7C:41:3E MikroTik                DHCPv4_Server                                bound
</pre>
 
Then you can set a rate to a DHCPv4 lease that will create a new dynamic simple queue entry:
<pre>
[admin@MikroTik] > /ip dhcp-server lease set 0 rate-limit=10M/10M
 
[admin@MikroTik] > /queue simple print
Flags: X - disabled, I - invalid, D - dynamic
0  D name="dhcp-ds<6C:3B:6B:7C:41:3E>" target=192.168.88.254/32 parent=none packet-marks="" priority=8/8 queue=default-small/default-small limit-at=10M/10M max-limit=10M/10M burst-limit=0/0 burst-threshold=0/0 burst-time=0s/0s
      bucket-size=0.1/0.1
</pre>
 
{{ Note | By default <code>allow-dual-stack-queue</code> is enabled, this will add a single dynamic simple queue entry for both DCHPv6 binding and DHCPv4 lease, without this option enabled separate dynamic simple queue entries will be added for IPv6 and IPv4. }}
 
If <code>allow-dual-stack-queue</code> is enabled, then a single dynamic simple queue entry will be created containing both IPv4 and IPv6 addresses:
<pre>
[admin@MikroTik] > /queue simple print
Flags: X - disabled, I - invalid, D - dynamic
0  D name="dhcp-ds<6C:3B:6B:7C:41:3E>" target=192.168.88.254/32,fdb4:4de7:a3f8:418c::/66 parent=none packet-marks="" priority=8/8 queue=default-small/default-small limit-at=10M/10M max-limit=10M/10M burst-limit=0/0 burst-threshold=0/0
      burst-time=0s/0s bucket-size=0.1/0.1
</pre>
 
====RADIUS Support====
 
Since RouterOS v6.43 it is possible to use RADIUS to assign a rate-limit per lease, to do so you need to pass the <var>Mikrotik-Rate-Limit</var> attribute from your RADIUS Server for your lease. To achieve this you first need to set your DHCPv4 Server to use RADIUS for assigning leases. Below is an example how to set it up:
<pre>
/radius
add address=10.0.0.1 secret=VERYsecret123 service=dhcp
/ip dhcp-server
set dhcp1 use-radius=yes
</pre>
 
After that you need to tell your RADIUS Server to pass the <var>Mikrotik-Rate-Limit</var> attribute. In case you are using FreeRADIUS with MySQL, then you need to add appropriate entries into '''radcheck''' and '''radreply''' tables for a MAC address, that is being used for your DHCPv4 Client. Below is an example for table entries:
<pre>
INSERT INTO `radcheck` (`username`, `attribute`, `op`, `value`) VALUES
('00:0C:42:00:D4:64', 'Auth-Type', ':=', 'Accept'),
 
INSERT INTO `radreply` (`username`, `attribute`, `op`, `value`) VALUES
('00:0C:42:00:D4:64', 'Framed-IP-Address', '=', '192.168.88.254'),
('00:0C:42:00:D4:64', 'Mikrotik-Rate-Limit', '=', '10M'),
</pre>


==Alerts==
==Alerts==
Line 570: Line 621:


<p>
<p>
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:
To find any rogue DHCP servers as soon as they appear in your network, DHCP Alert tool can be used. It will monitor the ethernet interface for all DHCP replies and check if this reply comes from a valid DHCP server. If a reply from an unknown DHCP server is detected, alert gets triggered:
<pre>
<pre>
[admin@MikroTik] ip dhcp-server alert>/log print
[admin@MikroTik] ip dhcp-server alert>/log print
Line 580: Line 631:
</p>
</p>
<p>
<p>
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 detector acts as a dhcp client as well - it sends out dhcp discover requests once a minute
As DHCP replies can be unicast, the 'rogue dhcp detector' may not receive any offer to other dhcp clients at all. To deal with this, the rogue dhcp detector acts as a dhcp client as well - it sends out dhcp discover requests once a minute
</p>
</p>


Line 591: Line 642:
<tr>
<tr>
     <td><var><b>alert-timeout</b></var> (<em>none | time</em>; Default: <b>none</b>)</td>
     <td><var><b>alert-timeout</b></var> (<em>none | time</em>; Default: <b>none</b>)</td>
     <td>Time, after which alert will be forgotten. If after that time the same server will be detected, new alert will be generated. If set to <b>none</b> timeout will never expire.</td>
     <td>Time after which alert will be forgotten. If after that time the same server is detected, new alert will be generated. If set to <b>none</b> timeout will never expire.</td>
</tr>
</tr>
<tr>
<tr>
Line 638: Line 689:


<p>
<p>
With help of DHCP Option list, it is possible to define additional custom options for DHCP Server to advertise.
With help of DHCP Option list, it is possible to define additional custom options for DHCP Server to advertise. Option precedence is as follows:
*radius,
*lease,
*server,
*network.
This is the order in which client option request will be filled in.
</p>
</p>
<p>
<p>
Line 660: Line 716:
<tr>
<tr>
     <td><var><b>value</b></var> (<em>string</em>; Default: <b></b>)</td>
     <td><var><b>value</b></var> (<em>string</em>; Default: <b></b>)</td>
     <td>Parameter's value in form of a string. If the string begins with "0x", it is assumed as a hexadecimal value</td>
     <td>Parameter's value.
 
 
Starting from v6.8 available data types for options are:
* 0xXXXX - hex string (works also in v5)
* 'XXXXX' - string (works also in v5 but without ' ' around the text)
* $(XXXXX) - variable (currently there are no variables for server)
* '10.10.10.10' - IP address
* s'10.10.10.10' - IP address converted to string
* '10' - decimal number
* s'10' - decimal number converted to string
 
RouterOS has predefined variables that can be used:
* HOSTNAME - client hostname
* RADIUS_MT_STR1 - from radius MT attr nr. 24
* RADIUS_MT_STR2 - from radius MT attr nr. 25
* REMOTE_ID - agent remote id
* NETWORK_GATEWAY - first gateway from '/ip dhcp-server network', note that this option won't work if used from lease
 
 
Now it is also possible to combine data types into one, for example:
"0x01'vards'$(HOSTNAME)"
 
For example if HOSTNAME is 'kvm', then raw value will be 0x0176617264736b766d.
 
</td>
</tr>
<tr>
    <td><var><b>raw-value</b></var> (<em>HEX string</em> <b></b>)</td>
    <td>Read only field which shows raw dhcp option value (the format actually sent out)</td>
</tr>
</tr>
</table>
</table>


===Example===
===Example===
<p>
 
Classless route adds specified route in clients routing table. In our example it will add dst-address=160.0.0.0/24 gateway=10.1.101.1
'''Classless Route'''
 
A classless route adds specified route in clients routing table. In our example, it will add  
* dst-address=160.0.0.0/24 gateway=10.1.101.1
* dst-address=0.0.0.0/0 gateway=10.1.101.1
 
 
According to RFC 3442: The first part is the netmask ("18" = netmask /24). Second part is
significant part of destination network ("A00000" = 160.0.0). Third part is IP address of
gateway ("0A016501" = 10.1.101.1). Then There are parts of the default route, destination netmask (0x00 = 0.0.0.0/0) followed by default route (0x0A016501 = 10.1.101.1)
   
   
<pre>
<pre>
Line 684: Line 779:
</pre>
</pre>


</p>
Much more robust way would be to use built in variables, previous example can be rewritten as:
<pre>
/ip dhcp-server option
add name=classless code=121 value="0x18A00000\$(NETWORK_GATEWAY)0x00\$(NETWORK_GATEWAY)"
</pre>


==Configuration Examples==


===Enabling IPv6 Prefix delegation===
'''Auto Proxy Config'''
 
Lets consider that we already have running DHCP server.
 
To enable IPv6 prefix delegation, first we need to create address pool


<pre>
<pre>
/ipv6 pool add name=myPool prefix=2001:db8:7501::/60  prefix-length=62
/ip dhcp-server option
  add code=252 name=auto-proxy-config value="'http://autoconfig.something.lv/wpad.dat'"
</pre>
</pre>
Notice that prefix-length is 62 bits, it means that clients will receive /62 prefixes from the /60 pool.


Next step is to enable DHCPv6. It is done simply by adding address-pool6 in servers configuration


<pre>
==DHCP Option Sets==
/ip dhcp-server set myServer address-pool6=myPool
</pre>


<p id="shbox"><b>Sub-menu:</b> <code>/ip dhcp-server option sets</code></p>
<br />


Since RouterOS does not support DHCPv6 client yet, to test our server we will set up wide-dhcpv6 on ubuntu machine:
This menu allows to combine multiple options in option sets, which later can be used to override default DHCP server option set.
* install wide-dhcpv6-client
* edit "/etc/wide-dhcpv6/dhcp6c.conf" as above


<pre>
interface eth2{
  send ia-pd 0;
};


id-assoc pd {
{{Mr-arg-table-h
  prefix-interface eth3{
|prop=Property
  sla-id 1;
|desc=Description
  sla-len 2;
}}
  };
};


</pre>
{{Mr-arg-table
|arg=name
|type=string
|default=
|desc=Name of the option set.
}}


* Run DHCPv6 client
{{Mr-arg-table-end
<pre>
|arg=options
sudo dhcp6c -d -D -f eth2
|type=list
</pre>
|default=
|desc=List of options defined in options menu.
}}


* Verify that prefix was added to eth3
==Configuration Examples==
<pre>
mrz@bumba:/media/aaa$ ip -6 addr
..
2: eth3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qlen 1000
    inet6 2001:db8:7501:1:200:ff:fe00:0/64 scope global
      valid_lft forever preferred_lft forever
    inet6 fe80::224:1dff:fe17:81f7/64 scope link
      valid_lft forever preferred_lft forever
</pre>


* You can make binding to specific client static, so that it always receives the same prefix
<pre>
[admin@RB493G] /ip dhcp-server binding6> print
Flags: X - disabled, D - dynamic
#  ADDRESS                                          MAC-ADDRESS      SERVER
0 D 2001:db8:7501:1::/62                    00:24:1D:17:81:F7 dhcp1 
[admin@RB493G] /ip dhcp-server binding6> make-static 0


</pre>


* DHCPv6 also installs route to assigned prefix into IPv6 routing table
<pre>
[admin@RB493G] /ipv6 route> print
Flags: X - disabled, A - active, D - dynamic, C - connect, S - static, r - rip, o - ospf, b - bgp, U - unreachable
#      DST-ADDRESS              GATEWAY                  DISTANCE
...
2 ADS  2001:db8:7501:1::/62    fe80::224:1dff:fe17:8...        1
</pre>


{{cont}}
{{cont}}
Line 765: Line 831:
[[Category:DHCP|D]]
[[Category:DHCP|D]]
[[Category:IP|D]]
[[Category:IP|D]]
[[Category:IPv6|D]]

Revision as of 12:04, 12 April 2019

Version.png

Applies to RouterOS: v3, v4, v5+


Summary

Standards: RFC 2131, RFC 3315, RFC 3633
Package: dhcp


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

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 for the DHCP server to work, IP pools must also be configured (do not include the DHCP server's own IP address into the pool range) and the DHCP networks.

It is also possible to hand out leases for DHCP clients using the RADIUS server; the supported parameters for a RADIUS server is as follows:


Access-Request:

  • NAS-Identifier - router identity
  • NAS-IP-Address - IP address of the router itself
  • NAS-Port - unique session ID
  • NAS-Port-Type - Ethernet
  • Calling-Station-Id - client identifier (active-client-id)
  • Framed-IP-Address - IP address of the client (active-address)
  • Called-Station-Id - name of DHCP server
  • User-Name - MAC address of the client (active-mac-address)
  • Password - ""

Access-Accept:

  • Framed-IP-Address - IP address that will be assigned to client
  • Framed-Pool - ip pool from which to assign ip address to client
  • Rate-Limit - Datarate limitation for DHCP clients. Format is: rx-rate[/tx-rate] [rx-burst-rate[/tx-burst-rate] [rx-burst-threshold[/tx-burst-threshold] [rx-burst-time[/tx-burst-time][priority] [rx-rate-min[/tx-rate-min]]]]. 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 are used as burst thresholds. If both rx-burst-time and tx-burst-time are not specified, 1s is used as default. Priority takes values 1..8, where 1 implies the highest priority, but 8 - the lowest. If rx-rate-min and tx-rate-min are not specified rx-rate and tx-rate values are used. The rx-rate-min and tx-rate-min values can not exceed rx-rate and tx-rate values.
  • Ascend-Data-Rate - tx/rx data rate limitation if multiple attributes are provided, first limits tx data rate, second - rx data rate. If used together with Ascend-Xmit-Rate, specifies rx rate. 0 if unlimited
  • Ascend-Xmit-Rate - tx data rate limitation. It may be used to specify tx limit only instead of sending two sequential Ascend-Data-Rate attributes (in that case Ascend-Data-Rate will specify the receive rate). 0 if unlimited
  • Session-Timeout - max lease time (lease-time)


Icon-note.png

Note: DHCP server requires a real interface to receive raw ethernet packets. If the interface is a Bridge interface, then the Bridge must have a real interface attached as a port to that bridge which will receive the raw ethernet packets. It cannot function correctly on a dummy (empty bridge) interface.


Quick Setup Guide

RouterOS has a built in command that lets you easily set up a DHCP server. Let's say we want to configure DHCP server on ether1 interface to lease addresses from 192.168.0.2 to 192.168.0.254 which belong to the 192.168.0.0/24 network. The gateway and DNS server is 192.168.0.1.

From /ip dhcp-server menu run setup command and follow instructions:

[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: 192.168.0.0/24
Select gateway for given network

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

addresses to give out: 192.168.0.2-192.168.0.254
Select DNS servers

dns servers: 192.168.0.1
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 192.168.0.0/24        192.168.0.1        192.168.0.1

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

[admin@MikroTik] ip dhcp-server>

IPv6

Starting from v5.8 RouterOS supports IPv6 prefix delegation according to RFC 3315 and RFC 3633.

Starting from v5.9, DHCPv6 server configuration was moved to /ipv6 sub-menu. Read-more >>

General

Sub-menu: /ip dhcp-server


Property Description
add-arp (yes | no; Default: no) Whether to add dynamic ARP entry. If set to no either ARP mode should be enabled on that interface or static ARP entries should be administratively defined in /ip arp submenu.
address-pool (string | static-only; Default: static-only) IP pool, from which to take IP addresses for the clients. If set to static-only, then only the clients that have a static lease (added in lease submenu) will be allowed.
allow-dual-stack-queue (yes | no; Default: yes) Creates a single simple queue entry for both IPv4 and IPv6 addresses, uses the MAC address and DUID for identification. Requires IPv6 DHCP Server to have this option enabled as well to work properly.
always-broadcast (yes | no; Default: no) Always send replies as broadcasts even if destination IP is known. Will add additional load on L2 network.
authoritative (after-10sec-delay | after-2sec-delay | yes | no; Default: yes) Option changes the way how server responds to DHCP requests:
  • yes - replies to clients request for an address that is not available from this server, dhcp server will send negative acknowledgment (DHCPNAK)
  • no - dhcp server ignores clients requests for addresses that are not available from this server
  • after-10sec-delay - requests with "secs < 10" will be processed as in "no" setting case and requests with "secs >= 10" will be processed as in "yes" case.
  • after-2sec-delay - requests with "secs < 2" will be processed as in "no" setting case and requests with "secs >= 2" will be processed as in "yes" case.


If all requests with "secs < x" should be ignored, then delay-threshold=x setting should be used.
bootp-lease-time (forever | lease-time | time; Default: ) Accepts two predefined options or time value:
  • forever - lease never expires
  • lease-time - use time from lease-time parameter
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
client-mac-limit (integer | unlimited; Default: unlimited) Specifies whether to limit specific number of clients per single MAC address or leave unlimited. Note that this setting should not be used in relay setups.
conflict-detection (yes | no; Default: ) Allows to disable/enable conflict detection. If option is enabled, then whenever server tries to assign a lease it will send ICMP and ARP messages to detect whether such address in the network already exist. If any of above get reply address is considered already used. Conflict detection must be disabled when any kind of DHCP client limitation per port or per mac is used.
delay-threshold (time | none; Default: none) If secs field in DHCP packet is smaller than delay-threshold, then this packet is ignored. If set to none - there is no threshold (all DHCP packets are processed)
dhcp-option-set (name | none; Default: ) Use custom set of DHCP options defined in option sets menu.
insert-queue-before (bottom | first | name; Default: ) Specify where to place dynamic simple queue entries for static DCHP leases with rate-limit parameter set.
interface (string; Default: ) Interface on which server will be running.
lease-script (string; Default: "") Script that will be executed after lease is assigned or de-assigned. Internal "global" variables that can be used in the script:
  • leaseBound - set to "1" if bound, otherwise set to "0"
  • leaseServerName - dhcp server name
  • leaseActMAC - active mac address
  • leaseActIP - active IP address
  • lease-hostname - client hostname
lease-time (time; Default: 10m) The time that a client may use the assigned 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 (string; Default: ) Reference name
parent-queue (string | none; Default: none)
relay (IP; 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 relay allowed)
  • 255.255.255.255 - the DHCP server should be used for any incoming 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; 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-framed-as-classless (yes | no; Default: yes) Forward RADIUS Framed-Route as a DHCP Classless-Static-Route to DHCP-client. Whenever both Framed-Route and Classless-Static-Route is received Classless-Static-Route is preferred.
use-radius (yes | no | accounting; Default: no) Whether to use RADIUS server:
  • no - do not use RADIUS;
  • yes - use RADIUS for accounting and lease;
  • accounting - use RADIUS for accounting only.


Menu specific commands

Property Description
setup () Start DHCP server setup wizard, which guides you through the steps to easily create all necessary configuration. Read more>>

Lease Store Configuration

Sub-menu: /ip dhcp-server config

This sub-menu allows the configuration of how often the DHCP leases will be stored on disk. If they would be saved on disk on every lease change, a lot of disk writes would happen which is very bad for Compact Flash (especially, if lease times are very short). To minimize writes on disk, all changes are saved on disk every store-leases-disk seconds. Additionally leases are always stored on disk on graceful shutdown and reboot.

Icon-note.png

Note: Manual changes to leases - addition/removal of static lease, removal of dynamic lease will cause changes to be pushed for this lease to storage.


This sub-menu has only one configurable property:

Property Description
store-leases-disk (time | immediately | never; Default: 5m) How frequently lease changes should be stored on disk

Networks

Sub-menu: /ip dhcp-server network


Property Description
address (IP/netmask; Default: ) the network DHCP server(s) will lease addresses from
boot-file-name (string; Default: ) Boot file name
caps-manager (string; Default: ) Comma-separated list of IP addresses for one or more CAPsMAN system managers. DHCP Option 138 (capwap) will be used.
dhcp-option (string; Default: ) Add additional DHCP options from option list.
dhcp-option-set (string; Default: ) Add additional set of DHCP options.
dns-none (yes | no; Default: no) If set, then DHCP Server will not pass dynamic DNS servers configured on the router to the DHCP clients if no DNS Server in dns-server is set. By default if there are no DNS Servers configured, then the dynamic DNS Servers will be passed to DHCP clients.
dns-server (string; Default: ) the DHCP client will use these as the default DNS servers. Two comma-separated DNS servers can be specified to be used by the DHCP client as primary and secondary DNS servers
domain (string; Default: ) The DHCP client will use this as the 'DNS domain' setting for the network adapter.
gateway (IP; Default: 0.0.0.0) The default gateway to be used by DHCP Client.
netmask (integer: 0..32; Default: 0) The actual network mask to be used by DHCP client. If set to '0' - netmask from network address will be used.
next-server (IP; Default: ) IP address of next server to use in bootstrap.
ntp-server (IP; Default: ) the DHCP client will use these as the default NTP servers. Two comma-separated NTP servers can be specified to be used by the DHCP client as primary and secondary NTP servers
wins-server (IP; Default: ) The Windows DHCP client will use these as the default WINS servers. Two comma-separated WINS servers can be specified to be used by the DHCP client as primary and secondary WINS servers

Leases

Sub-menu: /ip dhcp-server lease


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 a specific IP address to a particular client (identified by MAC address) .

Generally, the DHCP lease it allocated as follows:

  • an unused lease is in waiting state
  • if a client asks for an IP address, the server chooses one
  • if the client receives a statically assigned address, the lease becomes offered, and then bound with the respective lease time
  • if the client receives 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
  • in the case where the address does not respond, the lease becomes offered and then bound with the respective lease time
  • 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. The dynamic lease is removed, and the allocated address is returned to the address pool. But the static lease becomes busy until the client reacquires the address.

Icon-note.png

Note: IP addresses assigned statically are not probed!



Properties

Property Description
address (IP; Default: ) Specify IP address (or ip pool) for static lease. If set to 0.0.0.0 - pool from server will be used
address-list (string; Default: ) Address list to which address will be added if lease is bound.
allow-dual-stack-queue (yes | no; Default: yes) Creates a single simple queue entry for both IPv4 and IPv6 addresses, uses the MAC address and DUID for identification. Requires IPv6 DHCP Server to have this option enabled as well to work properly.
always-broadcast (yes | no; Default: ) Send all replies as broadcasts
block-access (yes | no; Default: no) Block access for this client
client-id (string; Default: ) If specified, must match DHCP 'client identifier' option of the request
dhcp-option (string; Default: ) Add additional DHCP options from option list.
dhcp-option-set (string; Default: ) Add additional set of DHCP options.
insert-queue-before (bottom | first | name;; Default: ) Specify where to place dynamic simple queue entries for static DCHP leases with rate-limit parameter set.
lease-time (time; Default: 0s) Time that the client may use the address. If set to 0s lease will never expire.
mac-address (MAC; Default: 00:00:00:00:00:00) If specified, must match the MAC address of the client
rate-limit (integer[/integer] [integer[/integer] [integer[/integer] [integer[/integer]]]];; Default: ) Adds a dynamic simple queue to limit IP's bandwidth to a specified rate. Requires the lease to be static. 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.
server (string) Server name which serves this client
use-src-mac (yes | no; Default: no) When this option is set server uses source MAC address instead of received CHADDR to assign address.


Icon-warn.png

Warning: The always-broadcast parameter will dynamically change. For the initial DHCP discover/offer/request/ack cycle a broadcast MAC address is going to be used, for lease renewal (request and ack) an unicast MAC address will be used. In case the DHCP Server keeps receiving DHCP requests while DHCP offer has been sent, then the always-broadcast parameter will be turned on dynamically until the DHCP lease has been renewed successfully.


Read only properties

Property Description
active-address (IP) Actual IP address for this lease
active-client-id (string) Actual client-id of the client
active-mac-address (MAC) Actual MAC address of the client
active-server (list) Actual dhcp server, which serves this client
agent-circuit-id (string) Circuit ID of DHCP relay agent. If each character should be valid ASCII text symbol or else this value is displayed as hex dump.
agent-remote-id (string) Remote ID, set by DHCP relay agent
blocked ( flag ) Whether the lease is blocked
expires-after (time) Time until lease expires
host-name (text) Shows host name option from last received DHCP request
radius (yes | no) Shows if this dynamic lease is authenticated by RADIUS or not
status (waiting | testing | authorizing | busy | offered | bound) Lease status:
  • waiting - un-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 no later than the lease time
src-mac-address (MAC; Default: ) Source MAC address


Menu specific commands

Property Description
check-status (id) Check status of a given busy dynamic lease, and free it in case of no response
make-static (id) Convert a dynamic lease to a static one

Rate limiting

It is possible to set a bandwidth to a specific IPv4 address by using DHCPv4 leases. This can be done by setting a rate limit on the DHCPv4 lease itself, by doing this a dynamic simple queue rule will be added for the IPv4 address that corresponds to the DHCPv4 lease. By using the rate-limit parameter you can conveniently limit a user's bandwidth.

Icon-note.png

Note: For any queues to work properly, the traffic must not be FastTracked, make sure your Firewall does not FastTrack traffic that you want to limit.


First, make the DHCPv4 lease static, otherwise it will not be possible to set a rate limit to a DHCPv4 lease:

[admin@MikroTik] > /ip dhcp-server lease print 
Flags: X - disabled, R - radius, D - dynamic, B - blocked 
 #   ADDRESS               MAC-ADDRESS       HOST-NAME               SERVER               RATE-LIMIT               STATUS 
 0 D 192.168.88.254        6C:3B:6B:7C:41:3E MikroTik                DHCPv4_Server                                 bound 

[admin@MikroTik] > /ip dhcp-server lease make-static 0

[admin@MikroTik] > /ip dhcp-server lease print 
Flags: X - disabled, R - radius, D - dynamic, B - blocked 
 #   ADDRESS               MAC-ADDRESS       HOST-NAME               SERVER               RATE-LIMIT               STATUS 
 0   192.168.88.254        6C:3B:6B:7C:41:3E MikroTik                DHCPv4_Server                                 bound

Then you can set a rate to a DHCPv4 lease that will create a new dynamic simple queue entry:

[admin@MikroTik] > /ip dhcp-server lease set 0 rate-limit=10M/10M

[admin@MikroTik] > /queue simple print 
Flags: X - disabled, I - invalid, D - dynamic 
 0  D name="dhcp-ds<6C:3B:6B:7C:41:3E>" target=192.168.88.254/32 parent=none packet-marks="" priority=8/8 queue=default-small/default-small limit-at=10M/10M max-limit=10M/10M burst-limit=0/0 burst-threshold=0/0 burst-time=0s/0s 
      bucket-size=0.1/0.1
Icon-note.png

Note: By default allow-dual-stack-queue is enabled, this will add a single dynamic simple queue entry for both DCHPv6 binding and DHCPv4 lease, without this option enabled separate dynamic simple queue entries will be added for IPv6 and IPv4.


If allow-dual-stack-queue is enabled, then a single dynamic simple queue entry will be created containing both IPv4 and IPv6 addresses:

[admin@MikroTik] > /queue simple print 
Flags: X - disabled, I - invalid, D - dynamic 
 0  D name="dhcp-ds<6C:3B:6B:7C:41:3E>" target=192.168.88.254/32,fdb4:4de7:a3f8:418c::/66 parent=none packet-marks="" priority=8/8 queue=default-small/default-small limit-at=10M/10M max-limit=10M/10M burst-limit=0/0 burst-threshold=0/0 
      burst-time=0s/0s bucket-size=0.1/0.1 

RADIUS Support

Since RouterOS v6.43 it is possible to use RADIUS to assign a rate-limit per lease, to do so you need to pass the Mikrotik-Rate-Limit attribute from your RADIUS Server for your lease. To achieve this you first need to set your DHCPv4 Server to use RADIUS for assigning leases. Below is an example how to set it up:

/radius
add address=10.0.0.1 secret=VERYsecret123 service=dhcp
/ip dhcp-server
set dhcp1 use-radius=yes

After that you need to tell your RADIUS Server to pass the Mikrotik-Rate-Limit attribute. In case you are using FreeRADIUS with MySQL, then you need to add appropriate entries into radcheck and radreply tables for a MAC address, that is being used for your DHCPv4 Client. Below is an example for table entries:

INSERT INTO `radcheck` (`username`, `attribute`, `op`, `value`) VALUES
('00:0C:42:00:D4:64', 'Auth-Type', ':=', 'Accept'),

INSERT INTO `radreply` (`username`, `attribute`, `op`, `value`) VALUES
('00:0C:42:00:D4:64', 'Framed-IP-Address', '=', '192.168.88.254'),
('00:0C:42:00:D4:64', 'Mikrotik-Rate-Limit', '=', '10M'),

Alerts

Sub-menu: /ip dhcp-server alert


To find any rogue DHCP servers as soon as they appear in your network, DHCP Alert tool can be used. It will monitor the ethernet interface for all DHCP replies and check if this reply comes from a valid DHCP server. If a reply from an 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, the 'rogue dhcp detector' may not receive any offer to other dhcp clients at all. To deal with this, the rogue dhcp detector acts as a dhcp client as well - it sends out dhcp discover requests once a minute

Properties

Property Description
alert-timeout (none | time; Default: none) Time after which alert will be forgotten. If after that time the same server is detected, new alert will be generated. If set to none timeout will never expire.
interface (string; Default: ) Interface, on which to run rogue DHCP server finder.
on-alert (string; Default: ) Script to run, when an unknown DHCP server is detected.
valid-server (string; Default: ) List of MAC addresses of valid DHCP servers.


Read only properties

Property Description
unknown-server (string) List of MAC addresses of detected unknown DHCP servers. Server is removed from this list after alert-timeout


Menu specific commands

Property Description
reset-alert (id) Clear all alerts on an interface

DHCP Options

Sub-menu: /ip dhcp-server option


With help of DHCP Option list, it is possible to define additional custom options for DHCP Server to advertise. Option precedence is as follows:

  • radius,
  • lease,
  • server,
  • network.

This is the order in which client option request will be filled in.

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.

Properties

Property Description
code (integer:1..254; Default: ) dhcp option code. All codes are available at http://www.iana.org/assignments/bootp-dhcp-parameters
name (string; Default: ) Descriptive name of the option
value (string; Default: ) Parameter's value.


Starting from v6.8 available data types for options are:

  • 0xXXXX - hex string (works also in v5)
  • 'XXXXX' - string (works also in v5 but without ' ' around the text)
  • $(XXXXX) - variable (currently there are no variables for server)
  • '10.10.10.10' - IP address
  • s'10.10.10.10' - IP address converted to string
  • '10' - decimal number
  • s'10' - decimal number converted to string

RouterOS has predefined variables that can be used:

  • HOSTNAME - client hostname
  • RADIUS_MT_STR1 - from radius MT attr nr. 24
  • RADIUS_MT_STR2 - from radius MT attr nr. 25
  • REMOTE_ID - agent remote id
  • NETWORK_GATEWAY - first gateway from '/ip dhcp-server network', note that this option won't work if used from lease


Now it is also possible to combine data types into one, for example: "0x01'vards'$(HOSTNAME)"

For example if HOSTNAME is 'kvm', then raw value will be 0x0176617264736b766d.

raw-value (HEX string ) Read only field which shows raw dhcp option value (the format actually sent out)

Example

Classless Route

A classless route adds specified route in clients routing table. In our example, it will add

  • dst-address=160.0.0.0/24 gateway=10.1.101.1
  • dst-address=0.0.0.0/0 gateway=10.1.101.1


According to RFC 3442: The first part is the netmask ("18" = netmask /24). Second part is significant part of destination network ("A00000" = 160.0.0). Third part is IP address of gateway ("0A016501" = 10.1.101.1). Then There are parts of the default route, destination netmask (0x00 = 0.0.0.0/0) followed by default route (0x0A016501 = 10.1.101.1)

/ip dhcp-server option
add code=121 name=classless value=0x18A000000A016501000A016501
/ip dhcp-server network
set 0 dhcp-option=classless

Result:

[admin@MikroTik] /ip route> print
Flags: X - disabled, A - active, D - dynamic, C - connect, S - static, r - rip, b - bgp, o - ospf,
m - mme, B - blackhole, U - unreachable, P - prohibit
 #      DST-ADDRESS        PREF-SRC        GATEWAY            DISTANCE
 0 ADS  0.0.0.0/0                          10.1.101.1         0
 1 ADS  160.0.0.0/24                       10.1.101.1         0

Much more robust way would be to use built in variables, previous example can be rewritten as:

/ip dhcp-server option 
add name=classless code=121 value="0x18A00000\$(NETWORK_GATEWAY)0x00\$(NETWORK_GATEWAY)"


Auto Proxy Config

/ip dhcp-server option 
  add code=252 name=auto-proxy-config value="'http://autoconfig.something.lv/wpad.dat'"


DHCP Option Sets

Sub-menu: /ip dhcp-server option sets


This menu allows to combine multiple options in option sets, which later can be used to override default DHCP server option set.


Property Description
name (string; Default: ) Name of the option set.
options (list; Default: ) List of options defined in options menu.

Configuration Examples

[ Top | Back to Content ]