Differences

This shows you the differences between two versions of the page.

doc:uci:dhcp [2013/03/23 07:44]
nilfred add dhpc host ip ignore
doc:uci:dhcp [2014/10/10 11:27] (current)
hashken Changed odhcpd to dhcp
Line 1: Line 1:
====== DNS and DHCP configuration ====== ====== DNS and DHCP configuration ======
-The //dnsmasq// configuration is located in ''/etc/config/dhcp'' and controls both DNS and DHCP server options on the device.+The //dnsmasq// and dhcpd configuration is located in ''/etc/config/dhcp'' and controls both DNS and DHCP server options on the device (both DHCP and DNS services are implemented using the same OpenWrt program, dnsmasq). 
In the default configuration this file contains one //common section// to specify DNS and daemon related options and one or more //DHCP pools// to define DHCP serving on network interfaces. In the default configuration this file contains one //common section// to specify DNS and daemon related options and one or more //DHCP pools// to define DHCP serving on network interfaces.
Line 36: Line 37:
  * Option ''leasefile'' stores the leases in a file, so that they can be picked up again if //dnsmasq// is restarted.   * Option ''leasefile'' stores the leases in a file, so that they can be picked up again if //dnsmasq// is restarted.
  * Option ''resolvfile'' tells //dnsmasq// to use this file to find upstream name servers; it gets created by the WAN DHCP client or the PPP client.   * Option ''resolvfile'' tells //dnsmasq// to use this file to find upstream name servers; it gets created by the WAN DHCP client or the PPP client.
 +  * Options "enable_tftp" and "tftp_root" turn on the TFTP server and serve files from tftp_root.  You may need to set the server's IP on the client.  On the client,  change it by setting "serverip" (e.g. "setenv serverip 192.168.1.10").
 +==== All Options ====
<sortable> <sortable>
^ Name ^ Type ^ Default ^ Option ^ Description ^ ^ Name ^ Type ^ Default ^ Option ^ Description ^
Line 54: Line 57:
| ''domain'' | domain name | //(none)// | ''-s'' | DNS domain handed out to DHCP clients | | ''domain'' | domain name | //(none)// | ''-s'' | DNS domain handed out to DHCP clients |
| ''domainneeded'' | boolean | ''0'' | ''-D'' | Tells //dnsmasq// never to forward queries for plain names, without dots or domain parts, to upstream nameservers. If the name is not known from /etc/hosts or DHCP then a "not found" answer is returned | | ''domainneeded'' | boolean | ''0'' | ''-D'' | Tells //dnsmasq// never to forward queries for plain names, without dots or domain parts, to upstream nameservers. If the name is not known from /etc/hosts or DHCP then a "not found" answer is returned |
 +| ''dnssec'' | boolean | ''0'' | <code>--dnssec</code> | Validate DNS replies and cache DNSSEC data.\\ :!: Requires the //dnsmasq-full// package. |
 +| ''dnsseccheckunsigned'' | boolean | ''0'' | <code>--dnssec-check-unsigned</code> | Check the zones of unsigned replies to ensure that unsigned replies are allowed in those zones. This protects against an attacker forging unsigned replies for signed DNS zones, but is slower and requires that the nameservers upstream of //dnsmasq// are DNSSEC-capable.\\ :!: Requires the //dnsmasq-full// package. |
| ''ednspacket_max'' | integer | ''1280'' | ''-P'' | Specify the largest EDNS.0 UDP packet which is supported by the DNS forwarder | | ''ednspacket_max'' | integer | ''1280'' | ''-P'' | Specify the largest EDNS.0 UDP packet which is supported by the DNS forwarder |
| ''enable_tftp'' | boolean | ''0'' | <code>--enable-tftp</code> | Enable the builtin TFTP server | | ''enable_tftp'' | boolean | ''0'' | <code>--enable-tftp</code> | Enable the builtin TFTP server |
Line 73: Line 78:
| ''queryport'' | integer | //(none)// | ''-Q'' | Use a fixed port for outbound DNS queries | | ''queryport'' | integer | //(none)// | ''-Q'' | Use a fixed port for outbound DNS queries |
| ''readethers'' | boolean | ''0'' | ''-Z'' | Read static lease entries from ''/etc/ethers'', re-read on SIGHUP | | ''readethers'' | boolean | ''0'' | ''-Z'' | Read static lease entries from ''/etc/ethers'', re-read on SIGHUP |
 +| ''rebind_protection'' | boolean | ''1'' | <code>--stop-dns-rebind</code> | Enables DNS rebind attack protection by discarding upstream RFC1918 responses |
 +| ''rebind_localhost'' | boolean | ''0'' | <code>--rebind-localhost-ok</code> | Allows upstream 127.0.0.0/8 responses, required for DNS based blacklist services, only takes effect if rebind protection is enabled |
 +| ''rebind_domain'' | list of domain names | //(none)// | <code>--rebind-domain-ok</code> | List of domains to allow RFC1918 responses for, only takes effect if rebind protection is enabled |
