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?

Jerbot
  • 374
  • 2
  • 3
  • 12

2 Answers2

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).

Jerbot
  • 374
  • 2
  • 3
  • 12
  • 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 09:51
  • Looking around the internet and talking to friends better versed in networking, that seems likely. – Jerbot 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=tag:net1,3,10.1.0.254  
    dhcp-option=tag:net2,3,10.1.20.254
Paul Tobias
  • 628
  • 6
  • 11
naf
  • 1
  • 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 01 '17 at 00:09