Online Book Reader

Home Category

UNIX System Administration Handbook - Evi Nemeth [166]

By Root 2960 0
the all-0 and all-1 host addresses are reserved (they are the network and broadcast addresses, respectively).

It’s confusing to do all this bit twiddling in your head, but some tricks can make it simpler. The number of hosts per network and the value of the last byte in the netmask always add up to 256:

last netmask byte = 256 − net size

For example, 256 − 64 = 192, which is the final byte of the netmask in the preceding example. Another arithmetic fact is that the last byte of an actual network address (as opposed to a netmask) must be evenly divisible by the number of hosts per network. We see this fact in action in the current example, where the last bytes are 0, 64, 128, and 192—all evenly divisible by 64.

In our example, the extra two bits of network address obtained by subnetting can take on the values 00, 01, 10, and 11. The 128.138.243.0/24 network has thus been divided into four /26 networks:

• 128.138.243.0/26 (0 in decimal is 00000000 in binary)

• 128.138.243.64/26 (64 in decimal is 01000000 in binary)

• 128.138.243.128/26 (128 in decimal is 10000000 in binary)

• 128.138.243.192/26 (192 in decimal is 11000000 in binary)

The boldfaced bits of the last byte of each address are the bits that belong to the network portion of that byte.

Given an IP address (say, 128.138.243.100), we cannot tell without the associated netmask what the network address and broadcast address will be. Table 13.4 shows the possibilities for /16 (the default for a class B address), /24 (a sensible value), and /26 (a realistic value if address space is tight).

Table 13.4 Example IP address decodings

Keith Owens has written a wonderful little Perl script called ipcalc.pl that helps with binary/hex/mask arithmetic. It’s available from ftp.ocs.com.au and requires Perl 5. ipcalc displays everything you might need to know about a network address and its netmask, broadcast address, hosts, etc. We’ve even found a version of ipcalc that was ported to the Palm Pilot; see www.ajw.com/ipcalc.htm.

Here’s some sample ipcalc output, munged a bit to help with formatting:

% ipcalc.pl 128.138.243.100/26

IP address 128 . 138 . 243 . 100 / 26 128.138.243.100/26

Mask bits 11111111 11111111 11111111 11000000

Mask bytes 255 . 255 . 255 . 192 255.255.255.192

Address 10000000 10001010 11110011 01100100

Network 128 . 138 . 243 . 64 128.138.243.64

Broadcast 128 . 138 . 243 . 127 128.138.243.127

First Host 128 . 138 . 243 . 65 128.138.243.65

Last Host 128 . 138 . 243 . 126 128.138.243.126

Total Hosts 62

PTR 100.243.138.128.in-addr.arpa

IP Address (hex) 808AF364

The output provides both easy-to-understand versions of the addresses and “cut and paste” versions. Cool.

Red Hat includes a program, also called ipcalc, that performs similar calculations. Its syntax is a bit different.

The original RFC on IP subnetting (RFC950) did not permit the use of the first or last subnets (all 0s and all 1s). In our example with the /26 networks, this rule would eliminate half of the subnets: the 0 subnet and the 192 subnet. Everyone ignored the RFC except Novell and Cisco. (Though in recent versions of Cisco’s IOS operating system—12.0 and later—subnet 0 is available by default.)

The RFC is wrong, although its intentions were fine. Subnet 0 was disallowed because it was thought that confusion might arise if a subnet address was indistinguishable from an unsubnetted network address. The fear proved groundless, however, and all-0/all-1 subnets are in common use today. It is the host portion that should not be all 0s or all 1s.

The network address and broadcast address steal two hosts from each network, so the smallest meaningful network would have four possible hosts: two real hosts—usually at either end of a point-to-point link—and the network and broadcast addresses. To have four values for hosts requires two bits in the host portion, so such a network would be a /30 network with netmask 255.255.255.252 or 0xFFFFFFFC.

Although the hosts on a network may agree that they are using subnetted addresses, the rest of the world doesn’t know

Return Main Page Previous Page Next Page

®Online Book Reader