| ''resolvfile'' | file path | ''/etc/resolv.conf'' | ''-r'' | Specifies an alternative resolv file | | ''resolvfile'' | file path | ''/etc/resolv.conf'' | ''-r'' | Specifies an alternative resolv file |
| ''server'' | list of strings | //(none)// | ''-S'' | List of DNS servers to forward requests to. See the //dnsmasq// man page for syntax details. | | ''server'' | list of strings | //(none)// | ''-S'' | List of DNS servers to forward requests to. See the //dnsmasq// man page for syntax details. |
| ''strictorder'' | boolean | ''0'' | ''-o'' | Obey order of DNS servers in ''/etc/resolv.conf'' | | ''strictorder'' | boolean | ''0'' | ''-o'' | Obey order of DNS servers in ''/etc/resolv.conf'' |
-| ''tftp_root'' | directory path | //(none)// | --tftp-root | Specifies the TFTP root directory +| ''tftp_root'' | directory path | //(none)// | <code>--tftp-root</code> | Specifies the TFTP root directory |
-| ''rebind_protection'' | boolean | ''1'' | --stop-dns-rebind | Enables DNS rebind attack protection by discarding upstream RFC1918 responses | +
-| ''rebind_localhost'' | boolean | ''0'' |--rebind-localhost-ok| Allows upstream 127.0.0.0/8 responses, required for DNS based blacklist services, only takes effect if rebind protection is enabled | +
-| ''rebind_domain'' | list of domain names | //(none)// | --rebind-domain-ok | List of domains to allow RFC1918 responses for, only takes effect if rebind protection is enabled |+
</sortable> </sortable>
Line 95: Line 100:
option 'start'      '100' option 'start'      '100'
option 'limit'     '150' option 'limit'     '150'
- option 'leasetime'  '12h'</code>+ option 'leasetime'  '12h' 
 +        option ra server 
 +        option dhcpv6 server</code>
  * ''lan'' specifies the OpenWrt interface that is served by this DHCP pool   * ''lan'' specifies the OpenWrt interface that is served by this DHCP pool
Line 101: Line 108:
  * ''150'' is the maximum number of addresses that may be leased, in the default configuration ''192.168.1.250''   * ''150'' is the maximum number of addresses that may be leased, in the default configuration ''192.168.1.250''
  * ''12h'' specifies the time to live for handed out leases, twelve hours in this example   * ''12h'' specifies the time to live for handed out leases, twelve hours in this example
 +  * ''server'' defines the mode for IPv6 configuration (RA & DHCPv6)
Below is a listing of legal options for ''dhcp'' sections. Below is a listing of legal options for ''dhcp'' sections.
Line 106: Line 114:
<sortable> <sortable>
^ Name ^ Type ^ Required ^ Default ^ Description ^ ^ Name ^ Type ^ Required ^ Default ^ Description ^
-| ''dhcp_option'' | list of strings | no | //(none)// | Additional options to be added for this //network-id//. For example with '26,1470' or 'option:mtu, 1470' you can assign an MTU per DHCP. Your client must accept MTU by DHCP for this to work |+| ''dhcp_option'' | list of strings | no | //(none)// | The ID dhcp_option here must be with written with an underscore. OpenWrt will translate this to --dhcp-option, with a hyphen, as ultimately used by dnsmasq. Multiple option values can be given for this //network-id//, with a a space between them and the total string between "". E.g. '26,1470' or 'option:mtu, 1470' that can assign an MTU per DHCP. Your client must accept MTU by DHCP for this to work. Or "3,192.168.1.1 6,192.168.1.1" to give out gateway and dns server addresses. |
| ''dynamicdhcp'' | boolean | no | ''1'' | Dynamically allocate client addresses, if set to ''0'' only clients present in the ''ethers'' files are served | | ''dynamicdhcp'' | boolean | no | ''1'' | Dynamically allocate client addresses, if set to ''0'' only clients present in the ''ethers'' files are served |
| ''force'' | boolean | no | ''0'' | Forces DHCP serving on the specified interface even if another DHCP server is detected on the same network segment | | ''force'' | boolean | no | ''0'' | Forces DHCP serving on the specified interface even if another DHCP server is detected on the same network segment |
| ''ignore'' | boolean | no | ''0'' | Specifies whether //dnsmasq// should ignore this pool if set to ''1'' | | ''ignore'' | boolean | no | ''0'' | Specifies whether //dnsmasq// should ignore this pool if set to ''1'' |
-| ''interface'' | logical interface name | yes | //(none)// | Specifies the interface associated with this DHCP address pool; must be one of the interfaces defined in ''/etc/config/network'' |+| ''dhcpv6'' | string | no | ''none'' | Specifies whether DHCPv6 server should be enabled (''server''), relayed (''relay'') or disabled (''disabled'') | 
 +| ''ra'' | string | no | ''none'' | Specifies whether Router Advertisements should be enabled (''server''), relayed (''relay'') or disabled (''disabled'') | 
 +| ''ndp'' | string | no | ''none'' | Specifies whether NDP should be relayed ''relay'' or disabled ''none'' | 
 +| ''master'' | boolean | no | 0 | Specifies whether DHCPv6, RA and NDP in relay mode is a master interface or not. | 
 +| ''interface'' | logical interface name | yes | //(none)// | Specifies the interface associated with this DHCP address pool; must be one of the interfaces defined in ''/etc/config/network''.|
