IP ADDRESSING
“DATA NETWORKS” FOR JTOs PH-II - IP Addessing
IP Addressing IP Addressing – Introduction Each host on the internet is assigned a 32-bit integer address called its internet address or IP address. The clever part of internet addressing is that the integers are carefully chosen to make routing efficient. Every host and router on the internet has an IP address, which encodes its network number and host number. The combination is unique: no two machines have the same IP address. The address is coded to allow a variable allocation of bits to specify network and host. The IP address scheme is to break up the binary number into pieces and represent each piece as a decimal number. A natural size for binary pieces is 8 bits, which is the familiar byte or octet (octet is the telecommunication term, but two words can be used interchangeably). So let’s take our binary number , write it using groups of 8 bits, and then represent each group as a decimal number: Example 1: 140.179.220.200 It is sometimes useful to view the values in their binary form. 140 .179 .220 .200 10001100.10110011.11011100.11001000 Every IP address consists of two parts, one identifying the network and one identifying the host. The Class of the address and the subnet mask determine which part belongs to the network address and which part belongs to the host address. 10111100 00011010 000111110 00111100 156 26 30 60 We can use a dot as a separator. Now our IP address has the form Example 2: 156.26.30.60 which is referred to as the dotted decimal notation.
IP Address should be hierarchical For a protocol to be routable, its address structure must be hierarchical, meaning that the address must contain at least two parts: the network portion and the host portion. A host is an end station such as a computer workstation, a router or a printer, whereas a network consists of one or more hosts.
BRBRAITT : Nov-2006
2
“DATA NETWORKS” FOR JTOs PH-II - IP Addessing
Address Classes This encoding provides flexibility in assigning addresses to host and allows a mix of network sizes on an internet. In particular, the three network classes are best suited to the following conditions: • Class A: Few networks, each with many hosts. It allows for up to 126 networks with 16 million hosts each. • Class B: Medium number of networks, each with a medium number of hosts. It allows for up to 16,328 networks with up to 64K hosts each; • Class C: Many networks, each with a few hosts. It allows for up to 2 millions networks with up to 254 hosts each; • Class D: Reserved for IP Multicasting. • Class E: Reserved for future use. Addresses beginning with 1111 are reserved for future use. The Following table lists the capabilities for class A, B and C addresses. Class A B C
Networks 126 16,384 2,097,152
Hosts 16,777,214 65,534 254
More about IP address Classes You can determine which class any IP address is in by examining the first 4 bits of the IP address. •
Class A addresses begin with 0xxx, or 1 to 126 decimal.
•
Class B addresses begin with 10xx, or 128 to 191 decimal.
•
Class C addresses begin with 110x, or 192 to 223 decimal.
•
Class D addresses begin with 1110, or 224 to 239 decimal.
•
Class E addresses begin with 1111, or 240 to 254 decimal.
Addresses beginning with 01111111, or 127 decimal, are reserved for loopback and for internal testing on a local machine. [You can test this: you should always be able to ping 127.0.0.1, which points to yourself] Class D addresses are reserved for multicasting. Class E addresses are reserved for future use. They should not be used for host addresses. Now we can see how the Class determines, by default, which part of the IP address belongs to the network (N) and which part belongs to the host (h). •
Class A -- NNNNNNNN.hhhhhhhh. hhhhhhhh. hhhhhhhh
•
Class B -- NNNNNNNN.NNNNNNNN. hhhhhhhh. hhhhhhhh
BRBRAITT : Nov-2006
3
“DATA NETWORKS” FOR JTOs PH-II - IP Addessing •
Class C -- NNNNNNNN.NNNNNNNN.NNNNNNNN. hhhhhhhh
In the example, 140.179.220.200 is a Class B address so by default the Network part of the address (also known as the Network Address) is defined by the first two octets (140.179.x.x) and the host part is defined by the last 2 octets (x.x.220.200). In order to specify the network address for a given IP address, the host section is set to all "0"s. In our example, 140.179.0.0 specifies the network address for 140.179.220.200. When the host section is set to all "1"s, it specifies a broadcast that is sent to all hosts on the network. 140.179.255.255 specifies the example broadcast address. Note that this is true regardless of the length of the host section.
Private Subnets There are three IP network addresses reserved for private networks. The addresses are 10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16. They can be used by anyone setting up internal IP networks, such as a lab or home LAN behind a Router performing NAT (Network Address Translation) or proxy server. It is always safe to use these because routers on the Internet will never forward packets coming from these addresses. These addresses are defined in RFC 1918.
Subnetting Subnetting an IP Network can be done for a variety of reasons, including organization, use of different physical media (such as Ethernet, FDDI, WAN, etc.), preservation of address space, and security. The most common reason is to control network traffic. In an Ethernet network, all hosts on a segment see all the packets transmitted by all the other hosts on that segment. Performance can be adversely affected under heavy traffic loads, due to collisions and the resulting retransmissions. A router is used to connect IP networks to minimize the amount of traffic each segment must receive.
Subnet Masking Applying a subnet mask to an IP address allows you to identify the network and host parts of the address. The network bits are represented by the 1s in the mask, and the host bits are represented by the 0s. Performing a bitwise logical AND operation between the IP address and the subnet mask results in the Network Address or Number. Eg, using our test IP address and the default Class B subnet mask, we get: 10001100.10110011.11110000.11001000 140.179.240.200 Class B IP Addrs 11111111.11111111.00000000.00000000 255.255. 0. 0 Default Class B S/M -------------------------------------------------------10001100.10110011.00000000.00000000 140.179.0.0 Network Address Default Subnet masks: •
Class A - 255.0.0.0 - 11111111.00000000.00000000.00000000
•
Class B - 255.255.0.0 - 11111111.11111111.00000000.00000000
BRBRAITT : Nov-2006
4
“DATA NETWORKS” FOR JTOs PH-II - IP Addessing •
Class C - 255.255.255.0 - 11111111.11111111.11111111.00000000
More Restrictive Subnet Masks Additional bits can be added to the default subnet mask for a given Class to further subnet, or break down, a network. When a bitwise logical AND operation is performed between the subnet mask and IP address, the result defines the Subnet Address (also called the Network Address or Network Number). There are some restrictions on the subnet address. Host addresses of all "0"s and all "1"s are reserved for specifying the local network (when a host does not know it's network address) and all hosts on the network (broadcast address), respectively. This also applies to subnets. A subnet address cannot be all "0"s or all "1"s. This also implies that a 1 bit subnet mask is not allowed. This restriction is required because older standards enforced this restriction. Recent standards that allow use of these subnets have superceded these standards, but many "legacy" devices do not support the newer standards. If you are operating in a controlled environment, such as a lab, you can safely use these restricted subnets. To calculate the number of subnets or hosts, use the formula (2 n-2) where n = number of bits in either field, and 2n represents 2 raised to the nth power. Multiplying the number of subnets by the number of hosts available per subnet gives you the total number of hosts available for your class and subnet mask. Also, note that although subnet masks with non-contiguous mask bits are allowed, they are not recommended. Example: 10001100.10110011.11011100.11001000 140.179.220.200 IP Address 11111111.11111111.11100000.00000000 255.255.224.000 Subnet Mask -------------------------------------------------------10001100.10110011.11000000.00000000 140.179.192.000 Subnet Address 10001100.10110011.11011111.11111111 140.179.223.255 Broadcast Addrs In this example a 3 bit subnet mask was used. There are 6 (23-2) subnets available with this size mask (remember that subnets with all 0's and all 1's are not allowed). Each subnet has 8190 (213-2) hosts. Each subnet can have hosts assigned to any address between the Subnet address and the Broadcast address. This gives a total of 49,140 hosts for the entire class B address subnetted this way. Notice that this is less than the 65,534 hosts an unsubnetted class B address would have. You can calculate the Subnet Address by performing a bitwise logical AND operation between the IP address and the subnet mask, then setting all the host bits to 0s. Similarly, you can calculate the Broadcast Address for a subnet by performing the same logical AND between the IP address and the subnet mask, then setting all the host bits to 1s. That is how these numbers are derived in the example above. Subnetting always reduces the number of possible hosts for a given network. There are complete subnet tables available here for Class A, Class B and Class C. These tables list all the possible subnet masks for each class, along BRBRAITT : Nov-2006
5
“DATA NETWORKS” FOR JTOs PH-II - IP Addessing with calculations of the number of networks, hosts and total hosts for each subnet.
An Example Here is another, more detailed, example. Say you are assigned a Class C network number of 200.133.175.0 (apologies to anyone who may actually own this domain address). You want to utilize this network across multiple small groups within an organization. You can do this by subnetting that network with a subnet address. We will break this network into 16 subnets of 14 hosts each. This will limit us to 224 hosts on the network instead of the 254 we would have without subnetting, but gives us the advantages of traffic isolation and security. To accomplish this, we need to use a subnet mask 4 bits long. Recall that the default Class C subnet mask is 255.255.255.0 (11111111.11111111.11111111.00000000 binary) Extending this by 4 bits yields a mask of 255.255.255.240 (11111111.11111111.11111111.11110000 binary) This gives us 16 possible network numbers: Subnet bits
Network Number
Host Addresses
Broadcast Address
0000
200.133.175.0
.1 thru .14
200.133.175.15
0001
200.133.175.16
.17 thru .30
200.133.175.31
0010
200.133.175.32
.33 thru .46
200.133.175.47
0011
200.133.175.48
.49 thru .62
200.133.175.63
0100
200.133.175.64
.65 thru .78
200.133.175.79
0101
200.133.175.80
.81 thru .94
200.133.175.95
0110
200.133.175.96
.97 thru .110
200.133.175.111
0111
200.133.175.112
.113 thru .126
200.133.175.127
1000
200.133.175.128
.129 thru .142
200.133.175.143
1001
200.133.175.144
.145 thru .158
200.133.175.159
1010
200.133.175.160
.161 thru .174
200.133.175.175
1011
200.133.175.176
.177 thru .190
200.133.175.191
1100
200.133.175.192
.193 thru .206
200.133.175.207
1101
200.133.175.208
.209 thru .222
200.133.175.223
1110
200.133.175.224
.225 thru .238
200.133.175.239
1111
200.133.175.240
.241 thru .254
200.133.175.255
BRBRAITT : Nov-2006
6
“DATA NETWORKS” FOR JTOs PH-II - IP Addessing
Super-netting: The "classful" system of allocating IP addresses can be very wasteful; anyone who could reasonably show a need for more that 254 host addresses was given a Class B address block of 65533 host addresses. Even more wasteful were companies and organizations that were allocated Class A address blocks, which contain over 16 Million host addresses! Only a tiny percentage of the allocated Class A and Class B address space has ever been actually assigned to a host computer on the Internet. People realized that addresses could be conserved if the class system was eliminated. By accurately allocating only the amount of address space that was actually needed, the address space crisis could be avoided for many years. This was first proposed in 1992 as a scheme called Supernetting. Under supernetting, the classful subnet masks are extended so that a network address and subnet mask could, for example, specify multiple Class C subnets with one address. For example, If I needed about 1000 addresses, I could supernet 4 Class C networks together: 192.60.128.0 (11000000.00111100.10000000.00000000) Class C subnet address 192.60.129.0 (11000000.00111100.10000001.00000000) Class C subnet address 192.60.130.0 (11000000.00111100.10000010.00000000) Class C subnet address 192.60.131.0 (11000000.00111100.10000011.00000000) Class C subnet address --------------------------------------------------------------------------------------------------------------192.60.128.0 (11000000.00111100.10000000.00000000) Supernetted address 255.255.252.0 (11111111.11111111.11111100.00000000) Subnet Mask 192.60.131.255 (11000000.00111100.10000011.11111111) Broadcast address In this example, the subnet 192.60.128.0 includes all the addresses from 192.60.128.0 to 192.60.131.255. As you can see in the binary representation of the subnet mask, the Network portion of the address is 22 bits long, and the host portion is 10 bits long. Instead of spelling out the bits of the subnet mask, it is simply listed as the number of 1s bits that start the mask. In the above example, instead of writing the address and subnet mask as 192.60.128.0, Subnet Mask 255.255.252.0 the network address would be written simply as: 192.60.128.0/22 which indicates starting address of the network, and number of 1s bits (22) in the network portion of the address. If you look at the subnet mask in binary (11111111.11111111.11111100.00000000), you can easily see how this notation works.
BRBRAITT : Nov-2006
7
“DATA NETWORKS” FOR JTOs PH-II - IP Addessing
CIDR – Classless Inter Domain Routing IP has been in heavy use for over a decade. It has worked extremely well, as demonstrated by the exponential growth of the Internet. Unfortunately, IP is rapidly becoming a victim of its own popularity: it is running out of addresses. This looming disaster has sparked a great deal of discussion and controversy within the Internet community about what to do about it. In this section we will describe both the problem and several proposed solutions. A more complete description is given in (Huitema, 1996). Back in 1987, a few visionaries predicted that some day the Internet might grow to 100,000 networks. Most experts pooh-poohed this as being decades in the future, if ever. The 100,000th network was connected in 1996. The problem, simply stated, is that the Internet is rapidly running out of IP addresses. In principle, over 2 billion addresses exist, but the practice of organizing the address space by classes waste millions of them. In particular, the real villain is the class B network. For most organizations, a class A network, with 16 million addresses is too big, and a class C network, with 256 addresses is too small. A class B network, with 65,536, is just right. In Internet folklore, this situation is known as the three bears problem (as in Goldilocks and the Three Bears). In reality, a class B address is far too large for most organizations. Studies have shown that more than half of all class B networks have fewer than 50 hosts. A class C network would have done the job, but no doubt every organization that asked for a class B address thought that one day it would outgrow the 8-bit host field. In retrospect, it might have been better to have had class C networks use 10 bits instead of eight for the host number, allowing 1022 hosts per network. Had this been the case, most organizations would have probably settled for a class C network, and there would have been half a million of them (versus only 16,384 class B networks). However, then another problem would have emerged more quickly: the routing table explosion. From the point of view of the routers, the IP address space is a two-level hierarchy, with network numbers and host numbers. Routers do not have to know about all the hosts, but they do have to know about all the networks. If half a million class C networks were in use, every router in the entire Internet would need a table with half a million entires, one per network, telling which line to use to get to that network, as well as other information. The actual physical storage of half a million entry tables is probably doable, although expensive for critical routers that keep the tables in static RAM on I/O boards. A more serious problem is that the complexity of various algorithms relating to management of the tables grows faster than linear. Worse yet, much of the existing router software and firmware was designed at a time when the Internet had 1000 connected networks and 10,000 networks seemed decades away. Design choices made then often are far from optimal now. BRBRAITT : Nov-2006
8
“DATA NETWORKS” FOR JTOs PH-II - IP Addessing In addition, various routing algorithms require each router to transmit its tables periodically. The larger the tables, the more likely some parts will get lost underway, leading to incomplete data at the other end and possibly routing instabilities. The routing table problem could have been solved by going to a deeper hierarchy. For example, having each IP address contain a country, state, city, network, and host field might work. Then each router would only need to know how to get to each country, the states or provinces in its own country, the cities in its state or province, and the networks in its city. Unfortunately, this solution would require considerably more than 32 bits for IP addresses and would use addresses inefficiently (Liechtenstein would have as many bits as the United States). In short, most solutions solve one problem but create a new one. One solution that is now being implemented and which will give the Internet a bit of extra breathing room is CIDR (Classless InterDomain Routing). The basic idea behind CIDR, which is described in RFC 1519, is to allocate the remaining class C networks, of which there are almost two million, in variable-sized blocks. If a site needs, say, 2000 addresses, it is given a block of 2048 addresses (eight contiguous class C networks), and not a full class B address. Similarly, a site needing 8000 addresses gets 8192 addresses (32 contiguous class C networks). In addition to using blocks of contiguous class C networks as units, the allocation rules for the class C addresses were also changed in RFC 1519. The world was partitioned into four zones, and each one given a portion of the class C address space. The allocation was as follows: Addresses 194.0.0.0 to 195.255.255.255 are for Europe Addresses 198.0.0.0 to 199.255.255.255 are for North America Addresses 200.0.0.0 to 201.255.255.255 are for Central and South America Addresses 202.0.0.0 to 203.255.255.255 are for Asia and the Pacific In this way, each region was given about 32 million addresses to allocate, with another 320 million class C addresses from 204.0.0.0 through 223.255.255.255 held in reserve for the future. The advantage of this allocation is that now any router outside of Europe that gets a packet addressed to 194.xx.yy.zz or 195.xx.yy.zz can just send it to its standard European gateway. In effect 32 million addresses have now been compressed into one routing table entry. Similarly for the other regions. Of course, once a 194.xx.yy.zz packet gets to Europe, more detailed routing tables are needed. One possibility is to have 131,070 entries for networks 194.0.0.xx through 195.255.255.xx, but this is precisely this routing table explosion that we are trying to avoid. Instead, each routing table entry is extended by giving it a 32-bit mask. When a packet comes in, its destination address is first extracted. Then (conceptually) the routing table is scanned entry by entry, masking the destination address and comparing it to the table entry looking for a match. BRBRAITT : Nov-2006
9
“DATA NETWORKS” FOR JTOs PH-II - IP Addessing To make this comparison process clearer, let us consider an example. Suppose that Cambridge University need 2048 addresses and is assigned the addresses 194.24.0.0 through 194.24.7.255, along with mask 255.255.248.0. Next, Oxford University asks for 4096 addresses. Since a block of 4096 addresses must lie on a 4096-byte boundary, they cannot be given addresses starting at 194.8.0.0. Instead they get 194.24.16.0 through 194.24.31.255 along with mask 255.255.240.0. Now the University of Edinburgh asks for 1024 addresses and is assigned addresses 194.24.8.0 through 194.24.11.255 and mask 255.255.252.0. The routing tables all over Europe are now updated with three entries, each one containing a base address and a mask. These entries (in binary) are: Address
Mask
11000010 00011000 00000000 00000000 11111111 11111111 11111000 00000000 Now consider what happens when a packet comes in addressed to 11000010 00011000 00010000 00000000 11111111 11111111 11110000 00000000 194.24.17.4, which in binary is 11000010 00011000 00001000 00000000 11111111 11111111 11111100 00000000 11000010 00011000 00010001 00000100 First it is Boolean ANDed with the Cambridge mask to get 11000010 00011000 00010000 00000000 This value does not match the Cambridge base address, so the original address is next ANDed with the Oxford mask to get 11000010 00011000 00010000 00000000 This value does match the Oxford mask, so the packet is sent to the Oxford router. In practice, the router entries are not tried sequentially; indexing tricks are used to speed up the search. Also, it is possible for two entries to match, in which case the one whose mask has the most 1 bits wins. Finally, the same idea can be applied to all addresses, not just the new class C addresses, so with CIDR, the old class A, B and C network
BRBRAITT : Nov-2006
10
“DATA NETWORKS” FOR JTOs PH-II - IP Addessing
Allowed Class A Subnet and Host IP addresses # bits Subnet Mask
CIDR # Subnets # Hosts
2
255.192.0.0
/10
2
4194302 8388604
3
255.224.0.0
/11
6
2097150 12582900
4
255.240.0.0
/12
14
1048574 14680036
5
255.248.0.0
/13
30
524286
15728580
6
255.252.0.0
/14
62
262142
16252804
7
255.254.0.0
/15
126
131070
16514820
8
255.255.0.0
/16
254
65534
16645636
9
255.255.128.0
/17
510
32766
16710660
10
255.255.192.0
/18
1022
16382
16742404
11
255.255.224.0
/19
2046
8190
16756740
12
255.255.240.0
/20
4094
4094
16760836
13
255.255.248.0
/21
8190
2046
16756740
14
255.255.252.0
/22
16382
1022
16742404
15
255.255.254.0
/23
32766
510
16710660
16
255.255.255.0
/24
65534
254
16645636
17
255.255.255.128 /25
131070
126
16514820
18
255.255.255.192 /26
262142
62
16252804
19
255.255.255.224 /27
524286
30
15728580
20
255.255.255.240 /28
1048574
14
14680036
21
255.255.255.248 /29
2097150
6
12582900
22
255.255.255.252 /30
4194302
2
8388604
BRBRAITT : Nov-2006
Nets * Hosts
11
“DATA NETWORKS” FOR JTOs PH-II - IP Addessing
Allowed Class B Subnet and Host IP addresses # bits Subnet Mask
CIDR # Subnets # Hosts Nets * Hosts
2
255.255.192.0
/18
2
16382
32764
3
255.255.224.0
/19
6
8190
49140
4
255.255.240.0
/20
14
4094
57316
5
255.255.248.0
/21
30
2046
61380
6
255.255.252.0
/22
62
1022
63364
7
255.255.254.0
/23
126
510
64260
8
255.255.255.0
/24
254
254
64516
9
255.255.255.128 /25
510
126
64260
10
255.255.255.192 /26
1022
62
63364
11
255.255.255.224 /27
2046
30
61380
12
255.255.255.240 /28
4094
14
57316
13
255.255.255.248 /29
8190
6
49140
14
255.255.255.252 /30
16382
2
32764
Allowed Class C Subnet and Host IP addresses # bits Subnet Mask
CIDR # Subnets # Hosts Nets * Hosts
2
255.255.255.192 /26
2
62
124
3
255.255.255.224 /27
6
30
180
4
255.255.255.240 /28
14
14
196
5
255.255.255.248 /29
30
6
180
6
255.255.255.252 /30
62
2
124
Logical Operations This page will provide a brief review and explanation of the common logical bitwise operations AND, OR, XOR (Exclusive OR) and NOT. Logical operations are performed between two data bits (except for NOT). Bits can be either "1" or "0", and these operations are essential to performing digital math operations. In the "truth tables" below, the input bits are in bold, and the results are plain.
AND
BRBRAITT : Nov-2006
12
“DATA NETWORKS” FOR JTOs PH-II - IP Addessing The logical AND operation compares 2 bits and if they are both "1", then the result is "1", otherwise, the result is "0". 0 1 0 0 0 1 0 1 OR The logical OR operation compares 2 bits and if either or both bits are "1", then the result is "1", otherwise, the result is "0". 0 1 0 0 1 1 1 1 XOR The logical XOR (Exclusive OR) operation compares 2 bits and if exactly one of them is "1" (i.e., if they are different values), then the result is "1"; otherwise (if the bits are the same), the result is "0". 0 1 0 0 1 1 1 0 NOT The logical NOT operation simply changes the value of a single bit. If it is a "1", the result is "0"; if it is a "0", the result is "1". Note that this operation is different in that instead of comparing two bits, it is acting on a single bit. 0 1 1 0
BRBRAITT : Nov-2006
13