# 5.2 The Internet Layer

## 5.2 The Internet Layer

The Internet as we know it is based on the Internet Protocol, version 4 (IPv4). The basic idea is that each computer on the Internet has a numeric IP address in the form of a.b.c.d, where a and d are one-byte numbers from 1 to 254, and b and c are one-byte numbers from 0 to 255. Technically, an IP address is just a four-byte (32-bit) number, but it's usually easiest to deal with the address as a dotted-quad sequence of decimal numbers, like 10.23.2.37, instead of something ugly like the hexadecimal 0x0A170225.

A subnet is a group of IP addresses in some (hopefully) regular order. For example, the hosts between 10.23.2.1 and 10.23.2.254 could comprise a subnet, or all of the hosts between 10.23.1.1 and 10.23.255.254 could also be a subnet.

Subnets are important because they determine how your packets move between different machines. To communicate with another computer, your machine must know that other computer's IP address. If the destination is on your local area network's subnet, your system can send the data directly to that host, but if not, your machine probably has to send it to a gateway (or router) that transmits your data across another network on its way to the final destination.

### 5.2.1 More on Subnets

A subnet mask defines a subnet; for example, the subnet mask for 10.23.2.1- 10.23.2.254 is 255.255.255.0. In pure binary form, the mask "covers" the bits in an address that are common to the subnet. For example, here are the binary forms of 10.23.2.0 and 255.255.255.0:

```10.23.2.0:        00001010 00010111 00000010 00000000
255.255.255.0:    11111111 11111111 11111111 00000000
```

Now, let's "cover" the bits in 10.23.2.0 with the 1s in 255.255.255.0 by marking these bits in bold:

```10.23.2.0:        00001010 00010111 00000010 00000000
```

Look at the bits that aren't in bold. You can set any number of these bits to 1 to get a valid IP address in this particular subnet (with two exceptions: all 0s and all 1s).

Putting it all together, you can see that a host computer with an IP address of 10.23.2.1 and a subnet mask of 255.255.255.0 can directly communicate with other computers that have IP addresses beginning with 10.23.2 (to talk to the rest of the Internet, your computer needs to use a gateway). You can denote this entire subnet as 10.23.2.0/255.255.255.0.

If you're lucky, you will deal only with easy subnet masks like 255.255.255.0 or 255.255.0.0, but you may be unfortunate and encounter stuff like 255.255.255.192, where it isn't quite so simple to determine the set of addresses that belong to the subnet. It helps to know that 192 is 0xC0 in hexadecimal, from which you should be able to figure out what addresses belong to such a subnet. If you aren't familiar with conversion between decimal, binary, and hexadecimal formats, you should probably learn now. The dc (desk calculator) program has excellent facilities for converting between different radix representations.

A common shorthand for subnet masks is to identify the number of bits at the start of the subnet mask that have a value of 1. For example, 255.255.255.0 contains 24 1-bits to start the 32-bit sequence, so you can write the earlier example of 10.23.2.0/255.255.255.0 as 10.23.2.0/24. Table 5-1 shows several example subnet masks.

Long Form

Short Form

255.0.0.0

8

255.255.0.0

16

255.240.0.0

12

255.255.255.0

24

255.255.255.192

26

Therefore, to specify 10.0.0.0/255.0.0.0, you can use 10.0.0.0/8.

 BackCover
 How Linux Works - What Every Super-User Should Know
 Chapter 1: The Basics
 Chapter 2: Devices, Disks, Filesystems, and the Kernel
 Chapter 3: How Linux Boots
 Chapter 4: Essential System Files, Servers, and Utilities
 Chapter 6: Network Services
 Chapter 7: Introduction to Shell Scripts
 Chapter 8: Development Tools
 Chapter 9: Compiling Software From Source Code
 Chapter 10: Maintaining the Kernel
 Chapter 11: Configuring and Manipulating Peripheral Devices
 Chapter 12: Printing
 Chapter 13: Backups
 Chapter 14: Sharing Files with Samba
 Chapter 15: Network File Transfer
 Chapter 16: User Environments
 Chapter 17: Buying Hardware for Linux
 Chapter 18: Further Directions
 Appendix A: Command Classification
 Bibliography
 List of Figures
 List of Tables
 List of Sidebars