| ''leasetime'' | string | yes | ''12h'' | Specifies the lease time of addresses handed out to clients, for example ''12h'' or ''30m'' | | ''leasetime'' | string | yes | ''12h'' | Specifies the lease time of addresses handed out to clients, for example ''12h'' or ''30m'' |
| ''limit'' | integer | yes | ''150'' | Specifies the maximum allowable address that may be leased to clients, calculated as network address + "start" + "limit". :!: The maximum number of leased addresses is limit+1 | | ''limit'' | integer | yes | ''150'' | Specifies the maximum allowable address that may be leased to clients, calculated as network address + "start" + "limit". :!: The maximum number of leased addresses is limit+1 |
-| ''networkid'' | string | no | //(value of ''interface'')// | Assigns a //network-id// to all clients that obtain an IP address from this pool. |+| ''networkid'' | string | no | //(value of ''interface'')// | The dhcp functionality defined in the dhcp section is limited to the interface indicated here through its //network-id//. In case omitted the system tries to know the network-id via the 'interface' setting in this dhcp section, through consultation of /etc/config/network. Some IDs get assigned dynamically, are not provided by network, but still can be set here. |
| ''start'' | integer | yes | ''100'' | Specifies the offset from the network address of the underlying interface to calculate the minimum address that may be leased to clients. It may be greater than 255 to span subnets.| | ''start'' | integer | yes | ''100'' | Specifies the offset from the network address of the underlying interface to calculate the minimum address that may be leased to clients. It may be greater than 255 to span subnets.|
</sortable> </sortable>
 +
 +Notes:
 +  * Although called 'interface', this is the network name, i.e. lan, wan, wifi etc. (section names in /etc/config/network), NOT the interface name used internally, like eth0, eth1, wlan0 etc. (the 'ifname' IDs in /etc/config/network).
 +  * Although called 'networkid', this is the interface name used internally, i.e. eth0, eth1, wlan0 etc., not the network name (lan, wan, wifi etc.).
 +This departs from 'ifname' and 'network' as used in /etc/config/network and in /etc/config/wireless, so double check!
==== Static Leases ==== ==== Static Leases ====
Line 128: Line 145:
        option name    'mypc'         option name    'mypc'
</code> </code>
-This adds the fixed IP address 192.168.1.2 and the name "mypc" for a machine with the (Ethernet) hardware address 00:11:22:33:44:55+This adds the fixed IP address 192.168.1.2 and the name "mypc" for a machine with the (Ethernet) hardware address 00:11:22:33:44:55
 + 
 +<code>config host 
 +        option ip      '192.168.1.3' 
 +        option mac      '11:22:33:44:55:66,aa:bb:cc:dd:ee:ff' 
 +        option name    'mylaptop' 
 +</code> 
 +This adds the fixed IP address 192.168.1.3 and the name "mylaptop" for a machine with the (Ethernet) hardware address 11:22:33:44:55:66 or aa:bb:cc:dd:ee:ff. Note that this is **unreliable** if more than one of the listed mac addresses is on the network simultaneously. It's useful for cases such as a laptop with both wireless and wired interfaces, provided that only one will be active at a given time.
