Set dnsmasq as a DHCP relay responder in UCI

Hi, I have changed my switch to serve as DHCP relay mode, and set an OpenWRT device as its responder.

The switch has two IP: 10.0.10.1/24 and 10.0.200.1/24. The first one is in the subnet of clients, and the second is together with the OpenWRT device (10.0.200.2/24).

[Client] --- (10.0.10.1/24-[Switch]-10.0.200.1/24) --- (10.0.200.2/24-[OpenWRT]

In dnsmasq.conf, I could easily setup the relay responder according to its official example (line 163):

dhcp-range=10.0.10.150,10.0.10.200,255.255.255.0,12h

It seems that the 3rd field 255.255.255.0 plays an important role in working as a relay responder.

I'd like to do this in UCI config (/etc/config/dhcp). But in the pool section of UCI config, I could never know which option value is corresponding to 255.255.255.0.

A normal setup like

config dhcp 'clients'
    option interface 'lan'
    option start '100'
    option leasetime '12h'
    option limit '150'

will not work certainly because it's missing the subnet where it is serving and prints

daemon.warn dnsmasq-dhcp[10447]: no address range available for DHCP request via 10.0.10.1

after the device receives relayed DHCP Discover / Request.

Then I tcpdumped the traffic and found that the relay server sent a DHCP request to OpenWRT with source ip 10.0.10.1, therefore the source IP can be regarded as a classifier. Thus I have also tried to add networkid and tag set as 10.0.10.1, but neither of them work. The UCI documents also show none about classifier based on source IP, so I'm lost.

How can I get the relay responder work in UCI config?

Create an alias interface in the target subnet and add a DHCP pool attached to that alias.

Does it imply that I have to assign another IP in the target subnet for the alias interface? Is it possible to achieve that without assigning extra IP?

Using a configured interface appears to be necessary, and OpenWrt is already connected to the target subnet via the switch, so adding a static IP is justified.

Well, actually these subnets are separated by VLAN. And the interface of 10.0.200.2 can semantically only have addresses of 10.0.200.0/24. I think it's quite weird to add an IP on OpenWRT which is unreachable unless additional routes are added to the L3 switch. Maybe I should turn to dnsmasq.conf. Anyway, thanks a lot for your help! :slight_smile:

1 Like