IP addressing, introduction to IP addresses and subnetting methods

  • The network layer is located between the data link layer and the transport layer. The network layer contains many protocols, the most important of which is the IP protocol. The network layer provides IP routing functionality. To understand IP routing, in addition to being familiar with the working mechanism of the IP protocol, you must also understand IP addressing and how to rationally use IP addresses to design networks.

Upper layer protocol type

  •  The Type field value in the Ethernet frame is 0x0800 , indicating that the network layer protocol of the frame is the IP protocol.
  • Before stripping off the header and trailer of the frame, the network device needs to determine which upper-layer protocol to send the frame to for processing based on the Type field in the frame header. The Type field in the frame header in this example indicates that the frame needs to be sent to the IP protocol for processing. The following will introduce how the IP protocol handles the data in the frame after the header and trailer of the frame are stripped off.

IP message header

  • IP packet header information is used to guide network devices to route and fragment packets. Data forwarding within the same network segment can be achieved through the link layer, while data forwarding across network segments requires the routing function of the network device. Fragmentation means that when a data packet exceeds a certain length, it needs to be divided into different fragments so that it can be transmitted on the network.
  • The length of the IP packet header is 20 to 60 bytes. The information in the packet header can be used to instruct the network device on how to send the packet from the source device to the destination device. Among them, the version field indicates the currently supported IP protocol version, and the current version number is 4 . The DS field was used to indicate the service type in the early days, and is now used to support the differentiated service model in QoS to optimize network traffic.
  • Source and destination IP addresses are logical addresses assigned to hosts and are used to identify the sender and receiver of messages at the network layer. Based on the source and destination IP addresses, you can determine whether the destination is in the same network segment as the sending end. If they are not in the same network segment, a routing mechanism needs to be used for cross-network segment forwarding.

IP addressing

  • An IPv4 address is a 32- bit binary number, usually expressed in dotted decimal notation. IP addresses are used to identify devices on the network. Devices with IP addresses can communicate within the same network segment or across network segments. The IP address consists of two parts. The first part is the network number, which indicates the network segment to which the IP address belongs. The second part is the host number, which is used to uniquely identify a network device on this network segment.

 

  • There are two special addresses on each network segment that cannot be assigned to hosts or network devices. The first one is the network address of the network segment. The host bits of the IP address are all 0 , indicating a network segment. The second address is the broadcast address in this network segment. Messages whose destination address is the broadcast address will be received by all network devices in this network segment. The host bits of the broadcast address are all ones . In addition to the network address and broadcast address, other IP addresses can be used as the IP address of the network device .

Binary, decimal and hexadecimal

  • Data in the network can be represented in binary, decimal or hexadecimal systems. Understanding these systems is necessary to understand the basics of IP networks. Each base uses a different base value to represent the value of each digit. Each bit of binary has only two values: 0 and 1 , and the base value is 2. Each bit of a binary number can be represented by 2 raised to the power of x , where x represents the number of digits in the binary number. Each digit of hexadecimal can have 16 values, ranging from 0-F (that is, 0-9 and AF ), A corresponds to 10 in decimal , and F corresponds to 15 in decimal ( 1111 in binary ).

Convert between bases

  • The IP address is divided into four segments in bytes. Each byte contains 8 bits and can represent 0 to 255 , a total of 256 values. You can see the decimal number represented by each binary number in the binary to decimal conversion table. The table above illustrates the conversion of 8 -bit binary numbers into decimal and hexadecimal numbers. From the table, you can also see the decimal and hexadecimal numbers corresponding to all 0s and all 1s .

Binary and decimal conversion

  • The 32 -bit IP address is divided into 4 bytes, and each byte has 256 values. Therefore, theoretically IPv4 can have 4,294,967,296 IP addresses , but in fact only some of them can be allocated to network devices. In this example, the first three bytes of the IP address represent the network number, and the last byte represents the address range available for network devices on the network. When converting an IP address in binary format to decimal format, you need to add the values ​​represented by each bit 1 in the binary to obtain the decimal value of the IP address.

IP address classification

  • IPv4 addresses are divided into five categories: A , B , C , D , and E. The network number of each type of address contains a different number of bytes. Class A , Class B and Class C addresses are assignable IP addresses. Each type of address supports a different number of networks and hosts. For example, Class A addresses can support 126 networks, and each network supports 224 ( 16,777,216) host addresses. In addition, the network address and broadcast address in each network segment cannot be assigned to hosts. Class C addresses support more than 2 million networks. Each network supports 256 host addresses, of which 254 addresses can be assigned to hosts.
  • Class D addresses are multicast addresses. After a host receives a message with a Class D address as the destination address, and the host is a member of the multicast group, it will receive and process the message. Various types of IP addresses can be distinguished by the bits in the first byte. For example, the highest bit of the first byte of a Class A address is fixed to 0 , the high two bits of the first byte of a Class B address are fixed to 10 , the high three bits of the first byte of a Class C address are fixed to 110 , and the first word of a Class D address is fixed The high-order four bits of the section are fixed to 1110 , and the high-order four bits of the first byte of the Class E address are fixed to 1111 .

