DNSMasq as DHCP server

From DD-WRT Wiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 15:22, 21 February 2009 (edit)
TinkerJ (Talk | contribs)
(Update for v24 standard)
← Previous diff
Revision as of 15:25, 21 February 2009 (edit) (undo)
TinkerJ (Talk | contribs)
m (Administration->management tab no longer has field for DNSMasq configuration)
Next diff →
Line 69: Line 69:
[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. --[[User:Wishyou|Wishyou]] 22:57, 19 June 2008 (CEST) ] [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. --[[User:Wishyou|Wishyou]] 22:57, 19 June 2008 (CEST) ]
-=Extra DNSMasq options=+==Extra DNSMasq options==
-There are some extra options you can set by entering them in '''Additional DNS 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.
-If you are using the Web-Admin method then you can enter additional options in the Administration/Management tab under '''Additional DHCPD Options'''+===ISP DNS-Servers===
- +
-==ISP DNS-Servers==+
If you wish to pass through the DNS servers from your ISP, you can use the following parameters: If you wish to pass through the DNS servers from your ISP, you can use the following parameters:
<pre> <pre>
Line 82: Line 80:
y.y.y.y = DNS2</pre> y.y.y.y = DNS2</pre>
-==Assign an alternate Gateway==+===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: By default, dd-wrt will hand out via DHCP its own IP as the Gateway. You can specify an alternate one like so:
dhcp-option=3,x.y.z.w dhcp-option=3,x.y.z.w
-==Denying DHCP service to specific MAC addresses==+===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 You can ignore requests from specific MAC addresses, so that no IP address will be leased to those specific MAC addresses/machines
<pre> <pre>
Line 94: Line 92:
11:22:33:44:55:66 = MAC address of the machine you wish to ignore</pre> 11:22:33:44:55:66 = MAC address of the machine you wish to ignore</pre>
-==Enable TFTP server==+===Enable TFTP server===
You can start a tftp server serving files from "/opt/tftpboot" You can start a tftp server serving files from "/opt/tftpboot"
<pre> <pre>
Line 100: Line 98:
tftp-root=/opt/tftpboot</pre> tftp-root=/opt/tftpboot</pre>
-==Disable NetBIOS over TCP/IP==+===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: 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:
<pre> <pre>

Revision as of 15:25, 21 February 2009

DD-WRT supports using DNSMasq "as local DNS server" and also uses the DHCP service "udhcpd". This is a waste of RAM (router has 16MB total and only 3MB free). With DNSMasq as the sole DHCP server you can save 300kB (udhcpd deactivated!). With this savings you can create one more PPTP tunnel with the inserted PPTPD server.

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 accomplish this

  • Using the Web-Interface (for beginners who want to use the default options)
  • 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

Contents

Configuration

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.


Image:Local_DNS_Config_DNSMasq_Options_Leases.png

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:
   dhcp-range=192.168.1.100,192.168.1.150,255.255.255.0,24h 
 * To setup machines to have a Static IP assigned by the router, add either:
   dhcp-host=AB:CD:EF:11:22:33,192.168.1.10,24h
   or
   dhcp-host=computername,192.168.1.10,24h

AB:CD:EF:11:22:33 is the MAC of the network, computername is the NetBIOS name of the computer on the network, 192.168.1.10 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:

no-hosts
addn-hosts=/tmp/hosts 

You must also add this computer to /tmp/hosts:

192.168.0.5 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:

dhcp-option=6,x.x.x.x,y.y.y.y

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:

dhcp-option=3,x.y.z.w

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

dhcp-host=11:22:33:44:55:66,ignore

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"

enable-tftp
tftp-root=/opt/tftpboot

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:

dhcp-option=43,01:04:00:00:00:02

Troubleshooting

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

References

http://blog.ptch.de/index.php?/archives/33-WRT54G-DNSMasq-als-DHCPD.html