This script fetches data from Netbox to create Kea subnet configuration from Prefixes, IP Ranges and IP Addresses.
A Jinja2 template is used to render each subnet. It can be customized to add additional data, e.g. from Netbox custom fields (see example in templates).
Docker Images are automatically built for new releases.
docker run --rm mkoetter/netbox-kea-subnets:latest --helppython3 -m venv venv/
source venv/bin/activate
pip3 install -r requirements.txtThe script prints the generated configuration to
stdout, it never updates config files directly. You should always test the generated config (ie.kea-dhcp4 -t /tmp/config.json) before activating it.
Set the Netbox URL and API token using the environment variables NETBOX_URL and NETBOX_TOKEN,
or pass the --url and --token arguments on invocation.
Netbox Prefixes (which represent Kea Subnets) can be selected using the --parent-prefix flag.
This also determines the address family - IPv4 or IPv6 - of the subnets.
0.0.0.0/0 (the default) or ::/0 can be used to select all subnets.
Examples:
--parent-prefix 192.168.0.0/16--parent-prefix 2001:db8:1::/48
Netbox IP Ranges (which represent Kea Pools) are filtered using roles. Specify the slug of the role you want to use for DHCP ranges,
e.g. if the role is called "DHCP Pool" the default slug would be dhcp-pool.
Netbox IP Addresses are used for Kea reservations. The addresses must have status DHCP in Netbox, and they should be assigned to an interface with a MAC address (although client identification could be customized in the subnet template).
The default subnet template uses to following Netbox custom fields to add DHCP options (option-data) to subnets, pools and reservations:
dhcp_default_gateway- IP Addressdhcp_dns_servers- List of IP Addressesdhcp_domain- Textdhcp_mtu- Integerdhcp_ntp_servers- List of IP Addressesdhcp_option_data- JSON, customoption-datafor options not covered above
You can specify an existing Dhcp4 or Dhcp6 config file (must match the address family of --parent-prefix!)
to generate a new configuration with updated subnet4/subnet6 attributes.
The specified config file must not include comments, ie. it must be a standard JSON file!
If this is omitted, the script just generates the subnet list.
Generate subnets within 192.168.0.0/16:
python3 kea-subnets.py --parent-prefix 192.168.0.0/16Update existing config with subnets within 192.168.0.0/16:
python3 kea-subnets.py --config example-dhcp4.json --parent-prefix 192.168.0.0/16