4

I have dhcp set up using DNSMasq, which looks like this:

dhcp-range=interface:eth0,10.1.0.50,10.1.0.250,255.255.255.0
dhcp-range=interface:eth1,10.1.20.50,10.1.20.250,255.255.255.0

What I need to be able to do is set the gateway 'dhcp-option 3' for each interface separately, which I expected would look like this:

dhcp-option=interface:eth0,3,10.1.0.254
dhcp-option=interface:eth1,3,10.1.20.254

However, this does not work. What would be the correct way of setting up independent gateways on a per-interface basis?

7

It stands to reason that the syntax in the question would make sense. However, it is even simpler than that:

dhcp-option=eth0,3,10.1.0.254
dhcp-option=eth1,3,10.1.20.254

[Edit] After a couple years of this in use, I'm reporting a problem with this setup. Say you have a public and a secure network, both accessible via WiFi. If your device connects to the public network, but you wish to switch to the secure one, your device and the DHCP server will try to re-use your address lease from the public network, resulting in an invalid address for the subnet you now occupy. This could probably be fixed by setting lease time to zero, but that may have other adverse effects depending on your network requirements (network printer addresses, etc).

| improve this answer | |
  • i'm actually facing the edit you wrote about. lease time to 0 would not flood the network for dhcp lease requests ? – y_nk Oct 21 '16 at 9:51
  • Looking around the internet and talking to friends better versed in networking, that seems likely. – SuperJer Oct 24 '16 at 15:09
0

You can do this with range tags:

    dhcp-range=set:net1,10.1.0.50,10.1.0.250,255.255.255.0
    dhcp-range=set:net2,10.1.20.50,10.1.20.250,255.255.255.0  

    dhcp-option=net1,3,10.1.0.254  
    dhcp-option=net2,3,10.1.20.254
| improve this answer | |
  • If you have any links to documentation on the how and why of range tags, it's a good way to expand the answer for future reference. – Matthew Wetmore Mar 1 '17 at 0:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.