When configuring a gbase database cluster, you often need to convert IPv6 addresses into the standard RFC compressed format — turning 2001:db8:0:0:0:0:0:1 into 2001:db8::1, for example. This article provides a pure Bash script that performs IPv6 address compression without any external tools like iproute2. It validates the address, finds the longest run of zero segments, and outputs a fully lower‑cased compressed form, optionally preserving a prefix.

Features

Compresses any valid IPv6 address to the canonical RFC format by replacing the longest consecutive zero blocks with ::

Handles addresses with prefixes (e.g., /64); can keep or drop the prefix

Built‑in checks for illegal characters, segment length, and :: occurrence count