cidr
Manipulate and validate CIDR notation IP addresses
TLDR
Explain a CIDR range
Check whether an address belongs to a CIDR range
Get a count of all addresses in a CIDR range
Check whether two CIDR ranges overlap
Divide a CIDR range into a specific number of networks
SYNOPSIS
cidr <IP_ADDRESS/CIDR_BLOCK> [OPTIONS]
Example: cidr 192.168.1.0/24
Example: cidr 10.0.0.1/8 -v
PARAMETERS
-h, --help
Displays help information about the command and exits.
-v, --verbose
Provides more detailed output, potentially including binary representations of addresses or additional network statistics.
-n, --netmask
Outputs only the subnet mask (e.g., 255.255.255.0) for the given CIDR block.
-N, --network
Outputs only the network address (e.g., 192.168.1.0).
-B, --broadcast
Outputs only the broadcast address for the network.
-H, --hosts
Outputs the usable host IP address range (e.g., 192.168.1.1 - 192.168.1.254).
-c, --count
Outputs the total number of usable hosts within the specified CIDR block.
DESCRIPTION
The cidr command, as described here, is not a standard, universally available utility in most Linux distributions (e.g., Debian, Ubuntu, Fedora, CentOS). Instead, it represents a conceptual tool for performing Classless Inter-Domain Routing (CIDR) calculations. Its purpose is to take an IP address or a CIDR block as input and provide comprehensive details about the associated network. This typically includes the network address, broadcast address, subnet mask, the usable host IP range, and the total number of usable hosts within that specific subnet.
While a dedicated cidr command for general subnet arithmetic is not built-in, many network administrators and engineers develop custom scripts or utilize specialized third-party tools (like ipcalc or Python's ipaddress module) to achieve this functionality. Standard Linux commands like ip (from the iproute2 suite) primarily focus on network interface configuration and routing, extensively using CIDR notation, but they do not provide the detailed subnet breakdown that a conceptual cidr tool would. This conceptual command aims to simplify the understanding and management of complex IP addressing schemes by dissecting CIDR blocks into their fundamental components.
CAVEATS
The command cidr is not a standard, universally available Linux command included by default in most mainstream distributions. The analysis provided here describes a conceptual network calculation tool that performs operations commonly associated with CIDR blocks. Users typically achieve similar results by:
1. Utilizing existing network configuration tools like ip (for setting interface addresses with CIDR).
2. Writing custom scripts in languages like Python (leveraging the ipaddress module), Perl, or Bash.
3. Installing third-party utilities specifically designed for network calculations (e.g., ipcalc, net-tools).
CIDR NOTATION EXPLAINED
CIDR notation combines an IP address with a suffix indicating the number of bits in the network prefix (e.g., 192.168.1.0/24). This prefix determines the network portion of the address, and the remaining bits define the host portion. For instance, a /24 mask means the first 24 bits define the network, leaving 8 bits (256 addresses, including network and broadcast) for hosts. A /16 would mean 16 bits for the network, leaving 16 bits for hosts, and so on.
PRACTICAL CIDR USAGE IN LINUX
Even without a dedicated cidr command, Linux offers robust support for CIDR through its standard tools. For example, to assign an IP address using CIDR to an interface, you would use: ip addr add 192.168.1.10/24 dev eth0. To display the current configuration: ip addr show eth0. For more complex subnetting calculations or scripting, users often turn to programming languages like Python (with its built-in ipaddress module) or install utilities like ipcalc or net-tools (for `netmask` and `broadcast` calculations in some cases).
HISTORY
The concept of Classless Inter-Domain Routing (CIDR) was introduced in 1993 by the IETF (RFCs 1518, 1519, 1520) to address the rapid exhaustion of IPv4 addresses and to improve routing efficiency on the Internet. It replaced the older Classful network addressing scheme by allowing for more flexible allocation of IP addresses through arbitrary-length prefixes. While a specific cidr command for general calculations did not become a standard part of Linux distributions, the ip command, developed as part of the iproute2 suite (starting in the late 1990s) to supersede ifconfig, fully embraced and integrated CIDR notation into all its operations. The need for a dedicated 'CIDR calculator' utility often arises in network planning and troubleshooting, leading to the proliferation of many custom scripts and small open-source tools over the years to fill this niche.
SEE ALSO
ip(8) (The primary Linux networking utility, which extensively uses CIDR notation for interface configuration, routing, and address management.), netstat(8) (Displays network connections, routing tables, and interface statistics, often showing IP addresses with CIDR masks.), route(8) (Manages IP routing table entries, where routes are frequently defined using CIDR notation.), ifconfig(8) (A legacy network configuration utility, which also utilized CIDR masks, largely superseded by ip.)