Skip to content

CLI Reference

Subnetter provides a comprehensive CLI for generating, validating, and analyzing CIDR allocations.

Commands Overview

CommandDescription
generateGenerate CIDR allocations from a configuration file
validateValidate a configuration file without generating
analyzeDisplay statistics about a configuration
validate-allocationsCheck an existing CSV for CIDR overlaps
netbox-exportExport allocations to NetBox IPAM

generate

Generate IPv4 allocations for accounts, regions, and subnets.

Terminal window
subnetter generate --config config.json --output allocations.csv

Options

OptionShortRequiredDefaultDescription
--config-cYes-Path to configuration file (JSON or YAML)
--output-oNoallocations.csvPath to output CSV file
--provider-pNo-Filter results by cloud provider
--base-cidr-bNo-Override base CIDR from config
--verbose-vNofalseEnable verbose logging
--log-level-lNoinfoLog level: silent, error, warn, info, debug, trace
--no-color-NofalseDisable colored output
--timestamps-NofalseInclude timestamps in logs

Examples

Basic usage:

Terminal window
subnetter generate -c config.json -o allocations.csv

Filter by provider:

Terminal window
subnetter generate -c config.json -o aws-only.csv --provider aws

Override base CIDR:

Terminal window
subnetter generate -c config.json -b 172.16.0.0/12

Verbose output with debug logging:

Terminal window
subnetter generate -c config.json -v -l debug

validate

Validate a configuration file without generating allocations. Useful for CI/CD pipelines.

Terminal window
subnetter validate --config config.json

Options

OptionShortRequiredDefaultDescription
--config-cYes-Path to configuration file (JSON or YAML)
--verbose-vNofalseEnable verbose logging
--log-level-lNoinfoLog level: silent, error, warn, info, debug, trace
--no-color-NofalseDisable colored output
--timestamps-NofalseInclude timestamps in logs

Examples

Terminal window
# Basic validation
subnetter validate -c config.json
# Verbose validation for debugging
subnetter validate -c config.json -v

Exit Codes

CodeMeaning
0Configuration is valid
1Configuration has errors

analyze

Analyze a configuration file and display statistics.

Terminal window
subnetter analyze --config config.json

Options

OptionShortRequiredDefaultDescription
--config-cYes-Path to configuration file (JSON or YAML)
--verbose-vNofalseEnable verbose logging
--log-level-lNoinfoLog level: silent, error, warn, info, debug, trace
--no-color-NofalseDisable colored output
--timestamps-NofalseInclude timestamps in logs

Example Output

Configuration Analysis
======================
Base CIDR: 10.0.0.0/8
Total Accounts: 3
Total Regions: 8
Total Availability Zones: 24
Subnet Types: 4
Total Subnets: 96
Address Space Used: 24,576 IPs
Address Space Available: 16,777,216 IPs
Utilization: 0.15%

validate-allocations

Validate an existing allocations CSV file for CIDR overlaps.

Terminal window
subnetter validate-allocations --file allocations.csv

Options

OptionShortRequiredDefaultDescription
--file-fYes-Path to allocations CSV file
--verbose-vNofalseEnable verbose logging
--log-level-lNoinfoLog level: silent, error, warn, info, debug, trace
--no-color-NofalseDisable colored output
--timestamps-NofalseInclude timestamps in logs

Examples

Terminal window
# Validate a CSV file
subnetter validate-allocations -f allocations.csv
# Verbose output to see all checks
subnetter validate-allocations -f allocations.csv -v

netbox-export

Export allocations to NetBox IPAM for centralized IP address management.

Terminal window
subnetter netbox-export --config config.json --netbox-url https://netbox.example.com

Options

OptionShortRequiredDefaultDescription
--config-cYes-Path to configuration file (JSON or YAML)
--netbox-url-Yes*$NETBOX_URLNetBox API URL
--netbox-token-Yes*$NETBOX_TOKENNetBox API token
--dry-run-NofalsePreview changes without applying
--prune-NofalseDelete prefixes not in allocations
--status-NoreservedStatus for new prefixes
--verbose-vNofalseEnable verbose logging
--log-level-lNoinfoLog level: silent, error, warn, info, debug, trace

*Can be provided via environment variable instead

Examples

Preview what would be created:

Terminal window
subnetter netbox-export -c config.json --dry-run

Export with environment variables:

Terminal window
export NETBOX_URL="https://netbox.example.com"
export NETBOX_TOKEN="your-api-token"
subnetter netbox-export -c config.json

Export with active status:

Terminal window
subnetter netbox-export -c config.json --status active

Global Options

These options work with all commands:

OptionDescription
--versionShow version number
--helpShow help for a command
Terminal window
# Show version
subnetter --version
# Show help
subnetter --help
# Show help for a specific command
subnetter generate --help

Configuration File Formats

Subnetter supports both JSON and YAML configuration files:

{
"baseCidr": "10.0.0.0/8",
"accounts": [
{
"name": "production",
"clouds": {
"aws": {
"regions": ["us-east-1"]
}
}
}
],
"subnetTypes": {
"Public": 24,
"Private": 24
}
}

Output CSV Format

The generated CSV includes these columns:

ColumnDescription
Account NameName of the account
Cloud Provideraws, azure, or gcp
Region NameCloud provider region
Availability ZoneAZ within the region
VPC CIDRCIDR block for the VPC
AZ CIDRCIDR block for the AZ
Subnet RoleSubnet type name
Subnet CIDRCIDR block for the subnet
Usable IPsNumber of usable IP addresses
Total IPsTotal IP addresses in the block
Network AddressFirst address in the block
Broadcast AddressLast address in the block

Error Handling

When errors occur, Subnetter provides clear messages with error codes:

[ERROR] [CLI] ❌ Error: [3002] Not enough space left for allocation with prefix /20
[INFO] [CLI] 💡 Help: Your CIDR block is too small for the requested allocation.
Use a larger CIDR block or reduce the number of subnets.

See Error Handling for a complete list of error codes.