CIDR notation is a compact specification of an Internet Protocol address and its associated routing prefix. Classless Inter-Domain Routing (CIDR) is an Internet Protocol (IP) address allocation and route aggregation methodology[1] used within the Internet addressing architecture that replaced the IPv4 classful network organization of the IP address space. It is used also for IPv6 networking, the next generation of the IP addressing architecture.
CIDR notation is constructed from the IP address and the prefix size, the latter being the number of leading 1 bits of the routing prefix. The IP address is expressed according to the standards of IPv4 or IPv6. It is followed by a separator character, the forward slash (/) character, and the prefix size expressed as a decimal number.
The address may denote a single, distinct, interface address or the beginning address of an entire network. In the latter case the CIDR notation specifies the address block allocation of the network. The maximum size of the network is given by the number of addresses that are possible with the remaining, least-significant bits below the prefix. This is often called the host identifier.
For example:- the address specification 192.168.100.1/24 represents the given IPv4 address and its associated routing prefix 192.168.100.0, or equivalently, its subnet mask 255.255.255.0.
- the IPv4 block 192.168.0.0/22 represents the 1024 IPv4 addresses from 192.168.0.0 to 192.168.3.255.
- the IPv6 block 2001:DB8::/48 represents the IPv6 addresses from 2001:DB8:0:0:0:0:0:0 to 2001:DB8:0:FFFF:FFFF:FFFF:FFFF:FFFF.
- ::1/128 represents the IPv6 loopback address. Its prefix size is 128, i.e. the size of the address itself, indicating that this facility consists of only this one address.
Before CIDR notation, IPv4 networks usually used the dot-decimal notation, an alternative representation which uses the network address followed by the network's subnet mask. Thus, The CIDR notation 192.168.0.0/24 would be written as 192.168.0.0/255.255.255.0
The number of addresses of a subnet defined by the mask or prefix can be calculated as 2address size - mask, in which the address size for IPv6 is 128 and 32 for IPv4. For example, in IPv4, a mask of /29 gives: 232-29 = 23 = 8 addresses.
However, because at least one of these addresses is typically used for a gateway to other subnets, and because certain addresses are reserved as broadcast addresses, the number of addresses available for hosts is usually smaller.
IPv4 subnetting referenceCALCULUSSource
Linux comes with various IP subnet calculator that will help you with network settings. Once such program is Sipcalc which is an ip subnet calculator. You can install it as follows under Debian or Ubuntu Linux:
$ sudo apt-get update
$ sudo apt-get install sipcalc
Download sipcalc
How Do I Calculate Subnets?
$ sipcalc 192.168.1.0/24
Sample outputs:
-[ipv4 : 192.168.1.0/24] - 0 [CIDR] Host address - 192.168.1.0 Host address (decimal) - 3232235776 Host address (hex) - C0A80100 Network address - 192.168.1.0 Network mask - 255.255.255.0 Network mask (bits) - 24 Network mask (hex) - FFFFFF00 Broadcast address - 192.168.1.255 Cisco wildcard - 0.0.0.255 Addresses in network - 256 Network range - 192.168.1.0 - 192.168.1.255 Usable range - 192.168.1.1 - 192.168.1.254The above will provide network start & stop range, wildcard, mask and other information. You can calculate 192.168.1.0/24 subnet as follows
$ sipcalc 192.168.1.5/24
Interface Specific Calculation Instead of taking address information from the shell command line arg sipcalc can obtain relevant information by looking at a specified interface on the system. In this example, get information for eth0 interface:
$ sipcalc eth0
Sample outputs:
-[int-ipv4 : eth0] - 0 [CIDR] Host address - 192.168.3.254 Host address (decimal) - 3232236542 Host address (hex) - C0A803FE Network address - 192.168.3.0 Network mask - 255.255.255.0 Network mask (bits) - 24 Network mask (hex) - FFFFFF00 Broadcast address - 192.168.3.255 Cisco wildcard - 0.0.0.255 Addresses in network - 256 Network range - 192.168.3.0 - 192.168.3.255 Usable range - 192.168.3.1 - 192.168.3.254---------------------------------
whatmask Program Whatmask is a small C program that will help you with network settings.
Download whatmask
Download and compile it as follows:
$ cd /tmp
$ wget http://downloads.laffeycomputer.com/current_builds/whatmask/whatmask-1.2.tar.gz
$ tar -zxvf whatmask-1.2.tar.gz
$ cd whatmask-1.2/
$ ./configure
$ make
$ sudo make install
You can use it as follows to find out usable ip address with /29:
$ whatmask /29
Sample outputs:
--------------------------------------------- TCP/IP SUBNET MASK EQUIVALENTS --------------------------------------------- CIDR = .....................: /29 Netmask = ..................: 255.255.255.248 Netmask (hex) = ............: 0xfffffff8 Wildcard Bits = ............: 0.0.0.7 Usable IP Addresses = ......: 6OR
$ whatmask 202.54.1.2/27
Sample outputs:
------------------------------------------------ TCP/IP NETWORK INFORMATION ------------------------------------------------ IP Entered = ..................: 202.54.1.2 CIDR = ........................: /27 Netmask = .....................: 255.255.255.224 Netmask (hex) = ...............: 0xffffffe0 Wildcard Bits = ...............: 0.0.0.31 ------------------------------------------------ Network Address = .............: 202.54.1.0 Broadcast Address = ...........: 202.54.1.31 Usable IP Addresses = .........: 30 First Usable IP Address = .....: 202.54.1.1 Last Usable IP Address = ......: 202.54.1.30
- Whatmask can work in two modes. The first mode is to invoke Whatmask with only a subnet mask as the argument. In this mode Whatmask will echo back the subnet mask in four formats, plus the number of useable addresses in the range.
Netmask Notations supported:Examples
Name Example --------------------------------- CIDR /24 Netmask 255.255.255.0 Netmask (hex) 0xffffff00 Wilcard Bits 0.0.0.255The above notations are all identical. CIDR notation commonly has a "/" in front of the number (representing the number of bits). Whatmask can accept these notations with or without a slash. This notation is used more and more recently. A lot of popular routers and software support this notation.
Netmask notation is pretty much the standard old-school way of doing it. It is supported by most systems (Un*x, Win, Mac, etc.).
Netmask (Hex) is the hexadecimal representation of the netmask. Many implementations of ifconfig use this notation.
Wilcard bits are similar to the netmask, but they are the logical not of the netmask. This notation is used by a number of popular routers (and nobody knows why... ... actually I found a great explanation from 'billf' who removed the nobody knows why line from the FreeBSD port: Netmasks are contiguous bits, wildcard masks don't need to be).
To use Whatmask in the original mode simply type "whatmask" The notation can be in any of the four formats and Whatmask will automagically figure out what it is and display all four notations.
To find out more about subnets and netmasks see the References section below.
To use Whatmask in its second mode execute Whatmask with any ip address within the subnet, followed by a slash ('/'), followed by the subnet mask in any format. (e.g. 192.168.0.23/255.255.255.224, or 192.168.0.23/27)
Whatmask will echo back the following:
(Whatnet assumes that the Broadcast address is the highest address in the subnet. This is the most common configuration.)
- The netmask in the following formats: CIDR, Netmask, Netmask (Hex) Wildcard Bits
- The Network Address
- The Broadcast Address
- The number of Usable IP Addresses
- The First Usable IP Address
- The Last Usable IP Address
No comments:
Post a Comment