OpenWrt Forum Archive

Topic: dhcp config - different gateway for different computer

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

Hello, I have two gateways (one is backup adsl and the other is wifi ISP, which is faster). I'd like to configure some MAC adresses (such as voip phone) to use the adsl gateway as default, becasue it is more reliable.

This is my /etc/config/dhcp on wifi router running openwrt:

config dnsmasq
        option domainneeded '1'
        option boguspriv '1'
        option filterwin2k '0'
        option localise_queries '1'
        option rebind_protection '1'
        option rebind_localhost '1'
        option local '/lan/'
        option domain 'lan'
        option expandhosts '1'
        option nonegcache '0'
        option authoritative '1'
        option readethers '1'
        option leasefile '/tmp/dhcp.leases'
        option resolvfile '/tmp/resolv.conf.auto'

config dhcp 'lan'
        option interface 'lan'
        option start '100'
        option limit '100'
        option leasetime '12h'
        option ignore '0'
        option dhcp_option '3,10.0.0.1 6,88.86.108.7'

config host
        option ip '10.0.0.5'
        option mac '11:AA:BB:CC:DD:EE'
        option dhcp_option '3,10.0.0.254 6,208.67.222.222'

config dhcp 'wan'
        option interface 'wan'
        option ignore '1'

MAC address '11:AA:BB:CC:DD:EE' gets the ip 10.0.0.5, but it does not receive the gateway 10.0.0.254 and dns 208.67.222.222, it gets the gateway configured previously in 'lan'. How can I assign different gateways and dns servers to different comuters? Thank you.

(Last edited by nozombian on 6 Feb 2013, 11:54)

First desperate bump wink

Sounds like you need more than DHCP to do this. DHCP can be used to indicate that a given connected device should route its packets to a specific interface on the router, but then the router decides which gateway to send those packets to. You would need to "tell" the OpenWRT box to route the packets received on interface1 to gateway1 and those received on interface2 to gateway2, as well as telling the attached device to route its traffic to interface2 instead of interface1. You'd likely also need another NAT to handle the gateway2 traffic as well.

Thank you for reply, I'm using openwrt as a bridge with wifi AP and it is running a dhcp daemon, so it is only assigning addresses, but it is not a gateway at all, so most of the traffic is not going over this openwrt router. One my gateway is mikrotik router, which I don't have root access to, because it is leased from isp with the service, and the other gateway is adsl modem, both gateways are connected to a switch, where is also my openwrt connected, but it is located elswehere in different building, where I need wifi.

If I set IP/mask/gatway manually on device, everything is working fine, but some devices I have in network do not support manual IP addressing, they work only with dhcp.

From a quick read of the dnsmasq man page.

-G, --dhcp-host=[<hwaddr>][,id:<client_id>|*][,set:<tag>][,<ipaddr>][,<hostname>][,<lease_time>][,ignore]

Maybe I'm missing something, but I don't see an option to directly specify by-host parameters other than the IP address.

The "tag" feature looks like it might be what you need

-O, --dhcp-option=[tag:<tag>,[tag:<tag>,]][encap:<opt>,][vi-encap:<enterprise>,][vendor:[<vendor-class>],][<opt>|option:<opt-name>|option6:<opt>|option6:<opt-name>],[<value>[,<value>]]

Specify different or extra options to DHCP clients. By default, dnsmasq sends some standard options to DHCP clients, the netmask and broadcast address are set to the same as the host running dnsmasq, and the DNS server and default route are set to the address of the machine running dnsmasq. (Equivalent rules apply for IPv6.) If the domain name option has been set, that is sent. This configuration allows these defaults to be overridden, or other options specified. The option, to be sent may be given as a decimal number or as "option:<option-name>" The option numbers are specified in RFC2132 and subsequent RFCs. The set of option-names known by dnsmasq can be discovered by running "dnsmasq --help dhcp". For example, to set the default route option to 192.168.4.4, do --dhcp-option=3,192.168.4.4 or --dhcp-option = option:router, 192.168.4.4 and to set the time-server address to 192.168.0.4, do --dhcp-option = 42,192.168.0.4 or --dhcp-option = option:ntp-server, 192.168.0.4 The special address 0.0.0.0 (or [::] for DHCPv6) is taken to mean "the address of the machine running dnsmasq". Data types allowed are comma separated dotted-quad IP addresses, a decimal number, colon-separated hex digits and a text string. If the optional tags are given then this option is only sent when all the tags are matched.

-F, --dhcp-range=[tag:<tag>[,tag:<tag>],][set:<tag],]<start-addr>[,<end-addr>][,<mode>][,<netmask>[,<broadcast>]][,<lease time>]
-F, --dhcp-range=[tag:<tag>[,tag:<tag>],][set:<tag],]<start-IPv6addr>[,<end-IPv6addr>][,<mode>][,<prefix-len>][,<lease time>] 

The optional set:<tag> sets an alphanumeric label which marks this network so that dhcp options may be specified on a per-network basis. When it is prefixed with 'tag:' instead, then its meaning changes from setting a tag to matching it. Only one tag may be set, but more than one tag may be matched.

You may get some clues in package/dnsmasq/files/dnsmasq.init on how set/tag could be added to the configuration file.

(Last edited by jeffster on 14 Feb 2013, 21:08)

Uh, sounds a bit complicated. But thank you very much for your help, especially with pointing out the tag flag, I will try to study that and what it could do, but it won't be supported by uci for sure sad

(Last edited by nozombian on 15 Feb 2013, 10:27)

The discussion might have continued from here.