dnsmasq是openwrt中默认的dns&dhcp server,它小巧精炼,完全可以满足一个小型网络的需求。

dnsmasq默认将在无线路由器的所有端口上启用dhcp服务,假如需要限定dhcp监听的端口,需要一定的技巧。譬如说希望在wan口和oa口上取消监听:

/etc/config/network
...
config interface 'oa'
# intPort 1 lablePort eth1 vlan1
        option ifname   'eth1.1'
        option type     'bridge'
        option proto    'static'
        option ipaddr   '10.199.27.17'
        option netmask  '255.255.255.0'
        option macaddr  '00:26:9E:0E:B6:1C'

config interface 'wan'
        option ifname   'eth0'
        option proto    'static'
        option ipaddr   '192.168.7.21'
        option netmask  '255.255.255.0'
/etc/config/dhcp
...
config dhcp wan
        option interface        wan
        option ignore   1

config dhcp oa
        option interface        oa
        option ignore   1
取消监听的端口,应该使用/etc/config/network中所定义的接口,而不是ip addr show所看到的接口。
# ip addr show
...
1: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:42:a2:97:e2 brd ff:ff:ff:ff:ff:ff
    inet 192.168.7.21/24 brd 192.168.7.255 scope global eth0
    inet6 fe80::20c:42ff:fea2:97e2/64 scope link
       valid_lft forever preferred_lft forever
2: br-oa: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
    link/ether 00:26:9e:0e:b6:1c brd ff:ff:ff:ff:ff:ff
    inet 10.199.27.17/24 brd 10.199.27.255 scope global br-oa
    inet6 fe80::226:9eff:fe0e:b61c/64 scope link
       valid_lft forever preferred_lft forever

dnsmasq启动之前,会自动将/etc/config/dhcp转换成/tmp/etc/dnsmasq.conf,然后再执行,所以/etc/config/dhcp的改动是否生效,可以通过查看/tmp/etc/dnsmasq.conf来判断。