DHCP Client and Server

Document revision 24-Jan-2003
This document applies to the MikroTik RouterOS V2.6

Overview

DHCP (Dynamic Host Configuration Protocol) supports easy distribution of IP addresses for a network. The MikroTik RouterOS implementation includes both server and client modes 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 for DHCP clients. See the HotSpot Manual for more details.

Contents of the Manual

The following topics are covered in this manual:

Installation

Please download the dhcp-2.6.x.npk package from the MikroTik's web site, upload it with ftp in BINARY mode to the router and reboot.

Use the /system package print command to see the list of installed packages.

Hardware Resource Usage

The DHCP server does not consume any significant resources. The DHCP client may consume high resource for five to ten seconds when acquiring an address or renewing an address.

DHCP Description

The DHCP protocol gives and allocates IP addresses to IP clients. DHCP is basically insecure and should only be used on secure networks. UDP port 67 is the DHCP listen port and UDP port 68 is the DHPC transmit port.

DHCP Client Setup

The MikroTik RouterOS DHCP client may be enabled on one Ethernet-like interface. The client will accept an address, netmask, default gateway, and two dns server addresses. The IP address will be added to the interface with the netmask. The default gateway will be added to the routing table as a dynamic entry. When the DHCP client is disabled, 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.

The DNS-server from the DHCP server will be used as the router's default DNS if the router's DNS is set to 0.0.0.0 under the /ip dns settings.

To enable DHCP client on Mikrotik router, specify the interface for it, for example:

[admin@MikroTik] ip dhcp-client> set enabled=yes interface=ether1
[admin@MikroTik] ip dhcp-client> print
              enabled: yes
            interface: ether1
            client-id: ""
    add-default-route: yes

Descriptions of arguments:

enabled - Enables or disables the DHCP client (yes, no)
interface - Can be set to any Ethernet-like interface – this includes wireless and EoIP tunnels
client-id - (optional) It should correspond to the settings suggested by the network administrator or ISP
add-default-route - defines whether to add the default route to the gateway specified by DHCP server (yes, no)

To show obtained leases, use lease print command, for example:

[admin@MikroTik] ip dhcp-client> lease print
          address: 80.232.241.15/21
          expires: oct/20/2002 09:43:50
          gateway: 80.232.240.1
      primary-dns: 195.13.160.52
    secondary-dns: 195.122.1.59
[admin@MikroTik] ip dhcp-client>

To renew current leases, use the renew command. If the renew operation was not successful, client tries to reinitialize lease (i.e. it starts lease request procedure as it has not received an IP address yet).

DHCP Server Setup

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.

To use MikroTik RouterOS DHCP server feature, you should:

  1. Specify address pool to be used for DHCP clients.
    Address pools are added/managed under the /ip pool menu, for example:

    [admin@MikroTik] ip pool> add name=our-dhcp-clients ranges=10.0.0.2-10.0.1.254
    

    Do not inlude the DHCP server's (interface's) address into the pool range! See IP Pool Manual for more details!

  2. Add a DHCP server to the interface.

For example:

[admin@MikroTik] ip dhcp-server>
add name=dhcp-office address-pool=our-dhcp-clients interface=ether1 \
     lease-time=72h netmask=255.255.255.0 gateway=10.0.0.1 \
     dns-server=10.0.0.1,159.148.60.2 domain=mt.lv
[admin@MikroTik] ip dhcp-server> enable dhcp-office
[admin@MikroTik] ip dhcp-server> print
Flags: X - disabled, I - invalid
  0   name="dhcp-office" interface=ether1 lease-time=72h 
      address-pool=our-dhcp-clients netmask=255.255.255.0 gateway=10.0.0.1 
      src-address=10.0.0.1 dns-server=10.0.0.1,159.148.60.2 domain="mt.lv" 
      wins-server="" add-arp=yes 
[admin@MikroTik] ip dhcp-server>

Descriptions of arguments:

name - descriptive name for server
interface - All Ethernet like interfaces may run a DHCP server
lease-time - Dictates the time that a client may use an address. Suggested setting is three days. The client will try to renew this address after a half of this time and will request a new address after time limit expires
address-pool - IP pool, from which to take IP addresses for clients
netmask - The netmask to be used by DHCP client
gateway - The default gateway to be used by DHCP client
src-address - The address which the DHCP client must use 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.
dns-server - The DHCP client will use this as the default DNS server. Two comma-separated DNS servers can be specified to be used by DHCP client as primary and secondary DNS servers. Winbox does not have option for specifying two servers, use terminal console instead!
domain - The DHCP client will use this as the 'DNS domain' setting for the network adapter.
wins-server - The Windows DHCP client will use this as the default WINS server. Two comma-separated WINS servers can be specified to be used by DHCP client as primary and secondary WINS servers. Winbox does not have option for specifying two servers, use terminal console instead!
add-arp - defines whether to add dynamic ARP entry. If set to 'no', static ARP entries must be in /ip arp menu. See the IP Addresses and Address Resolution Protocol Manual for more details.

To monitor the leases issued to DHCP clients, use lease print command, for example:

[admin@MikroTik] ip dhcp-server> lease print                                       
Flags: X - disabled, D - dynamic, H - hotspot 
  #    ADDRESS         MAC-ADDRESS       EXPIRES-A... SERVER                 STATUS 
  0 D  10.0.0.202      00:04:EA:99:63:C4 1h47m24s     dhcp-office            bound  
  1 D  10.5.2.90       00:04:EA:C6:0E:40 1h54m9s      switch                 bound  
  2 D  10.5.2.91       00:04:EA:99:63:C0 1h48m1s      switch                 bound  
  3 D  10.0.0.201      00:00:E8:69:68:FE 2h40m4s      dhcp-office            bound  
[admin@MikroTik] ip dhcp-server> 

Static Leases

To assign static IP address for DHCP client, static leases can be used. Static leases can be assigned to MAC addresses using lease add command:

[admin@MikroTik] ip dhcp-server lease> print
Flags: X - disabled, D - dynamic, H - hotspot 
  #    ADDRESS         MAC-ADDRESS       EXPIRES-A... 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, D - dynamic, H - hotspot 
  #    ADDRESS         MAC-ADDRESS       EXPIRES-A... 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>

Leases assigned dynamically by the DHCP server are shown as dynamic.

Printout description (use print detail to see all arguments):

address - leased IP address for the client
mac-address - MAC address of the client. It is base for static lease assignment
expires-after - time until lease expires
server - server name which serves this client
lease-time - dictates the time that a client may use an address
netmask - the netmask to be given with the IP address coming from the range of addresses that can be given out
gateway - the default gateway to be used by the DHCP client
status - lease status:

Note that even though client address is changed in lease print list it will not change for the client. It is true for any changes in in the DHCP server configuration because of 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).

Additional DHCP Resources

Links for DHCP documentation:

http://www.ietf.org/rfc/rfc2131.txt?number=2131
http://www.isc.org/products/DHCP/
http://www.linuxdoc.org/HOWTO/mini/DHCP/
http://arsinfo.cit.buffalo.edu/FAQ/faq.cgi?pkg=ISC%20DHCP


© Copyright 1999-2002, MikroTik