DHCP Client Configuration
DHCP Client Configuration
Section titled “DHCP Client Configuration”TL;DR (Quick Start)
Section titled “TL;DR (Quick Start)”For the impatient: enable DHCP client on your WAN interface to get an IP from your ISP.
/ip dhcp-client add interface=ether1 disabled=noVerify with:
/ip dhcp-client printLook for status=bound and an assigned IP address.
Overview
Section titled “Overview”What this does: DHCP (Dynamic Host Configuration Protocol) Client enables automatic IP address configuration on MikroTik RouterOS interfaces. The client receives an IP address, netmask, default gateway, and DNS/NTP server addresses from a DHCP server.
When to use this:
- WAN connections to ISPs that provide dynamic IP addresses
- Automated network configuration without manual IP setup
- Multi-WAN failover setups with dynamic addressing
- Any scenario where you need dynamic IP assignment from an upstream DHCP server
Prerequisites:
- An Ethernet-like interface (Ethernet, VLAN, Bridge, Wireless)
- No static IP address configured on the same interface
- Access to a network with a DHCP server (typically your ISP or upstream router)
Configuration Steps
Section titled “Configuration Steps”Step 1: Add DHCP Client to WAN Interface
Section titled “Step 1: Add DHCP Client to WAN Interface”Enable DHCP client on your WAN interface. This will automatically request an IP address from the upstream DHCP server.
/ip dhcp-client add interface=ether1 disabled=noBy default, this configuration will:
- Accept and use DNS servers from the DHCP server (
use-peer-dns=yes) - Accept and use NTP servers from the DHCP server (
use-peer-ntp=yes) - Install a default route via the received gateway (
add-default-route=yes)
Step 2: Verify Lease Acquisition
Section titled “Step 2: Verify Lease Acquisition”Check that the DHCP client successfully obtained an IP address.
/ip dhcp-client print detailExpected output:
Flags: D - dynamic, X - disabled, I - invalid 0 interface=ether1 add-default-route=yes default-route-distance=1 use-peer-dns=yes use-peer-ntp=yes dhcp-options=hostname,clientid status=bound address=192.168.1.100/24 gateway=192.168.1.1 dhcp-server=192.168.1.1 primary-dns=8.8.8.8 expires-after=23h45mThe key indicator is status=bound with a valid IP address.
Step 3: Confirm Default Route
Section titled “Step 3: Confirm Default Route”Verify the default route was installed correctly.
/ip route print where dst-address=0.0.0.0/0Expected output:
Flags: D - dynamic, A - active, c - connect, d - dhcp # DST-ADDRESS GATEWAY DISTANCE 0 DAd 0.0.0.0/0 192.168.1.1 1The d flag indicates the route was added dynamically by DHCP.
Common Scenarios
Section titled “Common Scenarios”Scenario: Use Your Own DNS Servers
Section titled “Scenario: Use Your Own DNS Servers”If you want to use custom DNS servers instead of those provided by your ISP:
/ip dhcp-client add interface=ether1 disabled=no use-peer-dns=no use-peer-ntp=noThen configure your preferred DNS servers:
/ip dns set servers=1.1.1.1,8.8.8.8Scenario: Multi-WAN Failover
Section titled “Scenario: Multi-WAN Failover”For setups with two ISP connections where the second is a backup:
# Primary WAN - lower distance = preferred/ip dhcp-client add interface=ether1 disabled=no default-route-distance=1 \ use-peer-dns=no use-peer-ntp=no
# Secondary WAN - higher distance = backup/ip dhcp-client add interface=ether2 disabled=no default-route-distance=2 \ use-peer-dns=no use-peer-ntp=noFor automatic failover when primary link fails:
/ip dhcp-client set [find interface=ether1] check-gateway=ping/ip dhcp-client set [find interface=ether2] check-gateway=pingScenario: Custom Hostname for ISP
Section titled “Scenario: Custom Hostname for ISP”Some ISPs require or prefer a specific hostname:
/ip dhcp-client set [find interface=ether1] host-name="my-router"Scenario: LTE Interface DHCP Client
Section titled “Scenario: LTE Interface DHCP Client”LTE interfaces create dynamic DHCP clients that cannot be edited directly. Configure via APN profile instead:
/interface lte apn set [find name=default] default-route-distance=2 use-peer-dns=no add-default-route=yesScenario: DHCP Client with Script (Advanced)
Section titled “Scenario: DHCP Client with Script (Advanced)”For advanced multi-WAN setups requiring custom route management:
/ip dhcp-client add interface=ether1 disabled=no add-default-route=no script={ :if ($bound=1) do={ /ip route add gateway=$"gateway-address" comment="WAN1-DHCP" :log info ("DHCP bound: " . $"lease-address" . " via " . $"gateway-address") } else={ /ip route remove [find comment="WAN1-DHCP"] :log info "DHCP lease lost" }}Script variables available:
| Variable | Description |
|---|---|
$bound | 1 = lease acquired, 0 = lease lost |
$"lease-address" | Assigned IP address |
$"gateway-address" | Gateway from DHCP server |
$interface | Interface name |
$"server-address" | DHCP server IP |
Verification
Section titled “Verification”Confirm your DHCP client configuration is working:
Check 1: Verify Client is Bound
Section titled “Check 1: Verify Client is Bound”/ip dhcp-client print detail where status=boundExpected: Status shows bound with valid address and gateway.
Check 2: Verify Default Route
Section titled “Check 2: Verify Default Route”/ip route print where dst-address=0.0.0.0/0 gateway-status~"reachable"Expected: Active route with reachable gateway.
Check 3: Verify DNS (if use-peer-dns=yes)
Section titled “Check 3: Verify DNS (if use-peer-dns=yes)”/ip dns printExpected: dynamic=yes with servers matching DHCP-provided values.
Check 4: Test Connectivity
Section titled “Check 4: Test Connectivity”/tool ping 8.8.8.8 count=3Expected: 3 packets transmitted, 3 received.
Troubleshooting
Section titled “Troubleshooting”| Symptom | Cause | Solution |
|---|---|---|
| Status stuck on “searching” | No DHCP server responding | Verify physical connection; check if ISP requires specific options |
| Status stuck on “searching” | ISP hostname bug | Try changing hostname: /ip dhcp-client set 0 host-name="router" |
| Status stuck on “searching” | RouterOS 7.3.0+ option ordering | Add Option 57 (see Community Tips below) |
| Default route shows “invalid” | Conflicting static route exists | Remove static default route or adjust distances |
| Multiple default routes | Multiple DHCP clients with same distance | Set different default-route-distance values |
| DNS not updating | IPv6 also providing DNS | Set use-peer-dns=no on IPv6 DHCP client too |
| Bridge not getting IP | No physical port in bridge | Ensure at least one active port in bridge |
| Can’t edit LTE DHCP client | LTE creates dynamic client | Configure via /interface lte apn instead |
Common Mistakes
- Don’t configure static IP on the same interface - DHCP client and static IP conflict
- Don’t forget route distances in multi-WAN - Without different distances, routes will conflict
- Don’t expect firewall to block rogue DHCP - IP firewall does NOT apply to DHCP client traffic; use bridge filtering if needed
- Remember Option 121 precedence - Classless static routes (Option 121) override the default gateway (Option 3) per RFC 3442
DHCP Client Status Reference
Section titled “DHCP Client Status Reference”| Status | Description |
|---|---|
bound | Lease acquired successfully, client has valid IP |
searching | Sending DHCPDISCOVER, waiting for server offers |
requesting | Sent DHCPREQUEST, waiting for acknowledgment |
rebinding | Lease expiring, trying to extend with any server |
stopped | Client is disabled or stopped |
error | Error occurred during DHCP process |
Related Topics
Section titled “Related Topics”Prerequisites
Section titled “Prerequisites”- IP Address Configuration - understand static IP assignment (DHCP client is the alternative)
Related DHCP Topics
Section titled “Related DHCP Topics”- DHCP Server - configure your router as a DHCP server for downstream clients
- DHCP Relay - forward DHCP requests across network segments
- IP Pools - address pool management for DHCP servers
Next Steps
Section titled “Next Steps”- Static Routes - manual routing configuration
- NAT Masquerade - enable internet sharing for LAN devices
- DNS Server - local DNS configuration
IPv6 Alternative
Section titled “IPv6 Alternative”- DHCPv6 Client - IPv6 DHCP client with prefix delegation
Reference
Section titled “Reference”- MikroTik DHCP Documentation
- Version changes:
- v7.0: Added
default-route-tablesfor VRF,check-gateway=bgd - v6.43: Added
special-classlessforadd-default-route
- v7.0: Added
DHCP Options Requested
Section titled “DHCP Options Requested”RouterOS DHCP client automatically requests these options from the server:
| Option | Name | Purpose |
|---|---|---|
| 1 | Subnet Mask | Network mask for assigned address |
| 3 | Gateway List | Default gateway addresses |
| 6 | DNS Server List | DNS resolver addresses |
| 33 | Static Routes | Classful static routes |
| 42 | NTP Server List | Time server addresses |
| 43 | Vendor Specific | Vendor-specific information |
| 121 | Classless Static Routes | CIDR routes (takes precedence over Option 3 per RFC 3442) |
| 138 | CAPWAP AC Addresses | Controller addresses for CAPsMAN |
Key Properties Reference
Section titled “Key Properties Reference”| Property | Type | Default | Description |
|---|---|---|---|
interface | string | - | Interface for DHCP client (required) |
disabled | yes/no | yes | Whether client is disabled |
add-default-route | yes/no/special-classless | yes | Install default route from DHCP |
use-peer-dns | yes/no | yes | Accept DNS servers from DHCP |
use-peer-ntp | yes/no | yes | Accept NTP servers from DHCP |
default-route-distance | 0-255 | 1 | Administrative distance for default route |
host-name | string | system identity | Hostname sent to DHCP server |
client-id | string | MAC address | Custom client identifier |
check-gateway | none/arp/ping/bgd | none | Gateway reachability check method |
script | script | - | Script executed on lease events |