DHCP Client and Server
Document revision 1.6 (05-May-2003)
This document applies to the MikroTik RouterOS V2.7
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 assignment in LAN, cable-modem, and wireless systems
- Obtaining IP settings on cable-modem systems
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.
Packages required : dhcp
License required : Any
Home menu level : /ip dhcp-client, /ip dhcp-server
Protocols utilized : DHCP (RFC2131)
Hardware usage: not significant
Software
Package Installation and Upgrading
IP Addresses
and Address Resolution Protocol (ARP)
IP Pools
HotSpot Gateway
The DHCP protocol gives and allocates IP addresses to IP clients.
DHCP is basically insecure and should only be used on secure networks.
DHCP server listens on UDP 67 port, DHCP client - on UDP 68 port.
Submenu level : /ip dhcp-client
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.
enabled (yes | no, default: no) - whether the DHCP client is enabled
interface (name) - any Ethernet-like interface (this includes
wireless and EoIP tunnels)
host-name (string; default: "") - (optional) the host name of the client
client-id (string; default: "") - (optional) corresponds to the settings
suggested by the network administrator or ISP
add-default-route (yes | no, default: yes) - whether to add the default
route to the gateway specified by DHCP server
use-peer-dns (yes | no, default: yes) - whether to accept the DNS
settings advertized by DHCP server (they will appear in /ip dns settings)
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.
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).
To enable DHCP client on ether1 interface:
[admin@MikroTik] ip dhcp-client> set enabled=yes interface=ether1
[admin@MikroTik] ip dhcp-client> print
enabled: yes
interface: ether1
host-name: ""
client-id: ""
add-default-route: yes
use-peer-dns: yes
To show obtained leases:
[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>
Submenu level : /ip dhcp-server
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.
name (name; default: "")- descriptive name for server
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
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)
netmask (integer; default: 0) - the netmask to
be used by DHCP client
gateway (IP address; default: 0.0.0.0) - the default gateway
to be used by DHCP client
src-address (IP address; default: 0.0.0.0) - 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 (string; default: "") - 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
domain (string; default: "") - the DHCP client will use this as
the 'DNS domain' setting for the network adapter
wins-server (string; default: "") - 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
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 defined in /ip arp submenu
Winbox does not have option for specifying two DNS or WINS servers,
you should use terminal console instead.
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).
To use MikroTik RouterOS DHCP server feature:
- 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
[admin@MikroTik] ip pool> print
# NAME RANGES
0 our-dhcp-clients 10.0.0.2-10.0.1.254
[admin@MikroTik] ip pool>
Do not inlude the DHCP server's (interface's) address into the pool range!
See IP Pool Manual for more details!
- 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=24 \
\... 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=24 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>
Submenu level : /ip dhcp-server lease
DHCP server lease submenu is used to monitor and manage server's leases. You can
also add static leases to issue the definite client (determined by MAC address)
with the specified IP address.
address (IP address; default: 0.0.0.0) - leased IP address for the client
mac-address (MAC address; default: 00:00:00:00:00:00) - MAC address of the client.
It is base for static lease assignment
lease-time (time; default: 0) - dictates the time that a client may use an address
never (the same as 0) - lease will never expire
netmask (integer; default: 0) - the netmask to be given with the IP
address coming from the range of addresses that can be given out
gateway (IP address; default: "") - the default gateway to be used by the DHCP client
Statistics:
server (name) - server name which serves this client
expires-after (time) - time until lease expires
status (waiting | testing | busy | offeres | bound) - 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
Blank default values for some properties meand that property will be taken from the
server's default values.
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 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).
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, 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>
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-2003, MikroTik