ipsort v1.3.0

Sort IP addresses numerically,
leave everything else alone.

Feed it a YAML file, a config snippet, or a firewall ruleset and ipsort reorders the CIDRs and hands everything else back untouched.

View on GitHub
ipsort --inline < ingress.yaml
before
annotations:
  whitelist: >-
    192.168.1.0/24,
    10.99.0.0/16,
    10.0.0.0/8,
    172.16.5.0/24
spec:
  host: app.example.com
after
annotations:
  whitelist: >-
    10.0.0.0/8,
    10.99.0.0/16,
    172.16.5.0/24,
    192.168.1.0/24
spec:
  host: app.example.com

A few highlights (see the full feature list on GitHub).

--inline

Sort IPs across multiple lines as one pool. Useful for multi-line annotation values.

--aggregate

Merge adjacent CIDRs into their minimal supernet. 10.0.0.0/25 + 10.0.0.128/25 → 10.0.0.0/24

--unique

Deduplicate by normalized CIDR. First occurrence wins.

--check

Exit 0 if already sorted. Combine with any flag for CI enforcement.

decoration-aware

YAML list markers, JSON brackets, inline keys are all preserved exactly.

IPv4 + IPv6

Mixed input supported. IPv4 sorts first by default; --ipv6-first reverses this.

Get it

Download a pre-built binary for your platform from the releases page, or build from source. Shell completions and a manpage are included. See the README for full installation instructions.