Skip to main content

A NetBox source for octoDNS.

Project description

A NetBox source for octoDNS

PyPI PyPI - Python Version PyPI - License

This project provides a NetBox source for OctoDNS. It retrieves IP address information from NetBox so that OctoDNS creates corresponding A/AAAA and PTR records.

Note: This is just a source for OctoDNS, not a provider. It only serve to populate records into a zone, cannot be synced to.

Installation

pip install octodns-netbox

Getting started

You must configure the url and token parameters in your YAML file to work with the NetBox API. You can also specify the TTL (Time to Live) for the generated records, but this parameter is optional, and the default value is 60.

providers:
  netbox:
    class: octodns_netbox.NetboxSource
    url: https://ipam.example.com
    token: env/NETBOX_TOKEN
    ttl: 60

A records / AAAA records

To create A/AAAA records for octoDNS, you need to manage the mapping between IP addresses and fully qualified domain names (FQDNs) in NetBox. The description field is used for this purpose, and it should contain a comma-separated list of hostnames (FQDNs).

Starting with Netbox v2.6.0, Netbox now has a dns_name field in IP address records. But we do not use this field by default because this dns_name field can only store single FQDN. To use a dns_name field, set field_name: dns_name in the configuration.

PTR records

octodns-netbox also supports PTR records. By default, only the first FQDN in the field is used to generate the PTR record, but you can enable multiple PTR records for a single IP by setting the multivalue_ptr parameter to true in the configuration.

🔍 Example (multivalue_ptr: false - default)

  • IP Address: 192.0.2.1/24
    • Description: en0.host1.example.com,host1.example.com
  • DNS Zone: 2.0.192.in-addr.arpa.
    • 1. PTR en0.host1.example.com.

🔍 Example (multivalue_ptr: true)

  • IP Address: 192.0.2.1/24
    • Description: en0.host1.example.com,host1.example.com
  • DNS Zone: 2.0.192.in-addr.arpa.
    • 1. PTR en0.host1.example.com.
    • 1. PTR host1.example.com.

Classless subnet delegation (IPv4 /31 to /25)

If you are using classless subnets in Netbox, you can automatically expand records for the following format zones:

  • <subnet>-<subnet mask bit count>.2.0.192.in-addr.arpa (RFC 4183 style)
  • <subnet>/<subnet mask bit count>.2.0.192.in-addr.arpa (RFC 2317 style)

Examples

Here is an example configuration for octodns-netbox:

providers:
  netbox:
    class: octodns_netbox.NetboxSource

    # Your Netbox URL
    url: https://ipam.example.com

    # Your Netbox Access Token (read-only)
    # This token should have read-only access to Netbox.
    token: env/NETBOX_TOKEN

    # The TTL of the generated records (Optional, default: 60)
    # Time to Live (TTL) specifies the time interval that a DNS record is stored in cache.
    # The default value of 60 is commonly used for dynamic DNS records.
    ttl: 60

    # Advanced Parameters:
    # The following parameters are optional and can be ignored for most use cases.

    # Generate records including subdomains (Optional, default: `true`)
    # If `false`, only records that belong directly to the zone (domain) will be generated.
    # This can be useful to reduce the number of DNS queries and avoid `SubzoneRecordException` errors.
    populate_subdomains: true

    # FQDN field name (Optional, default: `description`)
    # The `dns_name` field on Netbox is provided to hold only a single name,
    # but typically one IP address will correspond to multiple DNS records (FQDNs).
    # The `description` does not have any limitations so by default
    # we use the `description` field to store multiple FQDNs, separated by commas.
    # Other tested values are `dns_name`.
    field_name: description

    # Tag Name (Optional)
    # By default, all records are retrieved from Netbox, but it can be restricted
    # to only IP addresses assigned a specific tag.
    # Multiple values can be passed, resulting in a logical AND operation.
    populate_tags:
      - tag_name

    # VRF ID (Optional)
    # By default, all records are retrieved from Netbox, but it can be restricted
    # to only IP addresses assigned a specific VRF ID.
    # If `0`, it explicitly points to the global VRF.
    populate_vrf_id: 1

    # VRF Name (Optional)
    # VRF can also be specified by name.
    # If there are multiple VRFs with the same name, it would be better to use `populate_vrf_id`.
    # If `Global`, it explicitly points to the global VRF.
    populate_vrf_name: mgmt

    # Multi-value PTR records support (Optional, default: `false`)
    # If `true`, multiple-valued PTR records will be generated.
    # If `false`, the first FQDN value in the field will be used.
    multivalue_ptr: true

  route53:
    class: octodns_route53.Route53Provider
    access_key_id: env/AWS_ACCESS_KEY_ID
    secret_access_key: env/AWS_SECRET_ACCESS_KEY

zones:
  example.com.:
    sources:
      - netbox  # will add A/AAAA records
    targets:
      - route53

  0/26.2.0.192.in-addr.arpa.:
    sources:
      - netbox  # will add PTR records (corresponding to A records)
    targets:
      - route53

  0.8.b.d.0.1.0.0.2.ip6.arpa:
    sources:
      - netbox  # will add PTR records (corresponding to AAAA records)
    targets:
      - route53

Contributing

See the contributing guide for detailed instructions on how to get started with our project.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

octodns_netbox-0.5.0.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

octodns_netbox-0.5.0-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file octodns_netbox-0.5.0.tar.gz.

File metadata

  • Download URL: octodns_netbox-0.5.0.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for octodns_netbox-0.5.0.tar.gz
Algorithm Hash digest
SHA256 a2867e07a979cc8bef4477b388d60bc3ff0a4b01be79baa7332f8cc52509d6ba
MD5 6b019c55d19fbf7ce0f1237cb6505a11
BLAKE2b-256 2dd7d697b21b8daa07d7c6144e1008944d3289ca915de79f08fb98edbc4c42f5

See more details on using hashes here.

File details

Details for the file octodns_netbox-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: octodns_netbox-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for octodns_netbox-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b397c49e82a36dbb5c30f782d18aa5130737d96e0bc08238718eb5a9ed81d41d
MD5 0e07f3577c8c2c91a58edf4e7ca8e175
BLAKE2b-256 51822c7ce4f6d952c2e9aac474610288e732343176d7452c8bdde494d546e79c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page