Transcription

IPv4 Addressing and Subnetting v1.41 – Aaron Balchunas1- IPv4 Addressing and Subnetting Hardware AddressingA hardware address is used to uniquely identify a host within a localnetwork. Hardware addressing is a function of the Data-Link layer of theOSI model (Layer-2).Ethernet utilizes the 48-bit MAC address as its hardware address. TheMAC address is often hardcoded on physical network interfaces, thoughsome interfaces support changing the MAC address using special utilities. Invirtualization environments, dynamically assigning MAC addresses is verycommon.A MAC address is most often represented in hexadecimal, using one of twoaccepted formats:00:43:AB:F2:32:130043.ABF2.3213The first six hexadecimal digits of a MAC address identify the manufacturerof the physical network interface. This is referred to as the OUI(Organizational Unique Identifier). The last six digits uniquely identifythe host itself, and are referred to as the host ID.The MAC address has one shortcoming – it contains no hierarchy. MACaddresses provide no mechanism to create boundaries between networks.There is no method to distinguish one network from another.This lack of hierarchy poses significant difficulties to network scalability. Ifonly Layer-2 hardware addressing existed, all hosts would technically existon the same network. Internetworks like the Internet could not exist, as itwould be impossible to separate my network from your network.Imagine if the entire Internet existed purely as a single Layer-2 switchednetwork. Switches, as a rule, will forward a broadcast out every port. Withbillions of hosts on the Internet, the resulting broadcast storms would bedevastating. The Internet would simply collapse.The scalability limitations of Layer-2 hardware addresses are mitigatedusing logical addresses, covered in great detail in this guide.***All original material copyright 2013 by Aaron Balchunas ([email protected]),unless otherwise noted. All other material copyright of their respective owners.This material may be copied and used freely, but may not be altered or sold without the expressed writtenconsent of the owner of the above copyright. Updated material may be found at http://www.routeralley.com.

IPv4 Addressing and Subnetting v1.41 – Aaron Balchunas2Logical AddressingLogical addressing is a function of the Network layer of the OSI Model(Layer-3), and provides a hierarchical structure to separate networks.Logical addresses are never hardcoded on physical network interfaces, andcan be dynamically assigned and changed freely.A logical address contains two components: Network ID – identifies which network a host belongs to. Host ID – uniquely identifies the host on that network.Examples of logical addressing protocols include Internetwork PacketExchange (IPX) and Internet Protocol (IP). IPX was predominantly usedon Novell networks, but is now almost entirely deprecated. IP is the mostwidely-used logical address, and is the backbone protocol of the Internet.Internet Protocol (IP)In the 1970’s, the Department of Defense developed the TransmissionControl Protocol (TCP), to provide both Network and Transport layerfunctions. When this proved to be an inflexible solution, those functionswere separated - with the Internet Protocol (IP) providing Network layerservices, and TCP providing Transport layer services.Together, TCP and IP provide the core functionality for the TCP/IP orInternet protocol suite.IP provides two fundamental Network layer services: Logical addressing – provides a unique address that identifies boththe host, and the network that host exists on. Routing – determines the best path to a particular destinationnetwork, and then routes data accordingly.IP was originally defined in RFC 760, and has been revised several times.IP Version 4 (IPv4) was the first version to experience widespreaddeployment, and is defined in RFC 791. IPv4 will be the focus of this guide.IPv4 employs a 32-bit address, which limits the number of possibleaddresses to 4,294,967,296. IPv4 will eventually be replaced by IP Version 6(IPv6), due to a shortage of available IPv4 addresses. IPv6 is covered ingreat detail in another guide.***All original material copyright 2013 by Aaron Balchunas ([email protected]),unless otherwise noted. All other material copyright of their respective owners.This material may be copied and used freely, but may not be altered or sold without the expressed writtenconsent of the owner of the above copyright. Updated material may be found at http://www.routeralley.com.

