Static DHCP

From DD-WRT Wiki

Jump to: navigation, search


[edit] Introduction

Static DHCP (aka DHCP reservation) is a useful feature which makes the DHCP server on your router always assign the same IP address to a specific computer on your LAN. To be more specific, the DHCP server assigns this static IP to a unique MAC address assigned to each NIC on your LAN. Your computer boots and requests its IP from the router's DHCP server. The DHCP server recognizes the MAC address of your device's NIC and assigns the static IP address to it. (Note also that, currently, each reserved IP address must also be unique. Therefore, e.g., one cannot reserve the same IP address for both the wired and wireless interfaces of a device, even though the device may be configured such that only one interface is active at any given time.)

Static DHCP will be needed if you want an interface to always have the same IP address. Sometimes required for certain programs, this feature is useful if other people on your LAN know your IP and access your PC using this IP. Static DHCP should be used in conjuction with Port Forwarding. If you forward an external WAN TCP/UDP port to a port on a server running inside your LAN, you have to give that server a static IP, and this can be achieved easily through Static DHCP.

v23 Port Forwarding section in the Web GUI

[edit] Configuration

  1. Log into the DD-WRT Web GUI
  2. Go to the Services tab
  3. DHCP Daemon should be enabled
  4. If there is no blank slot under "Static Leases", click Add
  5. Enter the MAC address of the client interface, the hostname of the machine, and the desired IP address for this machine. Note that you cannot reserve the same IP address for two different MAC addresses (e.g. both the wired and wireless interfaces of a device).
  6. Scroll to the bottom of the page and save your changes.

Note: You must either Save or Apply the page each time you've added and filled out a new static lease. Clicking the Add button refreshes the page without saving what you entered. If you try to add multiple blank leases and fill them all out at once then you will encounter a bug that the GUI thinks they are duplicate entries.

Note: A blank lease duration means it will be an infinite lease (never expires). Setting a lease duration will allow you to change the static lease information later on and have the host automatically get the new information without having to manually release/renew the lease on the host.

[edit] DHCP Options

The DHCP system assigns IP addresses to your local devices. While the main configuration is on the setup page you can program some nifty special functions here.

DHCP Daemon: Disabling here will disable DHCP on this router irrespective of the settings on the Setup screen.

Used domain: You can select here which domain the DHCP clients should get as their local domain. This can be the WAN domain set on the Setup screen or the LAN domain which can be set here.

LAN Domain: You can define here your local LAN domain which is used as local domain for DNSmasq and DHCP service if chosen above.

Static Leases: Assign certain hosts specific addresses here. This is also a way to add hosts to the router's local DNS service (DNSmasq).

Note: It is recommended but not necessary to set your static leases outside of your automatic DHCP address range.
This range is by default and can be configured under Setup -> Basic Setup : Network Address Server Settings (DHCP).

[edit] Example

To assign the IP address and the hostname "mypc" to a PC with a network card having the MAC address 00:AE:0D:FF:BE:56 you should press Add then enter 00:AE:0D:FF:BE:56 into the MAC field, mypc into the HOST field and into the IP field.

Remember: If you press the 'Add' button before saving the entries you just made, they will be cleared. This is normal behavior.

[edit] How to add static leases into dhcp by command

nvram set static_leasenum=X (where X is the total number of static leases)
nvram set static_leases="00:11:22:33:44:55=name1=IP-Address1 00:11:22:33:44:56=name2=IP-Address2"

If more than two...just keep adding them to the static_leases variable with a space between each.

Don't forget the double quotes...if you have any spaces (more than one lease) you must include the quotes to the variable.


NOTE: Starting with build 13832 the format has changed to the following:

nvram set static_leasenum=X (where X is the total number of static leases)
nvram set static_leases="00:11:22:33:44:55=name1=IP-Address1= 00:11:22:33:44:56=name2=IP-Address2= "


nvram set static_leases="00:11:22:33:44:55=name1=IP-Address1= 00:11:22:33:44:56=name2=IP-Address2=1440"
Edited to work with revision. (when edited 21676)(by Jackykoning)

current build require enter/return between each line to pick up the command(instead of the space).
the " is important!

nvram set static_leasenum=X (where X is the total number of static leases)
nvram set static_leases="
00:11:22:33:44:58=name2=IP-Address4= "

Note the '=' sign at the end of each lease. If you want to set static lease time then put a number after the last '=' to set time in the second cases above a blank after the = sign means its an indefinite lease, 1440=24 hours.

If you have success setting a couple of entries, but have difficulty setting lots of entries, then you may be encountering a length limitation for your given method and firmware combination. A workaround for this is to ssh or telnet to the router and enter it there. If you still run into a length problem then you could use vi (or other method) to enter your configuration into a file and then run the file. Here is what I saved into a file and ran with success (I needed single quotes instead of double quotes in my case):

 nvram set static_leasenum='15';
 nvram set static_leases='mac1=name1=ip1 mac2=name2=ip2 ...';

I then ran the file (which is named like so:


Also remember tools such as "nvram show | grep static" as well as "nvram commit".

[edit] Troubleshooting

If you cannot ping a hostname, append a period to the end. I.e. instead of "ping server" try "ping server."

If the static reservations are visible, but your machines continue to get a normal DHCP IP try going to the Setup page. Hit Save and then Apply settings. The DHCP daemon should restart and you may lose connection briefly. Try renewing your DHCP lease and you should be getting the correct IP at this point.