^ Name ^ Type ^ Required ^ Default ^ Description ^ ^ Name ^ Type ^ Required ^ Default ^ Description ^
| ''ip'' | string | yes | //(none)// | 'ignore' or the IP address to be used for this host. | | ''ip'' | string | yes | //(none)// | 'ignore' or the IP address to be used for this host. |
-| ''mac'' | string | no | //(none)// | The hardware address of this host. |+| ''mac'' | string | no | //(none)// | The hardware address(es) of this host, separated by commas. | 
 +| ''hostid'' | string | no | //(none)// | The IPv6 interface identifier (address suffix) as hexadecimal number (max. 8 chars) | 
 +| ''duid'' | string | no | //(none)// | The DHCPv6-DUID of this host. |
| ''name'' | string | no | //(none)// | Optional hostname to assign. | | ''name'' | string | no | //(none)// | Optional hostname to assign. |
 +| ''tag'' | string | no | //(none)// | Set the given tag for matching hosts. | 
 +| ''dns'' | boolean | no | ''0'' | Add static forward and reverse DNS entries for this host. | 
 +| ''broadcast'' | boolean | no | ''0'' | Force broadcast DHCP response. |
As well as adding ''host'' sections, you can also enable the ''dnsmasq'' section option ''readethers'', and add entries to the ''/etc/ethers'' file. As well as adding ''host'' sections, you can also enable the ''dnsmasq'' section option ''readethers'', and add entries to the ''/etc/ethers'' file.
Line 195: Line 223:
| ''remoteid''  | Matches the remote ID as sent by the relay agent, as defined in RFC3046. | | ''remoteid''  | Matches the remote ID as sent by the relay agent, as defined in RFC3046. |
| ''subscrid''  | Matches the subscriber ID as sent by the relay agent, as defined in RFC3993. | | ''subscrid''  | Matches the subscriber ID as sent by the relay agent, as defined in RFC3993. |
 +
 +
 +An example using the 'mac' classifier to create a tagged network for openvpn would look like this in the config file:
 +<code>
 +config mac 'opnvpn'
 +        option mac  '00:FF:*:*:*:*'
 +        option networkid  'opnvpn'
 +        list  dhcp_option '3'
 +</code>
 +
 +
 +And like this in UCI
 +<code>
 +dhcp.opnvpn=mac
 +dhcp.opnvpn.mac=00:FF:*:*:*:*
 +dhcp.opnvpn.networkid=opnvpn
 +dhcp.opnvpn.dhcp_option=3
 +</code>
//DHCP-option// adds a DHCP option for this //network-id//. See the //dnsmsq// man page for a complete explanation of the syntax of the ''-O'' option. //DHCP-option// adds a DHCP option for this //network-id//. See the //dnsmsq// man page for a complete explanation of the syntax of the ''-O'' option.
Line 208: Line 254:
<code>dhcp-script=/sbin/action.sh</code> <code>dhcp-script=/sbin/action.sh</code>
 +
 +==== DNS and DHCP Ports ====
 +DNS needs TCP and UDP port 53 open on the firewall.  DHCP needs UDP ports 67 and 68 open from your zone to/from the firewall.  See http://wiki.openwrt.org/doc/recipes/guest-wlan and http://www.thekelleys.org.uk/dnsmasq/docs/dnsmasq-man.html (viz "--dhcp-alternate-port") for more information.