IPv4 Addressing and Subnetting v1.41 – Aaron Balchunas3IPv4 AddressingA core function of IP is to provide logical addressing for hosts. An IPaddress provides a hierarchical structure to both uniquely identify a host,and what network that host exists on.An IP address is most often represented in decimal, in the following format:158.80.164.3An IP address is comprised of four octets, separated by periods:First OctetSecond OctetThird OctetFourth Octet158801643Each octet is an 8-bit number, resulting in a 32-bit IP address. The smallestpossible value of an octet is 0, or 00000000 in binary. The largest possiblevalue of an octet is 255, or 11111111 in binary.The above IP address represented in binary would look as follows:First OctetSecond OctetThird OctetFourth Octet10011110010100001010010000000011Decimal to Binary ConversionThe simplest method of converting between decimal and binary is toremember the following table:1286432168421To convert a decimal number of 172 to binary, start with the leftmostcolumn. Since 172 is greater than 128, that binary bit will be set to 1. Next,add the value of the next column (128 64 192). Since 172 is less than192, that binary bit will be set to 0.Again, add the value of the next column (128 32 160). Since 172 isgreater than 160, that binary bit will be set to 1. Continue this process untilthe columns with binary bits set to 1 add up to 172:DecimalBinary128164032116081412010***All original material copyright 2013 by Aaron Balchunas ([email protected]),unless otherwise noted. All other material copyright of their respective owners.This material may be copied and used freely, but may not be altered or sold without the expressed writtenconsent of the owner of the above copyright. Updated material may be found at http://www.routeralley.com.

IPv4 Addressing and Subnetting v1.41 – Aaron Balchunas4Binary to Decimal ConversionConverting from binary back to decimal is even simpler. Apply the binarynumber to the conversion table, and then add up any columns with binarybits set to 1.For example, consider the binary number of 11110001:DecimalBinary128164132116180402011By adding 128 64 32 16 1, it can be determined that 11110001equals 241.The Subnet MaskPart of an IP address identifies the network. The other part of the addressidentifies the host. A subnet mask is required to provide this distinction:158.80.164.3 255.255.0.0The above IP address has a subnet mask of 255.255.0.0. The subnet maskfollows two rules: If a binary bit is set to a 1 (or on) in a subnet mask, the correspondingbit in the address identifies the network. If a binary bit is set to a 0 (or off) in a subnet mask, the correspondingbit in the address identifies the host.Looking at the above address and subnet mask in binary:IP Address:Subnet 1111111.00000000.00000000The first 16 bits of the subnet mask are set to 1. Thus, the first 16 bits of theaddress (158.80) identify the network. The last 16 bits of the subnet mask areset to 0. Thus, the last 16 bits of the address (164.3) identify the unique hoston that network.The network portion of the subnet mask must be contiguous. For example, asubnet mask of 255.0.0.255 is not valid.***All original material copyright 2013 by Aaron Balchunas ([email protected]),unless otherwise noted. All other material copyright of their respective owners.This material may be copied and used freely, but may not be altered or sold without the expressed writtenconsent of the owner of the above copyright. Updated material may be found at http://www.routeralley.com.

IPv4 Addressing and Subnetting v1.41 – Aaron Balchunas5The Subnet Mask (continued)Hosts on the same logical network will have identical network addresses,and can communicate freely. For example, the following two hosts are onthe same network:Host A:Host B:158.80.164.100 255.255.0.0158.80.164.101 255.255.0.0Both share the same network address (158.80), which is determined by the255.255.0.0 subnet mask. Hosts that are on different networks cannotcommunicate without an intermediating device. For example:Host A:Host B:158.80.164.100 255.255.0.0158.85.164.101 255.255.0.0The subnet mask has remained the same, but the network addresses are nowdifferent (158.80 and 158.85 respectively). Thus, the two hosts are not onthe same network, and cannot communicate without a router between them.Routing is the process of forwarding packets from one network to another.Consider the following, trickier example:Host A:Host B:158.80.1.1 255.248.0.0158.79.1.1 255.248.0.0The specified subnet mask is now 255.248.0.0, which doesn’t fall cleanly onan octet boundary. To determine if these hosts are on separate networks, firstconvert everything to binary:Host A Address:Host B Address:Subnet 0.00000000Remember, the 1 (or on) bits in the subnet mask identify the network portionof the address. In this example, the first 13 bits (the 8 bits of the first octet,and the first 5 bits of the second octet) identify the network. Looking at onlythe first 13 bits of each address:Host A Address:Host B Address:10011110.0101010011110.01001Clearly, the network addresses are not identical. Thus, these two hosts are onseparate networks, and require a router to communicate.***All original material copyright 2013 by Aaron Balchunas ([email protected]),unless otherwise noted. All other material copyright of their respective owners.This material may be copied and used freely, but may not be altered or sold without the expressed writtenconsent of the owner of the above copyright. Updated material may be found at http://www.routeralley.com.

