
複数の OpenWRT ルータそれぞれをインターネットゲートウェイとして運用している場合に、個別のホストを特定のゲートウェイに DHCP で振りたいことがあります。そんな時に使える、 DHCP-Option を tag に定義する方法を試してみました。
個別ホストへのDHCP-Option記述
ルータを冗長運用している場合など、LAN内に複数のゲートウェイが存在するようなネットワークにおいて、OpenWRTのDHCPサーバがIPアドレスを配布する際に、通常とは異なるゲートウェイを一部のホストへ割当てたいことがあります。
例えば、DHCPのStatic Leasesへ登録している個別のホストに、DHCP-Option #3を使ってゲートウェイをこのように指定してみるも、全く動作してはもらえません。
1 2 3 4 5 6 7 |
config host option name 'piaware2' option dns '1' option mac 'b8:27:##:##:##:##' option ip '192.168.51.210' option leasetime 'infinite' list dhcp_option '3,192.168.51.5' |
DHCP-Optionをtagに入れる
そんな時は一旦、各ゲートウェイへのDHCP-Optionを記したtagを定義して、そのtagをホストエントリに付与します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
config host option name 'piaware2' option dns '1' option mac 'b8:27:##:##:##:##' option ip '192.168.51.210' option leasetime 'infinite' option tag 'gateway5' config tag 'gateway2' list dhcp_option '3,192.168.51.2' option force '1' config tag 'gateway5' list dhcp_option '3,192.168.51.5' option force '1' |
ここでtagの中にDHCP-Optionの値を記述する際には、そのカンマ後ろに半角スペースを入れないよう留意します。
設定のリロード時やサービスのリスタート時に、設定の不備に関するエラーが標準出力されたりしないので、 /etc/config/dhcp を元に出力される、実際の設定ファイル /var/etc/dnsmasq.conf.cfg01411c を確認したり、
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# auto-generated config file from /etc/config/dhcp conf-file=/etc/dnsmasq.conf localise-queries read-ethers enable-ubus=dnsmasq expand-hosts bind-dynamic port=0 edns-packet-max=1232 dhcp-lease-max=50 domain=local local=/local/ addn-hosts=/tmp/hosts dhcp-leasefile=/tmp/dhcp.leases resolv-file=/tmp/resolv.conf.d/resolv.conf.auto stop-dns-rebind rebind-localhost-ok dhcp-broadcast=tag:needs-broadcast conf-dir=/tmp/dnsmasq.d user=dnsmasq group=dnsmasq dhcp-host=b8:27:##:##:##:##,192.168.51.210,piaware2,infinite dhcp-option-force=tag:gateway2,3,192.168.51.2 dhcp-option-force=tag:gateway5,3,192.168.51.5 |
裏でログをモニタリングして、エラーが挙がっていないか確認する必要があります。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# logread Sun Jan 29 16:38:25 2023 daemon.crit dnsmasq[11602]: bad IP address at line 39 of /var/etc/dnsmasq.conf.cfg01411c Sun Jan 29 16:38:25 2023 daemon.crit dnsmasq[11602]: FAILED to start up Sun Jan 29 16:38:30 2023 daemon.crit dnsmasq[11643]: bad IP address at line 39 of /var/etc/dnsmasq.conf.cfg01411c Sun Jan 29 16:38:30 2023 daemon.crit dnsmasq[11643]: FAILED to start up Sun Jan 29 16:38:35 2023 daemon.crit dnsmasq[11652]: bad IP address at line 39 of /var/etc/dnsmasq.conf.cfg01411c Sun Jan 29 16:38:35 2023 daemon.crit dnsmasq[11652]: FAILED to start up Sun Jan 29 16:38:40 2023 daemon.crit dnsmasq[11669]: bad IP address at line 39 of /var/etc/dnsmasq.conf.cfg01411c Sun Jan 29 16:38:40 2023 daemon.crit dnsmasq[11669]: FAILED to start up Sun Jan 29 16:38:45 2023 daemon.crit dnsmasq[11686]: bad IP address at line 39 of /var/etc/dnsmasq.conf.cfg01411c Sun Jan 29 16:38:45 2023 daemon.crit dnsmasq[11686]: FAILED to start up Sun Jan 29 16:38:50 2023 daemon.crit dnsmasq[11696]: bad IP address at line 39 of /var/etc/dnsmasq.conf.cfg01411c Sun Jan 29 16:38:50 2023 daemon.crit dnsmasq[11696]: FAILED to start up Sun Jan 29 16:38:50 2023 daemon.info procd: Instance dnsmasq::cfg01411c s in a crash loop 6 crashes, 0 seconds since last crash Sun Jan 29 16:39:49 2023 daemon.crit dnsmasq[12010]: bad IP address at line 39 of /var/etc/dnsmasq.conf.cfg01411c |
ちなみに、先ほどのDHCP-Optionでカンマの後ろに空白が入っていると、設定が正しく解釈されずに次のようになっていました。
1 2 3 4 |
dhcp-option-force=tag:gateway2,3, dhcp-option-force=tag:gateway2,192.168.51.2 dhcp-option-force=tag:gateway5,3, dhcp-option-force=tag:gateway5,192.168.51.5 |
LuCIには現れない項目
なお、これらの設定項目は、OpenWRTのWebGUIであるLuCI上には現れないので、CLIベースでの設定が必須です。