A command-line tool for efficiently aggregating IPv4 prefixes into the smallest possible set of CIDR blocks.
- Aggregates adjacent and overlapping IPv4 CIDR blocks
- Optimizes for the smallest number of resulting prefixes
- Works with standard input/output for easy integration with other tools
- Cross-platform support (Linux, macOS, Windows)
Pre-built binaries are available for various platforms on the Releases page.
-
Download the appropriate binary for your platform:
- Linux:
prefix-aggregator-x86_64-unknown-linux-gnu.zip
- Windows:
prefix-aggregator-x86_64-pc-windows-gnu.zip
- macOS (Intel):
prefix-aggregator-x86_64-apple-darwin.zip
- macOS (Apple Silicon):
prefix-aggregator-aarch64-apple-darwin.zip
- Linux:
-
Extract the ZIP file and place the binary in a directory included in your PATH.
When running the application on macOS, you might see a security warning: "Apple could not verify this app is free from malware."
To resolve this:
- Right-click (or Control-click) on the
prefix-aggregator
binary - Select "Open" from the context menu
- Click "Open" in the dialog that appears
- The app will now be saved as an exception to your security settings
If you have Rust installed, you can build from source:
git clone https://github.com/ugwis/prefix-aggregator.git
cd prefix-aggregator
cargo build --release
The binary will be available at target/release/prefix-aggregator
.
Provide a list of IP prefixes via standard input:
prefix-aggregator < list_of_prefixes.txt
Or use a here document:
prefix-aggregator << EOF
192.168.1.0/24
192.168.2.0/24
192.168.3.0/24
EOF
Input:
10.0.0.0/24
10.0.1.0/24
10.0.2.0/24
Output:
10.0.0.0/23
10.0.2.0/24
The tool automatically combines 10.0.0.0/24
and 10.0.1.0/24
into 10.0.0.0/23
.
Input:
10.0.0.0/8
10.0.0.0/16
10.0.1.0/16
Output:
10.0.0.0/8
The tool recognizes that 10.0.0.0/8
already includes the other prefixes.
Aggregating AWS IP ranges:
curl -s https://ip-ranges.amazonaws.com/ip-ranges.json | jq -r '.prefixes[].ip_prefix' | sort -V | uniq | wc -l
# 4314 prefixes before aggregation
curl -s https://ip-ranges.amazonaws.com/ip-ranges.json | jq -r '.prefixes[].ip_prefix' | sort -V | uniq | prefix-aggregator | wc -l
# 1101 prefixes after aggregation
This example shows how the tool can reduce 4314 AWS IP prefixes to just 1101 prefixes.
The prefix-aggregator uses an algorithm that:
- Sorts the input prefixes
- Identifies adjacent prefixes that can be combined
- Merges overlapping prefixes
- Recursively applies these operations until no further aggregation is possible