Have DHCP serve addresses on a subnet different to interface?

Is it possible to setup OpenWRT's odhcpd or dnsmasq DHCP to serve IPs from a different subnet to that of an interface? For example if /etc/config/network has

config interface 'lan'
	option ifname 'eth0'
	option proto 'static'
	option ipaddr '192.168.1.1'
	option netmask '255.255.255.0'

Is it possible to have DHCP on lan interface serve 192.168.2.0/24 addresses?

I don’t think so… what is your use case?

1 Like

no, this is not possible with the current setup. But even if it was, those computers wouldn't be able to access the network at all. If you want have devices assigned to a different subnet, you must create additional subnets on the router (i.e. VLANs). This would necessarily mean that those systems would be on a different network than the main lan.

I have the same question as @darksky -- what is your goal here?

2 Likes

Are you looking to have this OpenWrt system serve DHCP to clients on the other side of another router that is the gateway for 192.168.2.0/24 ?
If so, then I think it is possible but I don't know details of how. I think I read that there is a straight forward setting for it. You also would need to configure the router directly connected to the 192.168.2.0/24 network to be a DHCP forwarder/relay.

@darksky @psherman I am setting up WiFi to ethernet bridge/relay. I originally posted about it on the forums here No DHCP assignment with relayd but I can't get that to work still. So I thought I'd try a different approach and have DHCP server on the lan interface assign a portion of the subdomain of the main WiFi network that the main DHCP server is not assigning.

I can manually assign an IP address, gateway, and DNS server of the WiFi subnet to the device on the lan/eth0 side/subdomain. It routes packets with relayd configured as per openwrt docs.

It would be simpler to have the WiFi bridge work but DHCP is not working in that configuration and I am looking to alternatives.

I don’t know what a WiFi bridge is … are you talking about a two device setup: access point + router/firewall?

The OpenWRT device fits like this into the packet flow chain:
WiFi <-> [ OpenWRT device WiFi interface <-> OpenWRT device lan/eth interface ] <-> device eth interface

This enables devices with RJ45 NIC to join WiFi networks [using OpenWRT device].

I would not attempt this since it could end up causing a DHCP conflict with your main DHCP server.

Relayd is really a PITA, but it is a workaround for creating a wifi->wired bridge device since this functionality apparently was not part of the original 802.11 spec/intent. It is believed that many of the commercially available bridge devices of this nature actually use relayd or similar, but that they end up with interesting customizations for their specific implementations.

Given the scenario, your easiest solution would be to actually make 2 routed networks (assuming that you don't need your wired devices to be on the same L2 network and/or that your main router supports static routes so that you can avoid a NAT situation with those devices).

Another option might be to purchase a purpose-built bridge device... although it isn't the ideal situation, you can have reasonable confidence that they figured out how to get it to work as required. (FWIW, Apple AirPort Express and maybe other devices in that line can operate in this mode).

Do you recommend something like this on OpenWRT device?:
WiFi subnet 192.168.0.0/24
--main router static 192.168.0.1
--OpenWRT device static 192.168.0.249
OpenWRT LAN subnet 192.168.1.0/24
On OpenWRT LAN default route any via 192.168.0.1
On main router route 192.168.1.0/24 via 192.168.0.249
On OpenWRT LAN (but not WiFi) enable DHCP

Will there be any problems with 192.168.1.xxx devices reaching the internet due to NAT via 192.168.0.1?

If you reset the router to defaults, you will have the basics of a nat routed configuration with the openwrt lan on 192.168.1.0/24. From there, you would setup a wwan interface and associate it with the radio in sta mode with the credentials to join your wifi network. Include the wwan interface in your wan firewall zone, and it should just work.