IPv4 Addressing and Subnetting v1.41 – Aaron Balchunas6IP Address ClassesThe IPv4 address space has been structured into several classes. The valueof the first octet of an address determines the class of the network:ClassFirst Octet RangeDefault Subnet MaskClass AClass BClass CClass D1 - 127128 - 191192 - 223224 - 239255.0.0.0255.255.0.0255.255.255.0-Class A networks range from 1 to 127. The default subnet mask is 255.0.0.0.Thus, by default, the first octet defines the network, and the last three octetsdefine the host. This results in a maximum of 127 Class A networks, with16,777,214 hosts per network!Example of a Class A address:Address:Subnet Mask:64.32.254.100255.0.0.0Class B networks range from 128 to 191. The default subnet mask is255.255.0.0. Thus, by default, the first two octets define the network, and thelast two octets define the host. This results in a maximum of 16,384 Class Bnetworks, with 65,534 hosts per network.Example of a Class B address:Address:Subnet Mask:152.41.12.195255.255.0.0Class C networks range from 192 to 223. The default subnet mask is255.255.255.0. Thus, by default, the first three octets define the network,and the last octet defines the host. This results in a maximum of 2,097,152Class C networks, with 254 hosts per network.Example of a Class C address:Address:Subnet Mask:207.79.233.6255.255.255.0Class D networks are reserved for multicast traffic. Class D addresses donot use a subnet mask.***All original material copyright 2013 by Aaron Balchunas ([email protected]),unless otherwise noted. All other material copyright of their respective owners.This material may be copied and used freely, but may not be altered or sold without the expressed writtenconsent of the owner of the above copyright. Updated material may be found at http://www.routeralley.com.

IPv4 Addressing and Subnetting v1.41 – Aaron Balchunas7CIDR (Classless Inter-Domain Routing)Classless Inter-Domain Routing (CIDR) is a simplified method ofrepresenting a subnet mask. CIDR identifies the number of binary bits set toa 1 (or on) in a subnet mask, preceded by a slash.For example, a subnet mask of 255.255.255.240 would be represented asfollows in binary:11111111.11111111.11111111.11110000The first 28 bits of the above subnet mask are set to 1. The CIDR notationfor this subnet mask would thus be /28.The CIDR mask is often appended to the IP address. For example, an IPaddress of 192.168.1.1 and a subnet mask of 255.255.255.0 would berepresented as follows using CIDR notation:192.168.1.1 /24Address Classes vs. Subnet MaskRemember the following three rules: The first octet on an address dictates the class of that address. The subnet mask determines what part of an address identifies thenetwork, and what part identifies the host. Each class has a default subnet mask. A network using its defaultsubnet mask is referred to as a classful network.For example, 10.1.1.1 is a Class A address, and its default subnet mask is255.0.0.0 (/8 in CIDR).It is entirely possible to use subnet masks other than the default. Forexample, a Class B subnet mask can be applied to a Class A address:10.1.1.1 /16However, this does not change the class of the above address. It remains aClass A address, which has been subnetted using a Class B mask.Remember, the only thing that determines the class of an IP address is thefirst octet of that address. Likewise, the subnet mask is the only thing thatdetermines what part of an address identifies the network, and what partidentifies the host.***All original material copyright 2013 by Aaron Balchunas ([email protected]),unless otherwise noted. All other material copyright of their respective owners.This material may be copied and used freely, but may not be altered or sold without the expressed writtenconsent of the owner of the above copyright. Updated material may be found at http://www.routeralley.com.

