LinuxCommandLibrary

cidr

Manipulate and validate CIDR notation IP addresses

TLDR

Explain a CIDR range

$ cidr explain [10.0.0.0/16]
copy

Check whether an address belongs to a CIDR range
$ cidr contains [10.0.0.0/16] [10.0.14.5]
copy

Get a count of all addresses in a CIDR range
$ cidr count [10.0.0.0/16]
copy

Check whether two CIDR ranges overlap
$ cidr overlaps [10.0.0.0/16] [10.0.14.0/22]
copy

Divide a CIDR range into a specific number of networks
$ cidr divide [10.0.0.0/16] [9]
copy

SYNOPSIS

cidr [-hnms] address[/nn | /mask] [address[/nn | /mask] ...]

PARAMETERS

-h
    Print usage help and exit.

-n
    Numeric output only (no hostnames).

-m
    Display netmask in dotted decimal.

-s
    Short output format (compact).

DESCRIPTION

The cidr command is a lightweight utility for computing and displaying network parameters from IPv4 addresses specified in CIDR notation. It takes an IP address with a prefix length (e.g., 192.168.1.0/24) or netmask and outputs essential details like the network address, broadcast address, usable host range, total hosts, and netmask in both dotted decimal and CIDR formats.

This tool is invaluable for network engineers, sysadmins, and scripters needing quick subnet validation or range calculations without full-featured tools like ipcalc. Written in Perl, it's efficient, portable across Unix-like systems, and focuses on core CIDR operations. Supports batch input for multiple networks. Output can be customized for numeric-only or compact views, aiding automation in scripts or firewalls.

Limitations include IPv4-only support and basic functionality—no IPv6, reverse DNS, or advanced routing metrics.

CAVEATS

IPv4-only; no IPv6 support. Requires valid input or errors with invalid CIDR. Not installed by default—install via package managers (e.g., cidr-tools on Debian).

EXAMPLE OUTPUT

cidr 192.168.1.0/24
ADDR: 192.168.1.0/255.255.255.0
NET: 192.168.1.0
BRD: 192.168.1.255
HOSTS: 192.168.1.1 - 192.168.1.254 (254)

BATCH USAGE

Process multiple: cidr 10.0.0.0/8 192.168.0.0/16
Outputs details for each on separate lines.

HISTORY

Developed by Bill Shupp in Perl (~1998); version 2.3.3 common. Evolved for quick CLI subnet math amid CIDR adoption post-1993 RFCs.

SEE ALSO

ipcalc(1), sipcalc(1), subnetcalc(1)

Copied to clipboard