OpenWrt Forum Archive

Topic: Howto announce multiple gateways via DHCP

The content of this topic has been archived on 24 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

The goal is to offer a different set of DNS servers and gateways to particular clients (statically configured) which are participating in the same IP subnet.
Let's say, we have two OpenWrt routers (physical routers), acting as two gateways to two different ISPs. In order to share the load and to achieve a simple redundancy, we want these two GW to be available for the host in the LAN in such a way that some of the hosts use as primary GW1 and GW2 as secondary, and the other hosts use GW2 as primary and GW1 as secondary.

In this thread I found a similar solution but I did not manage to adapt it to these particular needs : https://forum.openwrt.org/viewtopic.php … 87#p131987

I event posted in it, but as I can see the thread is regarding WhiteRussian build and here in Backfire it's a little different, not much at all, but mainly because I would like to find a way to do this using UCI and /etc/config/dhcp.

Here is a sample configuration that I am trying to get work. It would me OK even if this can be achieved with plain dnsmasq.conf file, however some of the options I have tested, like set:tag, etc seem not to be implemented.

1)
I would like to have 2 ranges(pools) within an IP subnet, lets say: 192.168.1.0/24. All the addresses in the 2 pools will be used for static leases.

dhcp-range=gw1,192.168.1.17,static,255.255.255.240,12h
dhcp-range=gw2,192.168.1.49,static,255.255.255.240,12h

Is this statement correct - I want to allocate two ranges in the same s/24 subnet, but I am no sure how to define the ranges - that's why i tried to use /28 subnet statements in this example. I couldn't find how to correctly allocate two different pools in the same subnet (/24) only for static usage (using the host statements)

Maybe the subnet masks need to be correctly set for the right IP subnet, but in this way how to distinguish the two DHCP ranges, and to configure them in a start-end fashion???
dhcp-range=gw1,192.168.1.17,static,255.255.255.0,12h
dhcp-range=gw2,192.168.1.49,static,255.255.255.0,12h

2)
I would like to specify two options to be used in the two ranges of addresses. These are two Gateways and DNS servers to be announced to the particular clients but in different sequence.

dhcp-option=gw1,3,192.168.1.1,192.168.1.2
dhcp-option=gw1,6,192.168.1.1,192.168.1.2

dhcp-option=gw2,3,192.168.1.2,192.168.1.1
dhcp-option=gw2,6,192.168.1.2,192.168.1.1

3)
Static leases for all the clients, but in accordance to the tag specified in the config, some of them, tagged with gw1 will use GW1, DNS1 as primary,and GW2, DNS2 as secondary and vice versa for the clients tagged with gw2

dhcp-host=net:gw1,00:20:e0:3b:13:af,192.168.1.20
dhcp-host=net:gw2,00:20:e0:3b:13:cd,192.168.1.50

Please, give a little help with the above config, as it seems I am missing something. As well, if there is any way to do the above using uci config of dnsmasq in /etc/config/dhcp

Thanks in advance,
Regards,
dir2cas

written_direcon wrote:

Wiki: DNS and DHCP configuration

Hi,
I know about this topic, I have passed through it several times (missed to mention it, sorry) and I couldn't find how to implement the options above - the example that is shown there concerns a dnsmasq sample section, which is then included in the host statement. As far as I know the obove DHCP options should be specified in the dhcp section of the config, however I couldn't find how to do the idea described in my firs post.
I will be grateful if finding how to achieve it in a plain dnsmasq.conf, but twice more if done using uci.
Anybody with ideas how to do that with any of the methods ?

I found a workaround that does the job for now, but it's not the most appropriate solution.

I left the configuration in the /etc/config/dhcp untouched  together with the standard DHCP pool configured in it, the only thing that was done is to add the lines concerning the dhcp-options and the statically configured hosts to the end of /etc/dnsmasq.conf. 

dhcp-option=gw1,3,192.168.1.1,192.168.1.2
dhcp-option=gw1,6,192.168.1.1,192.168.1.2

dhcp-option=gw2,3,192.168.1.2,192.168.1.1
dhcp-option=gw2,6,192.168.1.2,192.168.1.1

dhcp-host=net:gw1,00:20:e0:3b:13:af,192.168.1.20
dhcp-host=net:gw2,00:20:e0:3b:13:cd,192.168.1.50

In this way, only the statically configured clients are announced the specified set of Gateways and DNS servers, depending on the tag, that is set in the particular statement. It's easy now to change the preferred client's configuration by simply changing the tag.
To complete she scheme, you may put this concept in the configuration of the standard DHCP pool that is used for clients, not specified statically, in this way these clients may also use more gateways and DNS servers, but only one of them will be primary for the whole dynamic range.

config 'dhcp' 'lan'
        option 'interface' 'lan'
        option 'start' '62'
        option 'limit' '192'
        option 'leasetime' '600h'
        list 'dhcp_option' '3,192.168.1.1,192.168.1.2'
        list 'dhcp_option' '6,192.168.1.1,192.168.1.2'

Anyway this is not a problem at all, but it will be nice to find how to tag the hole config dhcp.
I am still accepting any suggestions,

Regards,
dir2cas

The discussion might have continued from here.