IP Addresses
IP identifies each network interface by a unique IP number. An IPv4 address is a 32-bit numeric value, divided into 4 individual 8-bit bytes, ranging from 0 through 255. In dotted-decimal notation, each of the 4 bytes making up the 32-bit value is represented as one of the quads in the IP address. For example, the IP address 192.168.10.30 is used as the local host address in the figures throughout this book.
IP addresses are divided into two fields: a network address and a host address within that network. Historically, there were five primary network classes, labeled A through E. Each class is defined by a particular sequence of leading bits in the network part of the IP address. The first 3 classes, A through C, are used for individual host addresses. Class A uses one byte as the network field; Class B uses two bytes; Class C uses 3 bytes; Classes D and E have specialized uses.
Network Address Classes and CIDR
The concept of the Class A, B, and C network address families is widely used, and useful, today. Formally, however, the concept of address classes has been replaced with the concept of Classless Inter-Domain Routing (CIDR). The idea is that the size of the network field in the IP address can be an arbitrary number of bits long. The network field is referred to as a network prefix, or the number of contiguous bits used to identify the network. The remaining bits are used to identify hosts in that network. The goal of CIDR is to allow much finer-grained address block allocation, and to simplify and reduce the size of routing tables. In practice, both addressing models are in use, but the IP address allocation authorities use CIDR, and routers must support it.
Address classes lend themselves well to examples in a book, because the network and host fields fall on byte boundaries.
n Class A network addresses use the high 8 bits of the IP address, the most significant bit being 0, allowing for 128 networks, each containing more than 16 million host addresses. (There are actually 126 networks rather than 128, because network 0 and network 127 are special, non-routable networks.) Usable Class A addresses range from 1.0.0.0 to 126.255.255.255. Figure 1.2 shows this visually.
Figure 1.2. Class A address.
-
Class B network addresses use the high 16 bits of the IP address, the two most significant bits being 10, allowing for more than 16 thousand networks, each containing over 65 thousand host addresses. Class B addresses range from 128.0.0.0 to 191.255.255.255. Figure 1.3 shows this visually.
-
Class C network addresses use the upper 24 bits of the IP address, the three most significant bits being 110, allowing for 2 million networks, each containing 254 host addresses (host addresses 0 and 255 having special meaning). Class C networks range from 192.0.0.0 to 223.255.255.255. Figure 1.4 shows this visually.
Class D multicast IP addresses, the four most significant bits being 1110, are set aside for use as destination addresses when participating in a multicast network broadcast, where many hosts can use a single address to refer to many other hosts. Class D addresses range from 224.0.0.0 to 239.255.255.255.
Class E reserved IP addresses, the four most significant bits being 1111, are set aside for future and experimental use and are not assigned publicly. They range from 240.0.0.0 to 247.255.255.255.
Classless, unallocated, reserved IP addresses follow. They range from 248.0.0.0 to 255.255.255.255.
Figure 1.3. Class B Address.
Figure 1.4. Class C Address.
Special IP Addresses
There are three major special cases of IP addresses:
n Network address 0As noted under Class A addresses, network address 0 is not used as part of a routable address. When used as a source address, its only legal use is during initialization when a host is attempting to have its IP address dynamically assigned by a server. When used as a destination, only address 0.0.0.0 has meaning, and then only to the local machine as referring to itself, or as a convention to refer to a default route.
n Loopback network address 127As noted under Class A addresses, network address 127 is not used as part of a routable address. Loopback addresses refer to a private network interface supported by the operating system. The interface is used as the addressing mechanism for local network-based services. In other words, local network clients use it to address local servers. Loopback traffic remains entirely within the operating system. It is never passed to a physical network interface. Typically, 127.0.0.1 is the only loopback address used, referring to the local host.
n Broadcast addresses are special addresses applying to all hosts on a network. There are two major categories of broadcast addresses. Limited broadcasts are not routed but are delivered to all hosts connected to the same physical network segment. All the bits in both the network and host fields of the IP address are set to one, as 255.255.255.255. Network-directed broadcasts are routed, being delivered to all hosts on a specified network. The IP address's network field specifies a network. The host field is usually all ones, as in 192.168.10.255. Alternatively, you might sometimes see the address specified as the network address, as in 192.168.10.0.
Subnettingthe Local Version of CIDR
Subnetting is a local extension to the network address part of the local IP addresses. A local network mask is defined that treats some of the most significant host address bits as if they were part of the network address. These additional network address bits serve to define multiple networks locally. Remote sites are not aware of local subnets. They see the address range as normal Class A, B, or C addresses.
For example, let's take the Class C private address block, 192.168.1.0. Within this address block, 192.168.1.0 defines the address as a Class C network address, containing up to 254 hosts. The network mask for this network is 255.255.255.0, exactly matching the first 24 bits, the network prefix, of the 192.168.1.0 network. (Remember that 192.168.1.255, the highest address, is the broadcast address for this network. Of the 256 addresses, 254 are available. The lowest address is the network address.)
This network can be subnetted into two local networks by defining the first 25 bits, rather than the first 24 bits, as the network prefix. The most significant bit of the host address field is now treated as part of the network address field. The host field now contains 7 bits rather than 8. The network mask becomes 255.255.255.128. Two subnetworks are defined: 192.168.1.0, addressing hosts from 1 to 126, and 192.168.1.128, addressing hosts from 129 to 254. Each subnet loses 2 host addresses because each subnet uses the lowest host address, 0 or 128, as the network address, and the highest host address, 127 or 255, as the broadcast address (see Table 1.1).
Table 1.1 Class C Network 192.168.1.0 Subnetted into Two Subnets
Subnetworks 192.168.1.0 and 192.168.1.128 can be assigned to two separate internal network interface cards. From the Internet's point of view, the site consists of a single network of up to 254 hosts. Internally, the site consists of two independent networks, each containing up to 126 hosts.
Subnetting allows for the creation of multiple internal networks, each containing different classes of client or server machines, each with its own, independent routing. Different firewall policies can be applied to the two networks.
Host Names and IP Addresses
People like to use words to name things, such as giving computers names like mycomputer.mydomain.myisp.net. Technically, it's not the computer that's being named, but the network interface in the computer. If the computer has multiple network cards, each card will typically have a different name and address, and most likely be on a different network in a different subdomain.
Host name elements are separated by dots. In the case of mycomputer.mydomain.myisp.net, the leftmost element, mycomputer, is the host name. The .mydomain, .myisp, and .net are elements of the domains this network card is a member of. Network domains are hierarchical trees. The most common top level domains are .com, .edu, .org, and .net. These top level domains are intended for commercial sites, educational sites, organizations, and networks, respectively.
What is a domain? It's a naming convention. The hierarchical domain tree represents the hierarchical nature of the global Domain Name Service (DNS) database. DNS maps between the symbolic names people give to computers and networks and the numeric addresses the IP layer uses to uniquely identify network interfaces.
DNS maps in both directionsIP address to name and name to IP address. When you click on a URL in your web browser, the DNS database is consulted to find the unique IP address associated with that host name. The IP address is passed to the IP layer to use as the destination address in the packet.
IP Addresses and Ethernet Addresses
Whereas the IP layer identifies network hosts by their 32-bit IP address, the subnet or link layer identifies the Ethernet card by its unique 48-bit Ethernet address, or MAC address, which the manufacturer burns into the card. IP addresses are passed between the endpoint hosts to identify themselves. Ethernet addresses are passed between adjacent hosts and routers.
Ordinarily, the Ethernet address could be ignored in a firewall discussion. The Layer 2 hardware Ethernet address is not visible to the Layer 3 IP level or Layer 4 transport level. iptables has the extended ability to access and filter on the MAC address. There are specialized uses for this firewall functionality, but it's important to remember that Ethernet addresses do not pass end-to-end across the network. Ethernet addresses are passed between adjacent network interfaces, or hosts and routers. They are not passed through a router unchanged.