The discussion in this section is limited to IPv4 networks. For information about IPv6 protocol, the successor to IPv4, refer to Section 16.2, IPv6—The Next Generation Internet.
Every computer on the Internet has a unique 32-bit address. These 32 bits (or 4 bytes) are normally written as illustrated in the second row in Example 16-1.
Example 16-1 Writing IP Addresses
IP Address (binary): 11000000 10101000 00000000 00010100 IP Address (decimal): 192. 168. 0. 20
In decimal form, the four bytes are written in the decimal number system, separated by periods. The IP address is assigned to a host or a network interface. It can be used only once throughout the world. There are exceptions to this rule, but these are not relevant to the following passages.
The points in IP addresses indicate the hierarchical system. Until the 1990s, IP addresses were strictly categorized in classes. However, this system proved too inflexible and was discontinued. Now, classless routing (CIDR, classless interdomain routing) is used.
Netmasks are used to define the address range of a subnet. If two hosts are
in the same subnet, they can reach each other directly. If they are not in
the same subnet, they need the address of a gateway that handles all the
traffic for the subnet. To check if two IP addresses are in the same
AND both addresses with the netmask. If the
result is identical, both IP addresses are in the same local network. If
there are differences, the remote IP address, and thus the remote
interface, can only be reached over a gateway.
To understand how the netmask works, look at Example 16-2. The netmask consists of 32 bits that identify how much of an IP address belongs to the network. All those bits that are 1 mark the corresponding bit in the IP address as belonging to the network. All bits that are 0 mark bits inside the subnet. This means that the more bits are 1, the smaller the subnet is. Because the netmask always consists of several successive 1 bits, it is also possible to count the number of bits in the netmask. In Example 16-2 the first net with 24 bits could also be written as 192.168.0.0/24.
Example 16-2 Linking IP Addresses to the Netmask
IP address (192.168.0.20): 11000000 10101000 00000000 00010100 Netmask (255.255.255.0): 11111111 11111111 11111111 00000000 --------------------------------------------------------------- Result of the link: 11000000 10101000 00000000 00000000 In the decimal system: 192. 168. 0. 0 IP address (184.108.40.206): 11010101 10111111 00001111 11001000 Netmask (255.255.255.0): 11111111 11111111 11111111 00000000 --------------------------------------------------------------- Result of the link: 11010101 10111111 00001111 00000000 In the decimal system: 213. 95. 15. 0
To give another example: all machines connected with the same Ethernet cable are usually located in the same subnet and are directly accessible. Even when the subnet is physically divided by switches or bridges, these hosts can still be reached directly.
IP addresses outside the local subnet can only be reached if a gateway is configured for the target network. In the most common case, there is only one gateway that handles all traffic that is external. However, it is also possible to configure several gateways for different subnets.
If a gateway has been configured, all external IP packets are sent to the appropriate gateway. This gateway then attempts to forward the packets in the same manner—from host to host—until it reaches the destination host or the packet's TTL (time to live) expires.
This is the netmask AND any address in the network, as shown in Example 16-2 under Result. This address cannot be assigned to any hosts.
This could be paraphrased as:
Access all hosts in this
subnet. To generate this, the netmask is inverted in binary form
and linked to the base network address with a logical OR. The above
example therefore results in 192.168.0.255. This address cannot be
assigned to any hosts.
The address 127.0.0.1 is
assigned to the
loopback device on each host. A
connection can be set up to your own machine with this address and with
all addresses from the complete
127.0.0.0/8 loopback network
as defined with IPv4. With IPv6 there is only one loopback address
Because IP addresses must be unique all over the world, you cannot select random addresses. There are three address domains to use if you want to set up a private IP-based network. These cannot get any connection from the rest of the Internet, because they cannot be transmitted over the Internet. These address domains are specified in RFC 1597 and listed in Table 16-1.
Table 16-1 Private IP Address Domains
172.16.x.x – 172.31.x.x