OpenWrt Forum Archive

Topic: How to configure dnsmasq to assign IPs to subnets?

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

I have the following situation:

- Kamikaze running on my main router with bridged lan, IP address 192.168.1.1 netmask 255.255.255.0
- a second router on the lan, and a subnet 192.168.2.0/24 behind that router (not NAT'ed)
- I have set up the required static routes to route traffic between then 192.168.1.0/24 and 192.168.2.0/24 subnets
- dnsmasq running on my main router
- dns-forwarder running on the second router

I want dnsmasq on the main router to assign IP addresses in the subnet range 192.168.2.0/24 to clients behind the second router. 

I have no idea how to make Kamikaze on the main router aware of the 192.168.2put.0/24 subnet and configure dnsmasq accordingly.

What I have done so far is

1. Put a static route in /etc/config/network

config route 2subnet
   option interface lan
   option target 192.168.2.0
   option netmask 255.255.255.0
   option gateway 192.168.1.2

2. put the following line directly in /etc/init.d/dnsmasq

append args "--dhcp-range=lan,192.168.2.100,192.168.2.120,255.255.255.0,12h"


This works, but especially 2. is obviously a nasty hack and will also be overwritten every time I update the dnsmasq ipkg.

Also, 1. is also unelegant, because I have to hardcode the static route into /etc/config/network

Isn't there a more elegant way to make Kamikaze aware of the fact that there is a subnet on the lan and to properly configure dnsmasq to respond to dhcp queries from the 192.168.2.0/24 subnet?

DHCP works only on subnet AFAIK. ISC DHCP has a relay server, but you need that one on the second router, look for dhcp-relay (openwrt package), or dhcrelay.
Why not install openwrt on the second router and add a dnsmasq config there? It has to route anyway.

I make the following entry in my /etc/config/dhcp (Kamikaze-Version):

-----------------------------------------------snip---------------------------------------
config 'dhcp'
        option 'interface' 'lan2'
        option 'start' '100'
        option 'limit' '150'
        option 'leasetime' '720m'
        option 'ignore' '0'
        option 'options' '-O lan2,6,172.16.10.210 -O lan2,6,172.16.10.210 -O lan2,15,vpv.de -O               lan2,15,id.vpv.de -O lan2,15,vip.vpv.de

        option 'options' '-F lan2,172.26.20.1,172.26.20.10,255.255.0.0,12h'
------------------------------------------------snap----------------------------------------------------------

the entry: option 'options' '-F lan2,172.26.20.1,172.26.20.10,255.255.0.0,12h' seems to be correct.
in the log i can see:
-------------------------------------------------snip-------------------------------------------------------------
Jan  1 00:54:12 OpenWrt daemon.info dnsmasq[2459]: started, version 2.42 cachesize 150
Jan  1 00:54:12 OpenWrt daemon.info dnsmasq[2459]: compile time options: IPv6 GNU-getopt ISC-leasefile no-DBus no-I18N TFTP
Jan  1 00:54:12 OpenWrt daemon.info dnsmasq[2459]: DHCP, IP range 172.26.20.1 -- 172.26.20.10, lease time 12h
Jan  1 00:54:12 OpenWrt daemon.info dnsmasq[2459]: DHCP, IP range 172.26.0.100 -- 172.26.0.250, lease time 12h
Jan  1 00:54:12 OpenWrt daemon.info dnsmasq[2459]: DHCP, IP range 192.168.1.100 -- 192.168.1.250, lease time 12h
Jan  1 00:54:12 OpenWrt daemon.warn dnsmasq[2459]: warning: setting capabilities failed: Operation not permitted
Jan  1 00:54:12 OpenWrt daemon.warn dnsmasq[2459]: running as root
Jan  1 00:54:12 OpenWrt daemon.info dnsmasq[2459]: using local addresses only for domain lan
Jan  1 00:54:12 OpenWrt daemon.info dnsmasq[2459]: reading /tmp/resolv.conf.auto
Jan  1 00:54:12 OpenWrt daemon.info dnsmasq[2459]: using nameserver 217.237.150.188#53
Jan  1 00:54:12 OpenWrt daemon.info dnsmasq[2459]: using nameserver 217.237.151.142#53
Jan  1 00:54:12 OpenWrt daepmon.info dnsmasq[2459]: using local addresses only for domain lan
Jan  1 00:54:12 OpenWrt daemon.info dnsmasq[2459]: read /etc/hosts - 1 addresses
Jan  1 00:54:12 OpenWrt daemon.info dnsmasq[2459]: read /etc/ethers - 0 addresses
------------------------------------------------------snap--------------------------------------------------------
lan2 is a separate vlan. See my /etc/config/network :
-------------------------------------------------------snip-------------------------------------------------------
#### VLAN configuration
config switch eth0
        option vlan0    "1 5*"
        option vlan1    "0 5"
        option vlan2    "2 3 4 5"


#### Loopback configuration
config interface loopback
        option ifname   "lo"
        option proto    static
        option ipaddr   127.0.0.1
        option netmask  255.0.0.0


#### LAN configuration
config interface lan
        option type     bridge
        option ifname   "eth0.0"
        option proto    static
        option ipaddr   192.168.1.1
        option netmask  255.255.255.0


#### WAN configuration
config interface        wan
        option ifname   "eth0.1"
        option proto    "pppoe"
        option keepalive "5"
        option mtu "1500"
        option  username "xxxxxxxx"
        option  password "xxxxxxxx"
        option  userpeerdns
        option  defaultroute
        option  persist
        option  noipdefault

config  interface lan2
        option  ifname  "eth0.2"
        option  proto   static
        option  ipaddr  172.26.80.10
        option  netmask 255.255.0.0
-------------------------------------------------------snap-------------------------------------------------

The discussion might have continued from here.