zaki work log

作業ログやら生活ログやらなんやら

dnsmasqを使ったDHCPサーバ設定

構成はこちら

zaki-hmkc.hatenablog.com

構成図を以下に再掲。

f:id:zaki-hmkc:20200122215528p:plain

この図の2セグメントにまたがってルーター動作しているLinuxのdnsmasqにDHCPも設定する。
このとき、public segment(ens192のネットワーク)は別のDHCPサーバが動いているので、ens192側では動作しないようにする。
設定は、ルーター化の記事の内容に付け加える前提。

DHCPサーバ設定

設定の概要はこの通り。

設定項目 設定値
DHCPを提供するネットワークインタフェース ens224 (ens192には行わない)
リースするIPアドレスのレンジ 172.16.1.100 ~ 172.16.1.200
ネットマスク 255.255.254.0
リース期間 12時間
DNS設定 172.16.1.0
デフォルトゲートウェイ設定 172.16.1.0

以下のファイルを作成し、dnsmasqをrestartすれば完了。

# cat /etc/dnsmasq.d/private-dhcp.conf
no-dhcp-interface=ens192
bind-interfaces
dhcp-range=172.16.1.100,172.16.1.200,255.255.254.0,12h
dhcp-option=option:dns-server,172.16.1.0
dhcp-option=option:router,172.16.1.0

interfaceDNSサーバ機能も連動しているので注意。
DHCPのみインタフェースを限定するにはno-dhcp-interfaceで除外設定を行う。(なんでdhcp-interfaceは無いんだろ?)

firewalld設定

# firewall-cmd --add-service=dhcp --permanent --zone=internal
success
# firewall-cmd --reload
success
# firewall-cmd --list-all --zone=internal
internal (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens224
  sources:
  services: dhcp dhcpv6-client dns http mdns samba-client ssh
  ports:
  protocols:
  masquerade: yes
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules: