# dnsmasq - 1 DHCP server and multiple subnets

## njcwotx

I have a dnsmasq dhcp server.  Working as dchp server for the subnet the host is on.  However, there are other subnets connected via a Layer 3 switch.  Using an ip helper address on the swtich I can point any dhcp request in other subnets to the dnsmasq server to get an ip.

Has anyone configured dnsmasq to hand out ips for multiple subnets?  Id appreciate and example.

----------

## Bones McCracker

I have done so, but only with dnsmasq installed on the router itself.  The important thing is probably to clearly understand the use of the "set" and "tag" keywords.  From the dnsmasq man page:

 *Quote:*   

> The  optional  set:<tag>  sets an alphanumeric label which marks this network so that dhcp options may be specified on a per-network basis.  When it is  prefixed with 'tag:' instead, then its meaning changes from setting a tag to matching it.  Only one tag may be set, but more than one tag may be matched.

 

Here are some of the potentially interesting configuration items that I use.  Keep in mind that my dnsmasq instance is on the router itself, with a physical interface to the WAN and a physical interface to each of two subnets, which I refer to as "lan" and "dmz".  You don't want to copy this, but it should at least illustrate the use of the set and tag keywords to manage multiple subnets.

```
# If a name in /etc/hosts has multiple addresses, return the one

# in same subnet as the interface on which the query arrived

localise-queries

# Uncomment this to enable the integrated DHCP server, you need

# to supply the range of addresses available for lease and optionally

# a lease time. If you have more than one network, you will need to

# repeat this for each network on which you want to supply DHCP

# service.

dhcp-range=set:lan,192.168.0.15,192.168.0.30,24h

dhcp-range=set:dmz,192.168.1.15,192.168.1.30,12h

# Set the NTP time server address to be the same machine as

# is running dnsmasq

#dhcp-option=42,0.0.0.0

dhcp-option=tag:lan,42,192.168.0.1

dhcp-option=tag:dmz,42,192.168.1.1

# The following DHCP options set up dnsmasq in the same way as is specified

# for the ISC dhcpcd in

# http://www.samba.org/samba/ftp/docs/textdocs/DHCP-Server-Configuration.txt

# adapted for a typical dnsmasq installation where the host running

# dnsmasq is also the host running samba.

# you may want to uncomment some or all of them if you use

# Windows clients and Samba.

dhcp-option=19,0                    # option ip-forwarding off

dhcp-option=tag:lan,44,192.168.0.1  # set netbios-over-TCP/IP nameserver(s) aka WINS server(s)

dhcp-option=tag:dmz,44,192.168.1.1  # set netbios-over-TCP/IP nameserver(s) aka WINS server(s)

dhcp-option=tag:lan,45,192.168.0.1  # netbios datagram distribution server

dhcp-option=tag:dmz,45,192.168.1.1  # netbios datagram distribution server

dhcp-option=46,8                    # netbios node type

# Send microsoft-specific option to tell windows to release the DHCP lease

# when it shuts down. Note the "i" flag, to tell dnsmasq to send the

# value as a four-byte integer - that's what microsoft wants. See

# http://technet2.microsoft.com/WindowsServer/en/library/a70f1bb7-d2d4-49f0-96d6-4b7414ecfaae1033.mspx?mfr=true

#dhcp-option=vendor:MSFT,2,1i

# (I want this, but only for the dmz network (for guests))

dhcp-option=tag:dmz,vendor:MSFT,2,1i
```

----------

