Assign different gateways via DHCP based upon MAC address.

Discussion in 'Tomato Firmware' started by Jaidee, Jul 17, 2007.

  1. Jaidee

    Jaidee LI Guru Member

    Hello all,

    I've had a thread going about half-bridge mode on the DSL-320T for a few days now, and now that's all solved, I'm moving on to my next issue.

    The way my home netowrk is designed, we have two routers which operate on eth same subnet. 192.168.0.* These each have their own WAN connections, as my neighbours would rather be in control of their own internet connection. Fair enough.

    Because all computers on the network must have access to one another, they have to be all on the same subnet - either that or complicated routing tables, and I'm crap at that so let's not go there.

    Because both routers are on the same subnet, I can only run one DHCP server. So, my router gives out IPs in the range, and gives them a gateway of, my router. The second router has DHCP disabled, and this requires all my neighbours PCs to have static IPs and gateways of .

    Ideally, we want all PCs to just take IPs from DHCP. I need a way to customise my dnsmasq to hand out a specific gateway ( to certain MAC addresses on my network. I'm sure this is possible, but how?

    Many thanks,
  2. azeari

    azeari LI Guru Member

    i'm not sure if dnsmasq supports ur configuration, though i do know routing tables will most definitely work (= just draw a route from subnet1 to subnet2(i.e. to with a netmask of through the gateway(router), and vice versa. only issue here is broadcast traffic won't be routed over, which shouldn't usually be an issue
  3. ifican

    ifican Network Guru Member

    Have never tried this but dont see a reason why it should not work. Most of these types of routers now adays offer access restriction via mac, i would restrict the machines that you do not want on each router and then let the other router respond to the dhcp request of the allowed host.
  4. Jaidee

    Jaidee LI Guru Member

    Unfortunately MAC restriction still allows for DHCP requests to be met - it simply prevents traffic to the WAN side.
  5. ifican

    ifican Network Guru Member

    Well i think the easiest thing for you to do then is to get a 3rd router and place it between your networks, put it in router mode and let it handle the interdomain traffic. That way both networks can run dhcp with no worry of getting in each others way.
  6. mstombs

    mstombs Network Guru Member

    Sorry to follow you around Jaidee, but the documentation for dnsmasq does seem to allow what you asked for in the first post ie in the example config file

    You could tag your neighbours static dhcp addresses "red" and then for those that are tagged red allocate them a different default gateway, but you probably also need to change the dns server etc as well - don't see how to do this...

    Whether it works or not I have no idea but it looks like you define extra static dhcp leases with this sort of command in the custom config window


    and specify the gateway to be used for those tagged red with
    dhcp-option = net:red,option:router,
  7. Jaidee

    Jaidee LI Guru Member

    Mstombs, please make no apologies for following me around, this is exactly what I was looking for - fanstastic!

    So, here's my thinking: let's say that nextdoor they have four PCs. The MAC addresses are aa:aa:aa:aa:aa:aa, bb:bb:bb:bb:bb:bb, cc:cc:cc:cc:cc:cc and dd:dd:dd:dd:dd:dd. So I set up four rules to make these MAC addresses "red";

    Then I need to set specific gateway and dns to these MACs:

    To do the gateway I use:
    dhcp-option = net:red, option:router,
    and to do the DNS I think I use:
    dhcp-option = net:red, option:6,
    or it might be:
    dhcp-option = net:red, 6,
    (just removing the "option" as I'm not using the name but the number.)

    I'm actually off to the zoo now (wtf, I know), so I'll implemement this when I return. Cheers for the help folks!
  8. Jaidee

    Jaidee LI Guru Member

    Just to let you guys know I was bang on with the formatting of the custom config, so my config now looks like this:

    dhcp-option = net:red, option:router,
    dhcp-option = net:red, 6,
    Which as you can probably guess, sets all of the desired MAC addresses to take gateway and IP address of instead of the default settings.

    Now my network is truly beautiful.

    Many thanks!
  9. valiene

    valiene LI Guru Member

    2 questions about this config :
    1. where should paste this config to make it working?
    2. what is this "red" parameter?

    Many thanks,
  10. mstombs

    mstombs Network Guru Member

    1. In "Dnsmasq Custom Configuration" window under "Advanced->DHCP/DNS"
    2. It is a label local to this custom config, see example in the dnsmasq manual linked above
  11. skiv71

    skiv71 Addicted to LI Member

    i did it....

    dhcp-option = 6,,
    dhcp-option = 15, "elecref.local"

    in my custom dnsmasq

    i added option 15 to specify dns suffix, great!!

    linux rulezzzzzzz

    thanks for everyones help

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice