Interfaces and addresses
ipcalc
Works out an address's network, broadcast address and mask from its prefix.
Given ADDRESS/PREFIX, ipcalc prints the network address (all host bits 0), the broadcast
address (all host bits 1) and the netmask. Two devices are on the same network only if they get the same network
address with their own prefixes: when they do not, one of them sends to its gateway instead of straight to the other.
The labs use BusyBox's ipcalc; other versions print more, the same idea.
ipcalc command usage
ipcalc [-n] [-b] [-m] [-p] ADDRESS/PREFIX
Options
-
-n - the network address
-
-b - the broadcast address
-
-m - the netmask
-
-p - the prefix length
ipcalc examples
-
ipcalc -npbm 10.0.1.10/24 - Prints the network, prefix, broadcast address and mask of 10.0.1.10/24.
-
ipcalc -nb 10.0.1.200/26 - Shows which /26 network 10.0.1.200 falls in, and its broadcast address.
-
for p in 24 25 26; do ipcalc -n 10.0.1.200/$p; done - Shows how the network address of one device changes as the prefix grows.
-
ipcalc -m 10.0.0.1 - With no prefix, falls back to the old class rule: reads the first octet and prints the class's default mask (here class A, 255.0.0.0).
Reading the output
$ ipcalc -nbm 10.0.1.10/26 NETMASK=255.255.255.192 BROADCAST=10.0.1.63 NETWORK=10.0.1.0
NETWORK=10.0.1.0andBROADCAST=10.0.1.63: this network holds 10.0.1.1 to 10.0.1.62.NETMASK=255.255.255.192is/26written the old way.
Pitfalls
ipcalconly calculates: it never changes the card. Set the address withip addr.