# IP ADRESSING ## Introduction Layer 2 address -> Burned into each NIC by the manufacturer Layer 3 address -> Assigned by the network administrator **IP Address**: 1.2 (1=Network number, 2=Host number) **IP** * Most common Layer 3 protocol * Transmits data from a source network device to a destination network device * Performs other services such as fragmentation and reassembly of data ## The Internet Protocol ![](https://i.imgur.com/qgAkyww.jpg) ![](https://i.imgur.com/JFAeGrE.jpg) *Version*: 4-bit field (IP version). For IPv4, this field has a value of 4 *IP Header Length*: 4-bit field indicates the length of the IP header (20-24 octets) *DiffServ (ToS)*: 8-bit field was originally called the Type of Service. Used as a method of adding Quality of Service (QoS) to IP networks. *Total length*: 16-bit field specifies the entire packet size in octets *Identification*: 16-bit field, used for uniquely identifying fragments of an original IP datagram. Used together with Flags and Fragment Offset *Flags*: 3-bit field is used to control or identify fragments. *Fragment Offset*: 13-bit field specifies the offset (8 octets), of a particular fragment relative to the beginning of the original un-fragmented IP datagram. The first fragment has an offset of 0. *TTL*: Used to prevent packets from persisting indefinitely on a network, this 8-bit field is set to a number, commonly 64, when the packet is created. Each router that a packet crosses decrements the TTL field by one. When the TTL field reaches zero, the router discards the packet and sends an error message to the sending device. *Protocol*: 8-bit field specifies the number of the Layer 4 protocol used in the data portion of the packet. Ex: 6 for TCP, 17 for UDP, 1 for ICMP *Header checksum*: 16-bit field is used for error correction for just the IP header *Source IP Address*: Specifies the 32-bit IP address of the originator of the IP packet *Destination IP Address*: Specifies the 32-bit IP address of the destination of the IP packet. *Options*: This optional, variable length field is used primarily for testing and troubleshooting. Routers use addresses in binary format (8-bit). IP address doesn't clearly indicate which bits are network bits and which bits are host bits -> IP address have corresponding 32-bit **Network Mask/Address Mask/Subnet Mask** ![](https://i.imgur.com/ueyDdY5.jpg) ![](https://i.imgur.com/3YRV5Z8.jpg) If Network Mask = 1 -> Network Prefix If Network Mask = 0 -> Host Portion ## Working with Binary Numbers ![](https://i.imgur.com/VH8TqaN.jpg) ![](https://i.imgur.com/o4CXHfx.jpg) ## Working with Hexadecimal Numbers ![](https://i.imgur.com/eitJMVu.jpg) ![](https://i.imgur.com/WuxqrbZ.jpg) ![](https://i.imgur.com/dnE3eQF.jpg) ![](https://i.imgur.com/7oFS7bQ.jpg) The broadcast MAC address: ffff.ffff.ffff When displayed as a binary number, the broadcast MAC address consists of 48 bits set to one ## IP Network Masks **IP Address:** 192.168.1.8 **Network mask:** 255.255.255.0 **Network:** 192.168.1.0 Representing network mask in decimal form can caused confusion, because network mask isn't actually an address. Solution: **CIDR Notation**: 192.168.1.8/24 24 shows number of Bits in Network Prefix 192.168.1.0/24 identifies the address range starting at 192.168.1.0 and continuing through 192.168.1.255 192.168.1.8/16 -> Network number is 192.168.0.0 192.168.1.8/24 -> Network number is 192.168.1.0 ### Classful and Classless Routing and CIDR Notation Originally IP network address always fell in octet boundary. **CLASSFULL** ![](https://i.imgur.com/CQjbXzZ.jpg) ![](https://i.imgur.com/jwXwepI.jpg) To reduce the size of routing tables, CIDR provides a way to summarize many "classful" network numbers into a single routing table entry ![](https://i.imgur.com/6J9g7G6.jpg) To check whether the destination is in the same network, the decimal IP address will be converted to binary, and if it is the same, the data can be sent directly If it's not in the same network, PCs send the data to the default gateway ![](https://i.imgur.com/vk6KIdQ.jpg) Network number: 192.168.1.0 Broadcast address: 192.168.1.255 Therefore, Valid Host numbers: 192.168.1.1 through 192.168.1.254 Calculationg the Number of Valid Hosts: ![](https://i.imgur.com/hIqHF9M.jpg) In a /24 network, there are 24 network bits and 8 host bits ![](https://i.imgur.com/9yxLL0l.jpg) There are 254 valid host numbers in a /24 network ### IP Subnetting **IP Subnetting**: Taking a single network number and splitting it into smaller networks or subnets (sub-networks) ![](https://i.imgur.com/Zx1lIMN.jpg) To create subnet, change the mask to each broadcast domain. More network bits means fewer hosts per network. More host bits means more hosts with fewer networks How changing the size of the mask impacts the number of networks and the number of hosts possible in each network. |Subnet portion (7 bits of network)| Host portion (1 bit of Hosts/Network)| | -------- | -------- | | 1 |254 | |2|126 |4|62 |8|30 |16|14 |32|6 |64|2 |128|0 You can only change the size of the network mask within the last octet of the address range. Once you've been assigned a specific network range, you can only make the network prefix length longer, not shorter, because other networks will also be using the first 24 bits. ![](https://i.imgur.com/iW1CgQF.jpg) Using 4 bits for the network provides 2^4 or **16 networks** Valid Subnets: 0000 through 1111 Using 4 bits for the host provides (2^4)-2 or **14 host addresses** Valid Hosts: 0001 through 1110 (0000 and 1111 are reserved) ![](https://i.imgur.com/kyX4Yah.jpg) The decimal equivalent for this last octet is 128+64+32 = 224 The full subnet mask is 255.255.255.224 **If Network Prefix falls on an Octet Boundary** ![](https://i.imgur.com/pcg7mdl.jpg) **If Network Prefix not fall on an Octet Boundary** -> It is impossible to determine actual Subnet Number without the mask How can we tell if each of these is a subnet number or an individual host. ![](https://i.imgur.com/aXXTxKV.jpg) Example: 192.168.3.60/27 wants to communicate with 192.168.3.66. ![](https://i.imgur.com/F1SkJ3R.jpg) 27-bit mask, the source PC subnet and the destination PC subnet aren't the same. Because Source PC and Destination PC aren't on the same network, they must use a router to communicate. Assigned Network Range 192.168.3.0/24 Subnet and Host Ranges (27-bit mask) ![](https://i.imgur.com/NGcK8gv.jpg) ![](https://i.imgur.com/3xCjIxq.jpg) ![](https://i.imgur.com/vnl6xkY.jpg) ## IP Address Assignment * Jon Postel was the first to maintain a list of assigned network addresses. * The Internet Assigned Numbers Authority (IANA) was established to centrally manage the global IP address space. * IANA works through Regional Internet Registries (RIRs): ARIN, RIPE NCC, APNIC, LACNIC, AfriNIC * Internet Corporation for Assigned Names and Numbers (ICANN) was formed to be responsible for all IP address assignment and domain name registration. IANA is now part of ICANN. * A device uses the loopback interface to send a message back to itself (commonly used for troubleshooting and network testing). A PC can communicate with local server without an actual network (uses its loopback address) Loopback Address Space: 127.0.0.0-127.255.255.255 * Multicast IP address is similar as multicast MAC address * Devices use multicast IP addresses to send the same data to a specific group of devices ## IP Protocol Operations ![](https://i.imgur.com/y2pu0PO.jpg) **192.168.1.2 wants to send data to 192.168.1.8** 1. PC wants to know if it's on the same network. It uses the network prefix length to determine its own network number and the network number for the destination address 2. It's on the same network. So, no need a router. (Direct routing) 3. Sending PC needs to determine the MAC address of destination PC. (ARP request on the same network) 4. Destination PC responds and sends its MAC address 5. Communicate! **192.168.1.2 wants to send data to 192.168.3.2** 1. PC wants to know if it's on the same network. It uses the network mask to extract the network number for the destination IP address. 2. It's on the different networks. Router is needed! (Indirect routing) 3. PC encapsulate the packet and the frame address to its default gateway. IF sending PC doesn't know the destination PC MAC's address -> ARP request 4. Sending PC sent data to the router. Switch uses MAC address table to forward data. 5. Router receive the frame, first router will examine the destination MAC address. If it's so, router will strip off the Layer 2 frame (inspect the destination IP address). 6. Look in the Routing Table to see if it has a match for this address 7. Routers use static routes and dynamic routing protocols such as OSPF or IS-IS to learn about remote networks and build their routing tables 8. Destination IP address might match multiple entries in the Routing Table, each with different prefix/length. Routers always look for the best match for the destination IP address. The best match is the match with the longest prefix length. #Layer 3 -> Literally source and destination IP Address #Layer 4 -> Hop to hop (router) ![](https://i.imgur.com/XRyWGVo.jpg) ## Longest Match Routing 192.168.1.5 wants to send data to 192.168.3.36 **Route summarization** or **route aggregation** combines a group of network number to a single route -> more efficient The closer the packets to the destination, routing table become more spesific ![](https://i.imgur.com/bsmgMOp.jpg) Router uses 4th entry tp forward packets because it's the longest match 192.168.0.0/16 represents the address range 192.168.0.0 through 192.168.255.255. While the destination fall within this range, the router will try to find a better match using more bits. This address range, which is an example of a CIDR supernet, is actually the combination of many other address ranges that are located at corporate headquarters. Ex: - 192.168.1.0/24 - 192.168.5.0/24 - 192.168.10.0/24 Compare each routing table with the destination address. Does the network portion of the address match or not. ![](https://i.imgur.com/znnRLBS.jpg) ## Fragmentation IP -> Delivers packet between devices. IP packet is encapsulated in Layer 2 frame. But before that, packet size will be checked by router. *Maximum Transmission Unit (MTU)*: Fixed upper limit on the size of packet can be sent in a single frame. ![](https://i.imgur.com/8bRaLW2.jpg) If the packet is bigger than the Layer 2 technology, device need to break it up into several fragments, send it individually per segments, and reassembled into origincal packet by the receiving device. ## IPv6 The number of available IPv4 has almost been exhausted. So, here come IPv6 (128-bit address). **IP Version 6 (IPv6)** Ex: 2001:db8:31:1:20a:95ff:fef5:246e The larger address size -> won't exhaust the supply of addresses IPv4 Header -> 20 to 60 bytes total IPv6 Header -> 40 bytes total ![](https://i.imgur.com/rU6AdWv.jpg) In 1Pv6, routers don't fragment IPv6 packets, hosts are responsible for this. Protocol also replaced with Nezt Header Field. ![](https://i.imgur.com/fvpghRd.jpg) These extentions are only examined by endpoint devices, not by routers, so it doesn't negate the gains in processing speed. ![](https://i.imgur.com/2S50rJm.jpg) There's one entirely new field, Flow Control (used to QoS management) **IPv6 Header** ![](https://i.imgur.com/4g68C3O.jpg) *Traffic Class*: 8-bit field used for traffic prioritization where devices support it *Flow Label*: 20-bit field used for quality-of-service (QoS) management *Payload Length*: 16-bit field specifies the payload size (octets), including the data and any extension headers *Next Header*: 8-bit field indicates the type of next encapsulated header, which may be if there are no extensions, the Layer 4 protocol (TCP , UDP, or ICMP) *Hop Limit*: Used to prevent packets from persisting indefinitely on a network, this 8-bit field is set to a number, commonly 64 when the packet is created. Each router that a packet crosses decrements the hop limit by one. When the Hop Limit field reaches zero, the router discards the packet and sends an error message to the sending device. In IPv4, Time-to-Live (TTL) field. ![](https://i.imgur.com/b7QkNpw.jpg) Also can be written: - 2bfc:0:0:0:0217:cbff:f38c:5c85 - 2bfc::217:cbff:f38c:5c85 - 2BFC::217:CBFF:F38C:5C85 (not case sensitive) Double colon can replace consecutive zeros, leading zeros, or trailing zeros. Can't use a double colon twice in an address notation. Key requirements outlined in RFC 5952: * Leading zeros must be suppressed * Symbol "::" must be used to its max capacity * Characters a,b,c,d,e,f must be lowercase * Symbol "::" must NOT be used to shorten just one 16-bit field * When alternative choice exists in the placement of a "::", the longest run of consecutive 16-bit 0 fields must be shorthened ![](https://i.imgur.com/tHrjNm8.jpg) * When the length of the consecutive 16-bit fields are equal, the first sequence of zero bits must be shortened Systems able to accept and handle any legitimate IPv6 format ![](https://i.imgur.com/LUEzH0H.jpg) **IPv6 SUBNETTING** ![](https://i.imgur.com/lnlxZf4.jpg) Global routing prefix doesn't change. ![](https://i.imgur.com/OK7nCRh.jpg) First address ends with 001, not 000. The first address in a subnet is the **anycast address**. A packet sent to this address will be routed to the nearest interface in that subnet. IPv6 doesn't use broadcast, use the lasd address in the subnet.