IP address type

  • Some IP addresses in IPv4 are reserved for special purposes. In order to save IPv4 addresses, a specific range of addresses is reserved in class A , B , and C address segments as private network addresses. The total number of IP addresses required by all end systems and network devices in the world now exceeds the maximum number of addresses supported by 32 -bit IPv4 addresses , 4,294,967,296 . Assigning private network addresses to hosts saves public network addresses and can be used to alleviate the problem of IP address shortage. Private network addresses are commonly used in corporate networks, and private network addresses in different corporate networks can overlap. By default, hosts in the network cannot use private addresses to communicate with the public network; when they need to communicate with the public network, the private addresses must be converted into public addresses. There are also some other special IP addresses, such as the address in the 127.0.0.0 network segment, which is a loopback address and is used to diagnose whether the network is normal. The first address 0.0.0.0 in IPv4 represents any network. The role of this address will be introduced in detail in Routing Principles. The last address in IPv4 , 255.255.255.255 , is the broadcast address in the 0.0.0.0 network. 

Telecommunication

  • The source host must know the IP address of the destination host before it can send data to the destination. Before the source host sends a message to other destination hosts, it needs to check whether the destination IP address and the source IP address belong to the same network segment. If so, the message will be delivered to the underlying protocol for Ethernet encapsulation processing. If the destination address and source address belong to different network segments, the host needs to obtain the IP address of the next-hop router and then deliver the packet to the underlying protocol for processing.

subnet mask

  • The subnet mask is used to distinguish the network part from the host part. Subnet masks are expressed in the same way as IP addresses. Each IP address and subnet mask together can be used to uniquely identify a certain network device in a network segment. The 1 in the subnet mask represents the network bit, and the 0 represents the host bit. 

Default subnet mask

  • Each type of IP address has a default subnet mask. The default subnet mask for a Class A address is 8 bits, that is, the first byte represents the network bits, and the other three bytes represent the host bits. The default subnet mask of Class B addresses is 16 bits, so Class B addresses support more networks, but the number of hosts is also reduced accordingly. The default subnet mask of Class C address is 24 bits, which supports the largest number of networks and also limits the number of hosts in a single network. 

Address planning

  • The subnet mask can be used to determine the network segment to which the host belongs, the broadcast address on the network segment, and the number of hosts supported on the network segment. In the example in the figure, the host address is 192.168.1.7 and the subnet mask is 24 bits ( the default mask for Class C IP addresses). From this we can determine that the host is located in the 192.168.1.0/24 network segment. Set all the host bits in the IP address to 1 and convert them to decimal numbers to get the broadcast address of the network segment 192.168.1.255 . The number of hosts supported in the network segment is 2n , and n is the number of host bits. In this example, n=8 , 28=256 , subtracting the network address and broadcast address of this network segment, it can be seen that this network segment supports 254 valid host addresses.

Address planning example

  • Based on the given IP address and subnet mask, please calculate the number of host addresses contained in this network and the number of available host addresses.
  • This example shows how to determine the network segment to which the host belongs, the broadcast address in the network segment, and the number of valid host addresses based on the Class B IP address and its subnet mask. The judgment process is similar to that of Class C addresses.

Disadvantages of IP -like addressing

  • Using classful IP addresses when designing a network will cause a waste of addresses. 
  • If the enterprise network wants to isolate hosts on the physical network by planning multiple network segments, there will be certain limitations in using the default subnet mask. After the network is divided into multiple network segments, the actual number of hosts in each network segment may be very limited, resulting in many unused addresses. In the scenario shown in the figure, if the addressing scheme with the default subnet mask is used, the address usage rate is very low.

variable length subnet mask

  • The above problems can be solved by using variable length subnet mask. The default subnet mask can be further divided into variable length subnet masks ( VLSM ). By changing the subnet mask, the network can be divided into multiple subnets. The address in this example is a Class C address, and the default subnet mask is 24 bits. Now a host bit is borrowed as a network bit, and the borrowed host bit becomes a subnet bit. A subnet bit has two values ​​0 and 1 , so it can be divided into two subnets. If this bit is set to 0 , the subnet number is 0. If this bit is set to 1 , the subnet number is 128. Set the remaining host bits to 0 to obtain the divided subnet address; set the remaining host bits to 1 to obtain the broadcast address of the subnet. The number of hosts supported in each subnet is 27-2 (minus the subnet address and broadcast address), which is 126 host addresses.

