Can you get OpenWrt's DHCP to dynamically assign gateway IP based on MAC Address?

.. something like a static IP lease for specific devices, except I need a specific gateway IP assigned to one specific device as an exception. Possible?

This is my situation (and why I need this):

I recently purchased a VPN service and my intention is to get every device on my home network to access internet via this VPN.

Thought it would be straightforward to setup my OpenWrt gateway router as an OpenVPN client then go from there. Everything went well except it turned out my gateway router is too old and weak to handle the traffic and encryption. Spikes to 90% CPU whenever there is traffic, and speed was too slow to be usable.

OK I thought, I have another router within my LAN that is being used to bridge two subnets together, and I figured that router can be used instead to become the OpenVPN client. Bingo. Problem (almost) solved.

So basically now all devices that have my gateway router's IP address configured as the gateway IP will connect straight to internet. Those with the OpenVPN client router's IP configured as gateway IP will route traffic via VPN. So it's now only a matter of forcing the DHCP server in my gateway router to assign OpenVPN client router's IP as the gateway IP per my original intention of utilizing the VPN service for every device. End of story (sort of).

There is one device within my network that for some reason doesn't like manually assigned IP parameters (or it frequently drops connection for some strange reason). And I don't want to route traffic via the VPN for this device because the VPN speed is not fast enough for media streaming (this device is a set top box). So specifically for this device I need its gateway IP to be the gateway router's IP, and I cannot manually configure network settings because of the reason above (i.e. have to rely on DHCP). So my only option is to mess with the DHCP server settings to try getting the DHCP to assign a different gateway IP for this device and this device only.

Hope this explanation is clear enough.

Any help appreciated !! Cheers.

This is odd. U'd be needing VLAN and place each gatway on a different VLAN.

But wouldn't it be better to have ur router as the gateway and config routes so that each device/service be routed to different route?

My suggestion would be to buy a new router with enough performance to handle VPN. If u place 2 routers or 2 DHCP servers on the same LAN, u can't force a given device to use only 1 of them. Any device on the LAN would use either, or they conflict with each other.

With a router that fits ur needs, u place 1 port on VLAN 11 and other port on VLAN 12. Set VLAN 11 to be routed directly to Internet and VLAN 12 to be routed to VPN route. Then anything connected to each port will be sure to take that route only.

Or at least connect Internet devices on the main router together with the VPN client router, and VPN devices to the VPN client router and set it to route everything to VPN.

3, is router = gateway.

https://www.iana.org/assignments/bootp-dhcp-parameters/bootp-dhcp-parameters.xhtml

3 Likes

Posted the same question on reddit. Got the answer to my problem there.

The "tag" classifier does exactly what I needed. What I did was basically:


uci set dhcp.tag1="tag"
uci set dhcp.tag1.dhcp_option="3,192.168.1.254"
uci add dhcp host
uci set dhcp.@host[-1].name="my_defiant_device"
uci set dhcp.@host[-1].mac="aa:bb:cc:dd:ee:ff"
uci set dhcp.@host[-1].tag="tag1"
uci commit dhcp
/etc/init.d/dnsmasq restart

That's it.

yep, just as indicated in post#3, > 3 hours prior to it being corroborated on reddit.

2 Likes

... while I appreciate @frollic for trying to help, he merely talked about a universal "dhcp-option 3" for assigning gateway IP for every device, which I have been doing all along.

It was the "tag classifier" that solved my problem, not "dhcp-option 3".

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.