Manual:IP/DHCP Client

From MikroTik Wiki
< Manual:IP
Revision as of 08:55, 28 October 2011 by Marisb (talk | contribs)
Jump to navigation Jump to search
Version.png

Applies to RouterOS: v3, v4 +

Summary

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

RouterOS DHCP cilent asks for following options:

  • option 1 - SUBNET_MASK,
  • option 3 - GATEWAY_LIST,
  • option 6 - TAG_DNS_LIST,
  • option 33 - STATIC_ROUTE,
  • option 42 - NTP_LIST,
  • option 122 - CLASSLESS_ROUTE,


IPv6

Starting from v5.8 DHCP Client can receive delegated prefixes from DHCPv6 server. Currently received prefix is added to IPv6 pool, which later can be used for example in pppoe server configuration.

Quick setup example

Add a DHCP client on ether1 interface:

/ip dhcp-client add interface=ether1 disabled=no

After interface is added, you can use rint" or "print detail" command to see what parameters DHCP client acquired:

[admin@MikroTik] ip dhcp-client> print detail
Flags: X - disabled, I - invalid 
 0   interface=ether1 add-default-route=yes use-peer-dns=yes use-peer-ntp=yes
     status=bound address=192.168.0.65/24 gateway=192.168.0.1
     dhcp-server=192.168.0.1 primary-dns=192.168.0.1 primary-ntp=192.168.0.1
     expires-after=9m44s 
[admin@MikroTik] ip dhcp-client>
Icon-note.png

Note: If interface used by DHCP client is part of VRF configuration, then default route and other received routes from DHCP server will be added to VRF routing table.


Properties

Sub-menu: /ip dhcp-client


Property Description
add-default-route (yes | no; Default: yes) Whether to install default route in routing table received from dhcp server.
client-id (string; Default: ) Corresponds to the settings suggested by the network administrator or ISP. If not specified, client's MAC address will be sent
default-route-distance (integer:0..255; Default: ) Distance of default route. Applicable if add-default-route is set to yes.
host-name (string; Default: ) Host name of the client sent to a DHCP server. If not specified, client's system identity will be used.
ipv4 (yes | no; Default: yes) Client will receive IPv4 address from the server if this parameter is set.
ipv6-pd (yes | no; Default: no) Client will receive delegated prefix from DHCPv6-PD server.
pool-name (string; Default: ) Name of the IPv6 pool in which received IPv6 prefix will be added. Applicable if ipv6-pd is enabled.
pool-prefix-length (string; Default: ) Prefix length parameter that will be set for IPv6 pool in which received IPv6 prefix is added. Applicable if ipv6-pd is enabled. Prefix length must be greater than the length of received prefix, otherwise prefix-length will be set to received prefix length + 8 bits.
interface (string; Default: ) Interface on which DHCP client will be running.
use-peer-dns (yes | no; Default: yes) Whether to accept the DNS settings advertised by DHCP Server. (Will override the settings put in the /ip dns submenu.
use-peer-ntp (yes | no; Default: yes) Whether to accept the NTP settings advertised by DHCP Server. (Will override the settings put in the /system ntp client submenu)

Status

Command /ip dhcp-client print detail will show current status of dhcp client and read-only properties listed in table below:


Property Description
address (IP/Netmask) IP address and netmask, which is assigned to DHCP Client from the Server
dhcp-server (IP) IP address of the DHCP server.
expires-after (time) Time when the lease expires (specified by the DHCP server).
expires-after-v6 (time) Time when the IPv6 prefix expires (specified by the DHCP server).
gateway (IP) IP address of the gateway which is assigned by DHCP server
invalid (yes | no) Shows whether configuration is invalid.
netmask (IP)
prefix (IPv6 prefix) Shows received IPv6 prefix from DHCPv6-PD server
primary-dns (IP) IP address of the primary DNS server, assigned by the DHCP server
primary-ntp (IP) IP address of the primary NTP server, assigned by the DHCP server
secondary-dns (IP) IP address of the secondary DNS server, assigned by the DHCP server
secondary-ntp (IP) IP address of the secondary NTP server, assigned by the DHCP server
status (bound | error | rebinding... | requesting... | searching... | stopped) Shows the status of DHCP Client
v6-status (stopped | searching | requesting... | bound | renewing | rebinding | error | stopping) Shows the status of DHCPv6 Client:
  • stopped - dhcpv6 client is stopped
  • searching - sending "solicit" and trying to get "advertise"
  • requesting - sent "request" waiting for "reply"
  • bound - received "reply". Prefix assigned.
  • renewing - sent "renew", waiting for "reply"
  • rebinding - sent "rebind", waiting for "reply"
  • error - reply was not received in time or some other error ocurred.
  • stopping - sent "release"

Menu specific commands

Property Description
release (numbers) Release current binding and restart DHCP client
renew (numbers) Renew current leases. If the renew operation was not successful, client tries to reinitialize lease (i.e. it starts lease request procedure (rebind) as if it had not received an IP address yet)


Setup Examples

IPv6-PD setup example

This simple example demonstrates how to enable dhcp client to receive IPv6 prefix and add it to the pool.

For DHCPv6 client to work we just need to specify four parameters:

/ip dhcp-client add ipv6-pd=yes pool-name=ipv6 pool-prefix-length=64 interface=ether13


Detailed print should show status of the client and we can verify if prefix is received

[admin@MikroTik] /ip dhcp-client> print detail 
Flags: X - disabled, I - invalid 
 0   interface=ether13 ipv4=yes add-default-route=yes default-route-distance=1 
     use-peer-dns=yes use-peer-ntp=yes ipv6-pd=yes pool-name="ipv6" pool-prefix-length=64 
     status=bound address=10.5.101.9/24 gateway=10.5.101.1 dhcp-server=10.5.101.1 
     primary-dns=10.5.101.1 expires-after=2d23h45m27s v6-status=bound 
     prefix=2001:db8:7501:ff14::/62 expires-after-v6=2d23h45m34s 

Notice that server gave us prefix 2001:db8:7501:ff14::/62. And it should be also added to ipv6 pools

[admin@MikroTik] /ipv6 pool> print 
Flags: D - dynamic 
 #   NAME                         PREFIX                                      PREFIX-LENGTH
 0 D ipv6                         2a02:610:7501:ff14::/62                                64

It works! Now you can use this pool, for example, for pppoe clients.


[ Top | Back to Content ]