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.
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).
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:
[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!
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>
[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:
- waiting - not used static lease
- testing - testing whether this address is used or not
- busy - this address is used in the network, so it can not be leased
- offered - server has offered this lease to a client, but did not receive client confirmation
- bound - server has received client confirmation that it accepts offered address and is using it now
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).
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