IPv4 Addressing and Subnetting v1.41 – Aaron Balchunas8Subnet and Broadcast AddressesOn each IP network, two host addresses are reserved for special use: The subnet (or network) address The broadcast addressNeither of these addresses can be assigned to an actual host.The subnet address is used to identify the network itself. A routing tablecontains a list of known networks, and each network is identified by itssubnet address. Subnet addresses contain all 0 bits in the host portion ofthe address.For example, 192.168.1.0/24 is a subnet address. This can be determined bylooking at the address and subnet mask in binary:IP Address:Subnet 1111111.11111111.00000000Note that all host bits in the address are set to 0.The broadcast address identifies all hosts on a particular network. A packetsent to the broadcast address will be received and processed by every host onthat network. Broadcast addresses contain all 1 bits in the host portion ofthe address.For example, 192.168.1.255/24 is a broadcast address. Note that all host bitsare set to 1:IP Address:Subnet 1111111.11111111.00000000Broadcasts are one of three types of IP packets: Unicasts are packets sent from one host to one other host Multicasts are packets sent from one host to a group of hosts Broadcasts are packets sent from one host to all other hosts on thelocal networkA router, by default, will never forward a multicast or broadcast packetfrom one interface to another.A switch, by default, will forward a multicast or broadcast packet out everyport, except for the port that originated the multicast or broadcast.***All original material copyright 2013 by Aaron Balchunas ([email protected]),unless otherwise noted. All other material copyright of their respective owners.This material may be copied and used freely, but may not be altered or sold without the expressed writtenconsent of the owner of the above copyright. Updated material may be found at http://www.routeralley.com.

IPv4 Addressing and Subnetting v1.41 – Aaron Balchunas9SubnettingSubnetting is the process of creating new networks (or subnets) by stealingbits from the host portion of a subnet mask. There is one caveat: stealing bitsfrom hosts creates more networks but fewer hosts per network.Consider the following Class C network:192.168.254.0The default subnet mask for this network is 255.255.255.0. This singlenetwork can be segmented, or subnetted, into multiple networks. Forexample, assume a minimum of 10 new networks are required. Resolvingthis is possible using the following magical formula:2nThe exponent ‘n’ identifies the number of bits to steal from the host portionof the subnet mask. The default Class C mask (255.255.255.0) looks asfollows in binary:11111111.1111111.1111111.00000000There are a total of 24 bits set to 1, which are used to identify the network.There are a total of 8 bits set to 0, which are used to identify the host, andthese host bits can be stolen.Stealing bits essentially involves changing host bits (set to 0 or off) in thesubnet mask to network bits (set to 1 or on). Remember, network bits in asubnet mask must always be contiguous - skipping bits is not allowed.Consider the result if three bits are stolen. Using the above formula:2n 23 8 8 new networks createdHowever, a total of 8 new networks does not meet the original requirementof at least 10 networks. Consider the result if four bits are stolen:2n 24 16 16 new networks createdA total of 16 new networks does meet the original requirement. Stealing fourhost bits results in the following new subnet mask:11111111.11111111.11111111.11110000 255.255.255.240***All original material copyright 2013 by Aaron Balchunas ([email protected]),unless otherwise noted. All other material copyright of their respective owners.This material may be copied and used freely, but may not be altered or sold without the expressed writtenconsent of the owner of the above copyright. Updated material may be found at http://www.routeralley.com.

IPv4 Addressing and Subnetting v1.41 – Aaron Balchunas 10Subnetting (continued)In the previous example, a Class C network was subnetted to create 16 newnetworks, using a subnet mask of 255.255.255.240 (or /28 in CIDR). Fourbits were stolen in the subnet mask, leaving only four bits for hosts.To determine the number of hosts this results in, for each of the new 16networks, a slightly modified formula is required:2n – 2Consider the result if four bits are available for hosts:2n – 2 24 – 2 16 – 2 14 usable hosts per networkThus, subnetting a Class C network with a /28 mask creates 16 newnetworks, with 14 usable hosts per network.Why is the formula for calculating usable hosts 2n – 2? Because it is neverpossible to assign a host an address with all 0 or all 1 bits in the host portionof the address. These are reserved for the subnet and broadcast addresses,respectively. Thus, every time a network is subnetted, useable host addressesare lost.The 2n-2 Rule and Subnetted NetworksTo avoid confusion, it was historically unacceptable to use the first and lastnew networks created when subnetting, as it is possible for a classfulnetwork to have the same subnet and broadcast address as its subnettednetworks. This required the 2n – 2 formula to also be used when calculatingthe number of new networks created while subnetting.However, this is no longer a restriction for modern equipment and routingprotocols. Specifically, on Cisco IOS devices, the following command isnow enabled by default:Router(config)# ip subnet-zeroThe ip subnet-zero commands allows for the use of networks with all 0 or all1 bits in the stolen network portion of the address. Thus, the fo