DNSMasq as DHCP server

From DD-WRT Wiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 15:36, 21 February 2009 (edit)
TinkerJ (Talk | contribs)
m (Formatting changes, make intro more concise)
← Previous diff
Revision as of 14:53, 1 May 2009 (edit) (undo)
Soulstace (Talk | contribs)
m (Extra DNSMasq options - a related but different solution for assigning an alternate gateway)
Next diff →
Line 87: Line 87:
dhcp-option=3,x.y.z.w dhcp-option=3,x.y.z.w
 +A related but different solution is to create a DHCP setting that gives a static IP address to a certain MAC, but with a different Gateway address than the rest.
 + dhcp-range=net:2,,,static
 + dhcp-option=net:2,3,
 +Then use:
 + dhcp-host=<hwaddr>, net:2, <ipaddr>
 +[http://www.dd-wrt.com/phpBB2/viewtopic.php?t=51267 click here for more details...]
===Denying DHCP service to specific MAC addresses=== ===Denying DHCP service to specific MAC addresses===

Revision as of 14:53, 1 May 2009

DD-WRT supports using DNSMasq as a local DNS server and can also support using replacement of the standard DD-WRT DHCP service "udhcpd". uDHCPd uses more RAM than DNSMasq.

Using DNSMasq as the sole DHCP server can save you 300kB. With this savings you can create one more PPTP tunnels with the inserted PPTPD server.

An added advantage is that DNSMasq can intelligently add DHCP leases to its DNS database, providing local name lookups for any DHCP client, static or dynamic.

udhcpd, a DHCP server (daemon), is not to be confused with udhcpc, the DHCP client. Most setups require that the router run udhcpc to acquire DHCP leases for the WAN interface.

There are two ways to configure DNSMasq to take over the

  • Using the Web-Interface (most options are configurable here)
  • Using DNSMasq parameters (for advanced users who can understand dnsmasq.conf file layout, and know where to find the manual page for it)

You can NOT use both



Using Web-Admin

This is the easiest way to setup DNSMasq as DHCP Server

  • Go to your Web-Interface and log in
  • Go to Setup->Basic Setup
    • Make sure that
      • DHCP Type = DHCP Server
      • DHCP Server = Enable
      • Use DNSMasq for DHCP = Checked
      • Use DNSMasq for DNS = Checked

Image:DHCP Using DNSMasq Basic Settings.png

Make sure that the maximum number of DHCP leases that you set is appropriate for your netmask; otherwise, DNSMasq will not start.

  • Go to Administration->Services
    • Make sure that
      • LAN Domain = <chosen LAN domain>
      • DNSMasq = Enabled
      • Local DNS = Enabled
      • Additional DNSMasq Options = Add your domain as a local search domain, add expand-hosts option. See screenshot.
  • You can add static allocations the same way as when you're using DHCPd. These settings should end up in /tmp/dnsmasq.conf.


DNSMasq DHCP Parameters

As of v24, DNSMasq respects the settings of the DHCP server on the "Setup" page and static leases set on the "Services" page

Old Way

This provides access to more functionality at the expense of not being able to use the structured web interface.

Following steps are necessary:

  • Deactivate the DHCPD service on the "Setup" page.

[Comment: above step deactivated all DHCP for me and wasn't needed anyway - andmalc 4/2008]

  • Under the "Administration" tab in the "Services" sub tab, you will find a "DNSMasq" section. Under "Additional DNS Options", you need to set some parameters.
 * To setup the default options for Dynamic IP Allocation, add:
 * To setup machines to have a Static IP assigned by the router, add either:

AB:CD:EF:11:22:33 is the MAC of the network, computername is the NetBIOS name of the computer on the network, indicates the desired IP, and finally 24h the DHCP lease of 24 hours, however if you wish to have the lease for the machine never expire, you may do so by changing 24h to infinite.

If it's not possible to assign an IP with DNSMasq and you want to identify devices via name resolution, you must add the following lines:


You must also add this computer to /tmp/hosts: printers drucker.lan

[Comment: In v23-SP2 (and possibly other versions) /etc/hosts is simply a softlink to /tmp/hosts. To get the last part to work you need to remove the no-hosts part and specify a separate hosts file for the static assignments. --Wishyou 22:57, 19 June 2008 (CEST) ]

Extra DNSMasq options

There are some extra options in the web interface for DNSMasq that you can set by entering them in Additional DNSMasq Options on the "Services" tab.

ISP DNS-Servers

If you wish to pass through the DNS servers from your ISP, you can use the following parameters:


x.x.x.x = DNS1
y.y.y.y = DNS2

Assign an alternate Gateway

By default, dd-wrt will hand out via DHCP its own IP as the Gateway. You can specify an alternate one like so:


A related but different solution is to create a DHCP setting that gives a static IP address to a certain MAC, but with a different Gateway address than the rest.


Then use:

dhcp-host=<hwaddr>, net:2, <ipaddr>

click here for more details...

Denying DHCP service to specific MAC addresses

You can ignore requests from specific MAC addresses, so that no IP address will be leased to those specific MAC addresses/machines


11:22:33:44:55:66 = MAC address of the machine you wish to ignore

Enable TFTP server

You can start a tftp server serving files from "/opt/tftpboot". This may prove useful for upgrading firmwares for embedded devices.


Disable NetBIOS over TCP/IP

Since DNSMasq acting as a local DNS server suitably takes care of host name resolution, disabling NetBT on appropriately configured Microsoft DHCP clients, such as Windows 2000 and XP, can be accomplished with the following:



It's possible to verify that the options you set in the web interface match those being passed to DNSMasq. telnet to your router's IP address and log in as root with your usual password. Then:

cat /tmp/dnsmasq.conf

The options should match the command-line format specified in the DNSMasq man page.

You should also make sure that DNSMasq is running at all. To do so, while in telnet issue

ps | grep dnsmasq

The output should look like:

  144 root       772 S    dnsmasq --conf-file=/tmp/dnsmasq.conf 
 2966 root       508 S    grep masq

If the first line is missing, DNSMasq isn't running and may have been unable to start due to one of its options being set incorrectly.

External Links

http://www.faqs.org/rfcs/rfc2132.html Options on MAC addresses