===== Examples ===== ===== Examples =====
Line 221: Line 270:
=== Troubleshooting === === Troubleshooting ===
-:!: **Windows 7** has bringed new //Microsoft-enhanced// feature. It won't assign IP address obtained from DHCP server to an interface, if the IP was used before for another interface, despite the another interface is **NOT** active currently (i.e. cable is out). This behaviour is unique and was not reported for older Windows versions, Mac OS nor Linux.+:!: **Windows 7** has introduced a new //Microsoft-enhanced// feature. It won't assign IP address obtained from a DHCP server to an interface, if the IP was used before for another interface, even if that other interface is **NOT** active currently (i.e. cable disconnected). This behaviour is unique and was not reported for older Windows versions, Mac OS nor Linux.
-If you try configure MAC address hot swap on your router, Windows 7 clients will end up in infinite [[http://tools.ietf.org/html/rfc1531#section-3.1|DORA]] loop.+If you try configure MAC address hot swap on your router, Windows 7 clients will end up in an infinite [[http://tools.ietf.org/html/rfc1531#section-3.1|DORA]] loop.
Solution: Solution:
-  - Create bridge from wireless and ethernet interface on your client +  - Create a bridge from the wireless and ethernet interfaces on your client 
-    * its trivial, [[googe>windows 7 create bridge|google it]] +    * it's trivial: [[googe>windows 7 create bridge|google it]] 
-    * you will have to add MAC address of the bridge to ''/etc/config/dhcp''+    * you will have to add the MAC address of the bridge to ''/etc/config/dhcp''
      * <code>config 'host'       * <code>config 'host'
option 'name' 'example-host' option 'name' 'example-host'
option 'ip'  '192.168.1.230' option 'ip'  '192.168.1.230'
option 'mac'  '00:a0:24:5a:33:69 00:11:22:33:44:55 02:a0:24:5a:33:69 02:11:22:33:44:55'</code> option 'mac'  '00:a0:24:5a:33:69 00:11:22:33:44:55 02:a0:24:5a:33:69 02:11:22:33:44:55'</code>
-    * Since the bridge will probably take and alter your ethernet MAC address, you will loose SLAAC on wifi interface, making your laptop IPv6-disabled when only wireless is up. +    * Since the bridge will probably take and alter your ethernet MAC address, you will lose SLAAC on wifi interface, making your laptop IPv6-disabled when only wireless is up. 
-  - Another solution is IPv6 friendly, but it involves user interaction, but you dont need to create network bridge nor add MAC address to dnsmasq config file. +  - Another solution is IPv6 friendly, you don't need to create a bridge, nor add MAC address to dnsmasq config file, but it involves user interaction: 
-    * When you plug-in ethernet cable, disable wireless interface in control panel (power off wireless won't do it). +    * When you plug the ethernet cable in, disable wireless interface in control panel (power off wireless won't do it).
    * When you unplug ethernet cable, enable wireless and disable ethernet.     * When you unplug ethernet cable, enable wireless and disable ethernet.
-    * Its not that painful if you don't have to do it every day. 
Notes: Notes:
Line 247: Line 295:
:!: Note that this currently only works for IPv4 addresses and that this functionality is not present in release prior to 8.09.2 . :!: Note that this currently only works for IPv4 addresses and that this functionality is not present in release prior to 8.09.2 .
 +
 +:!: Note that reverse records are not properly generated at present. (Barrier Breaker 14.07-RC2)
<code>config 'domain' <code>config 'domain'
Line 358: Line 408:
root@OpenWrt:~# root@OpenWrt:~#
</code> </code>
 +
 +==== Classifying Clients And Assigning Individual Options ====
 +
 +Assign different dhcp-options to a single MAC address:
 +<code bash>
 +uci batch <<'EOF'
 +add dhcp mac
 +set dhcp.@mac[-1].mac=00:11:22:33:44:55
 +set dhcp.@mac[-1].networkid=someone
 +add_list dhcp.@mac[-1].dhcp_option=6,192.168.1.3,192.168.1.2,192.168.1.1
 +add_list dhcp.@mac[-1].dhcp_option=3,192.168.1.2
 +add_list dhcp.@mac[-1].dhcp_option=44,192.168.1.3
 +commit dhcp
 +EOF
 +uci commit dhcp
 +/etc/init.d/dnsmasq reload
 +</code>
 +Where 6=DNS, 3=Default Gateway, 44=WINS
 +
 +Assign different dhcp-options to multiple hosts:
 +
 +<code bash>
 +config host
 +    option name 'j400'
 +    option mac '00:21:63:75:aa:17'
 +    option ip '10.11.12.14'
 +    option tag 'vpn'  # assign tag "vpn" to this host
 +
 +config host
 +    option name 'j500'
 +    option mac '01:22:64:76:bb:18'
 +    option ip '10.11.12.15'
 +    option tag 'vpn'  # assign tag "vpn" to this host
 +
 +config tag 'vpn'  # match tag "vpn"
 +    list dhcp_option '6,8.8.8.8,8.8.4.4'  # assign arbritary extra dhcp options to this tag
 +</code>
 +
 +FIXME Convert to procd: etc/init.d/dnsmasq restart
 +
 +==== Enabling DNS without enabling DHCP ====
 +
 +dnsmasq can be used to provide clients with a DNS server but not with DHCP (for example, if DHCP is already supplied by a separate server).
 +
 +First, dnsmasq must be turned on for the internal interface:
 +
 +  * Network > Interfaces
 +    * click the desired internal interface to select it
 +      * DHCP Server
 +        * click the "Setup DHCP Server" button to enable dnsmasq on this interface -- this will enable both DHCP and DNS
 +
 +Now that dnsmasq is enabled, the DHCP portion of dnsmasq needs to be turned off.
 +
 +  * Network > Interfaces
 +    * click the desired internal interface to select it
 +      * DHCP Server
 +        * Ignore interface: Enable this option
 +      * Save & Apply
 +
 +This change will turn off just DHCP but leave DNS services available on the specified interface.

Back to top

doc/uci/dhcp.1364021072.txt.bz2 · Last modified: 2013/03/23 07:44 by nilfred