Variable length subnet mask example

  • The variable-length subnet mask alleviates the address waste problem caused by using the default subnet mask, and also provides a more effective addressing scheme for enterprise networks. In this example, a variable-length subnet mask needs to be used to divide multiple subnets. While a certain number of host bits are borrowed as subnet bits, the remaining host bits must ensure that there are enough IP addresses for all hosts on each subnet.

Classless inter-domain routing

  • Classless Inter Domain Routing CIDR ( Classless Inter Domain Routing ) is defined by RFC1817 . CIDR breaks through the classification boundaries of traditional IP addresses and aggregates several routes in the routing table into one route, reducing the size of the routing table and improving the scalability of the router.
  • As shown in the figure above, an enterprise is assigned a class A network address, 10.24.0.0/22 . The company plans to allocate these Class A networks to various user groups, and has currently allocated four network segments to users. If CIDR technology is not implemented, there will be four routing entries for downstream network segments in the routing table of the enterprise router, and they will be advertised to other routers. By implementing CIDR technology, we can aggregate these four routes 10.24.0.0/24 , 10.24.1.0/24 , 10.24.2.0/24 , 10.24.3.0/24 into one route 10.24.0.0/22 ​​on the enterprise's router . In this way, the enterprise router only needs to advertise the route 10.24.0.0/22 , which greatly reduces the size of the routing table.

gateway

  • During the packet forwarding process, you first need to determine the forwarding path and the interface leading to the destination network segment, and then encapsulate the packet in an Ethernet frame and forward it through the designated physical interface. If the destination host and the source host are not in the same network segment, the packet needs to be forwarded to the gateway first, and then the packet is forwarded to the destination network segment through the gateway.
  • A gateway refers to a device that receives and processes packets sent by hosts in the local network segment and forwards them to the destination network segment. To implement this function, the gateway must know the IP address of the destination network segment. The interface address on the gateway device connected to the local network segment is the gateway address of the network segment.

IP packet fragmentation

  • The length of IP packets forwarded in the network can be different, but if the length of the packet exceeds the maximum length supported by the data link, the packet needs to be divided into several smaller fragments before it can be transmitted on the link. The process of splitting a message into multiple fragments is called fragmentation.
  • The receiving end reassembles the fragmented message based on the Identification , Flags , and Fragment Offset fields in the fragmented message. The identifier is used to identify fragments belonging to the same data packet to distinguish them from other data packet fragments sent by the same host or other hosts to ensure that the fragments are correctly reassembled. The flag field is used to determine whether the last fragment has been received. The flag field of the last fragment is set to 0 , and the flag fields of other fragments are set to 1. After receiving the fragment with the flag field set to 0 , the destination begins to reassemble the message. The fragment offset field indicates the position of each fragment in the original message. The slice offset of the first slice is 0 , and the slice offset of the second slice represents the position of the first bit immediately following the first slice. For example, if the first fragmented message contains 1259 bits, then the fragment offset field value of the second fragmented message should be 1260 .

survival time

  • When packets are forwarded between network segments, if the routing planning on the network device is unreasonable, loops may occur, causing the packets to loop endlessly in the network and fail to reach the destination. After a loop occurs, all packets sent to this destination will be forwarded in a loop. As the number of such packets gradually increases, network congestion will occur.
  • To avoid network congestion caused by loops, the IP packet header contains a TTL ( Time To Live ) field. Every time a packet passes through a layer 3 device, the TTL value is reduced by 1. The initial TTL value is set by the source device. When the TTL in the packet drops to 0 , the packet will be discarded. At the same time, the device that discarded the packet will send an ICMP error message to the source based on the source IP address in the packet header .

Agreement number

  • After receiving and processing the message, the network layer at the destination needs to decide what to do with the message in the next step. The protocol field in the IP header identifies the protocol that will continue to process the message. Similar to the Type field in the Ethernet frame header , the protocol field is also a hexadecimal number. This field can identify network layer protocols, such as ICMP ( Internet Control Message Protocol , Internet Control Message Protocol), or upper-layer protocols, such as TCP ( Transmission Control Protocol, corresponding value 0x06 ), UDP ( User Datagram Protocol) , User Data Packet Protocol, corresponding value 0x11 ). 

Chapter summary

Q: What is the role of subnet mask?

Answer: The 32-bit IP subnet mask is used to distinguish the network number and host number in the IP address. The network number represents the network or subnet, and the host number represents the host in the network or subnet.

Q: What is the role of the TTL field in the IP packet header ?

Answer: If there is a loop in the network, the IP packet may loop in the network and fail to reach the destination. The TTL field limits the lifetime of IP packets, ensuring that packets that cannot reach the destination are eventually discarded.

Q: What is the role of the gateway?

Answer: A gateway refers to a device that receives and processes packets sent by hosts in the local network segment and forwards them to the destination network segment.

Guess you like

Origin blog.csdn.net/yy123cisco/article/details/135179628