Conditional DHCP

I have a DSL setup via RPi3 which acts as DHCP and main router( for a small LAN
The speed is dismal, so I have been experimenting a 2nd RPi ( with a 4G/LTE link.
The LTE stick is an e3772h-320 which is double NAT'd and I cannot get the usbmode to work, so I followed the simplistic rndis option from here and it is now working beautifully....mostly. The modem establishes the connection internally, and then eth1 becomes WAN.

config interface 'wan'
option ifname 'eth1'
option proto 'dhcp'

I would like to test the stability of the 4G before I scrap the DSL completely, so I will have both for a few weeks.

Currently, the serves DHCP to the LAN.
I have added a statics-ONLY setting to the [under interfaces/LAN/Advanced - Dynamically allocate DHCP addresses for clients. If disabled, only clients having static leases will be served.]
My theory was that specific devices that I'd like to work through that router, will be allowed to get DHCP from there.

Now the question... I imagine ALL the devices will try to get DHCP from the default router, which will mess up the gateway setting for those specific stations.

Is it possible to set up one DHCP server for general machines (gateway=, and a 2nd for specific machines (gateway= on the same subnet?
How (if it's possible) would I send default requests to A and specifics to B?


1 Like


This should be applied on each DHCP server.

Thanks for the reply/info.
The static option is cool for the "known" IP's but alas, I have a bunch of visitors too, and they need to go to the other one.

I see I can specify specific gateway using 3,gateway_IP and 6,DNS_IP in the options part.
From the example, would something like this work...

#Assign different DHCP options to multiple hosts.

uci set dhcp.pc1="host"
uci set"pc1"
uci set	dhcp.pc1.mac="00:21:63:75:aa:17"
uci set	dhcp.pc1.ip=""
uci set	dhcp.pc1.tag="router1"

uci set dhcp.pc2="host"
uci set"pc2"
uci set	dhcp.pc2.mac="01:22:64:76:bb:18"
uci set	dhcp.pc2.ip=""
uci set	dhcp.pc2.tag="router2"

uci set dhcp.router1="tag"
uci set dhcp.router1.dhcp_option="3,"
uci set dhcp.router1.dhcp_option="6,"
uci set dhcp.router2="tag"
uci set dhcp.router2.dhcp_option="3,"
uci set dhcp.router2.dhcp_option="6,"
uci commit dhcp
/etc/init.d/dnsmasq restart

and if so, could I simply disable the DHCP(B) and use only DHCP(A)?


If 2 DHCP servers are in the same broadcast domain, then you need to configure them both identically, but each will serve a different dynamic pool.

Both will have all the static leases with the respective tags for gateway and nameserver.
The first will have a dynamic pool say from The second will have a dynamic pool from

Pardon my ignorance here..
To achieve the selective dhcp, do I actually need to have 2x DHCP's with separate pools, or could one do everything required via the "tag"?

You can do everything with one dhcp server.
Since you asked in the first post I thought I could answer you.


Thank you!
I will try the single DHCP (less is more) and see if the tags work as I hoped.

1 Like

I can confirm that the conditional DHCP works as explained (no surprise really). Just in case it is useful, here's roughly what I did...
This is done on the main DHCP box, and the secondary one has dhcp disabled

#clear current settings
uci del dhcp.lan.dhcp_option
#set default route(3)/DNS(6) for the main LAN dhcp
uci add_list dhcp.lan.dhcp_option='6,,,,'
uci add_list dhcp.lan.dhcp_option='3,'
#remove old settings
uci del dhcp.gw1
uci del dhcp.gw2
#create a new tag-set for the 2nd gateway
uci set dhcp.gw2=tag
#clear it to start
uci del dhcp.gw2.dhcp_option
#add the "extended" settings
uci add_list dhcp.gw2.dhcp_option='6,,,,,,'
uci add_list dhcp.gw2.dhcp_option='3,'
#Now set up a machine as default
uci set dhcp.pc1='host'
uci set dhcp.pc1.mac='XX:XX:XX:XX:XX:XX'
uci set'pc1'
uci set dhcp.pc1.dns='1'
uci set dhcp.pc1.ip=''
#and then one on the alternative
uci set dhcp.pc2='host'
uci set dhcp.pc2.mac='XX:XX:XX:XX:XX:XX'
uci set'pc2'
uci set dhcp.pc2.dns='1'
uci set dhcp.pc2.ip=''
#this one gets the additional "tag"
uci set dhcp.pc2.tag='gw2'

Minor notes/observations...

  • if you use xxx-yyy as a station name, you get errors via UCI. xxx_yyy is fine though.
  • I used copy/paste from example page and it added in tabs instead of spaces, which cause the UCI commands to fail, so make sure you replace tabs with spaces.

Thanks to vgaetera and trendy for the help


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