[HCIA] 04. Network layer protocol and IP addressing

  • The IPv4 (Internet Protocol Version 4) protocol family is the core protocol family in the TCP/IP protocol family. It works at the network layer of the TCP/IP protocol stack, which corresponds to the network layer of the OSI reference model.
  • The network layer provides connectionless data transmission services, that is, the network does not need to establish a connection before sending data packets, and each IP data packet is sent independently.

network layer protocol

  • The network layer is often referred to as the IP layer. But the network layer protocol is not just the IP protocol, but also includes ICMP (Internet Control Message Protocol) protocol, IPX (Internet Packet Exchange) protocol, etc.

IP protocol

  • IP is the abbreviation of Internet Protocol. Internet Protocol itself is the name of a protocol file. The content of this protocol file is very small, mainly defining and expounding the format of IP packets.
  • IP, which is often mentioned, generally does not specifically refer to the Internet Protocol, the protocol document itself, but refers to any content related to the IP protocol in general or indirectly.

The IP protocol has versions, namely IPv4 and IPv6. Currently, the IP packets on the Internet are mainly IPv4 packets, but they are gradually transitioning to IPv6. Unless otherwise stated, the IP mentioned in this chapter refers to IPv4.

The IPv4 (Internet Protocol Version 4) protocol suite is the core protocol suite in the TCP/IP protocol suite. It works at the network layer of the TCP/IP protocol stack, which corresponds to the network layer of the OSI reference model.

IPv6 (Internet Protocol Version 6) is the second-generation standard protocol of the network layer protocol, also known as IPng (IP Next Generation). It is a set of specifications designed by the Internet Engineering Task Force (IETF) and is an upgraded version of IPv4 (Internet Protocol Version 4).

IP header message

  • The IP header line is 4 bytes, 32 bits
  • The default is 20 bytes, and the IP header ranges from 20-60 bytes
  • The TTL field sets the number of routers the packet can pass through.
  • Once passing through a router, the TTL value will be decremented by 1, and when the value of this field is 0, the packet will be discarded.
  • message explanation
    • Version: version identification 4 bits
    • Header Length: The length of the header is 4 bits
      • The binary multiplication of the header length by 4 is the real length, if it is not a multiple of 4, use padding to make up
    • Type of service: service level 8 bits
    • Total Length: The total length of the message is 16 bits
    • Identification: fragment id
    • Flags: Fragmentation flag
    • Fragment Offset: slice offset
    • TTL: TTL value, life time, defines how far the life cycle can go at most, and is used for ring release
    • Protocol: To determine which protocol the data packet is sent to the upper layer
      • 1:ICMP
      • 6:TCP
      • 17:UDP
      • 89:OSPF
    • Header Checksum: header checksum
    • Source IP Address: source IP address
    • Destination IP Address: destination IP address
    • padding: padding fields, meaningless data

binary calculation

  1. First list 128, 64, 32, 16, 8, 4, 2, 1
  2. Then compare a decimal number from left to right
  3. If it is greater than or equal to the number compared, it will be marked with 1, and if it is less than, it will be marked with 0
  4. If it is greater than or equal to the mark, subtract the number compared with it, continue to compare to the right, and so on
  5. The binary number from left to right is the converted binary

What is an IP address

  • The IP address is used to identify a node (or interface of a network device) in the network
  • IP addresses are used to address IP packets in the network

On an IP network, if a user wants to connect a computer to the Internet, he needs to apply for an IP address. An IP address is like an address in reality, it can identify a node in the network through which data finds its destination. That is, we realize global network communication through IP addresses.

The IP address is an attribute of the interface of the network device, not the attribute of the network device itself. When we talk about assigning an IP address to a certain device, we actually mean assigning an IP address to an interface of this device. If the device has multiple interfaces, each interface usually requires at least one IP address.

Note: The interface that needs to use the IP address is usually the interface of the router and the computer.

IP address representation

  • An IP address consists of a network address and a host address
  • An IPv4 address has 32bit
  • IPv4 addresses are usually expressed in "dotted decimal"
  • IPv4 address range: 0.0.0.0~255.255.255.255

  • IP address representation
    • The IP address is 32 bits in length and consists of 4 bytes. For the convenience of reading and writing, IP addresses are usually expressed in dotted decimal notation.
  • dotted decimal notation
    • The expression form of IP address can help us better use and configure the network, but the communication equipment uses the binary operation mode when calculating the IP address, so it is very necessary to master the decimal and binary conversion operations.
  • IPv4 address range
    • 00000000.00000000.00000000.00000000~11111111.11111111.11111111.11111111, that is, 0.0.0.0~255.255.255.255.

IP address composition

  • Network part: Used to identify a network.
  • Host part: used to distinguish different hosts within a network.

  • Netmask: Distinguishing between the network part and the host part of an IP address.

  • An IPv4 address consists of the following two parts:
  • Network part (network number): used to identify a network.
    • The IP address cannot reflect any geographical information about the location of the host, and only the network number field can be used to determine which network the host belongs to.
    • For devices with the same network number, regardless of their actual physical location, they are all in the same network.
  • Host part (host number): used to distinguish different hosts within a network.
  • Netmask (Netmask), also known as subnet mask (Subnet Mask):
    • The network mask is 32 bits, which is the same as the number of bits in the IP address, and is usually expressed in dotted decimal notation.
    • The netmask is not an IP address. In binary representation, it is a bunch of consecutive 1s followed by a bunch of consecutive 0s.
    • The number of 1s in a netmask is usually referred to as the length of the netmask. For example: the length of mask 0.0.0.0 is 0, and the length of mask 252.0.0.0 is 6.
    • The network mask is generally used in combination with the IP address, where the bit with a value of 1 corresponds to the network bit in the IP address; the bit with a value of 0 corresponds to the host bit in the IP address, so as to help us identify the network bit in an IP address with the host bit. That is, the number of 1s in the network mask is the number of digits of the network number of the IP address, and the number of 0s is the number of digits of the host number of the IP address.

IP addressing

  • The network number is used to indicate the network where the host is located, similar to the role of "XX District, XX City, XX City, XX Province".
  • The host number is used to indicate a specific host interface within the network range defined by the network number, which is similar to the role of the house number "XX Building XX".
  • Network addressing:
    • Layer 2 network addressing: The corresponding host interface can be found directly through the IP address.
    • Layer 3 network addressing: use the gateway to forward data packets from different network segments.
  • Gateway:
    • During packet forwarding, the forwarding path and the interface leading to the destination network segment need to be determined first. If the destination host is not on the same network segment as the source host, 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 is a device that receives and processes packets sent by hosts on the local network segment and forwards them to the destination network segment. In order to realize this function, the gateway must know the IP address of the destination network segment. The address of the interface connected to the local network segment on the gateway device is the gateway address of the network segment.

IP address classification (classified)

  • In order to facilitate the management and networking of IP addresses, IP addresses are divided into five categories:

  • Class A/B/C default netmask
    • Type A: 8 bits, 0.0.0.0~127.255.255.255/8
    • Type B: 16 bits, 128.0.0.0~191.255.255.255/16
    • Type C: 24 bits, 192.0.0.0~191.223.255.255/24

In order to facilitate the management and networking of IP addresses, IP addresses are divided into five categories:

  1. The category fields of categories A, B, C, D, and E are binary numbers 0, 10, 110, 1110, and 1111 respectively. The first few bits of the network number field can determine which category the IP address belongs to. The easiest way to class address.
  2. The three types of addresses A, B, and C are unicast IP addresses (except some special addresses), and only these three types of addresses can be assigned to the host interface.
  3. Class D addresses are multicast IP addresses.
  4. Class E addresses are reserved for special experimental purposes.
  5. In this section, we only focus on the three types of addresses A, B, and C.

Comparison of A, B, and C addresses:

  1. A network using class A addresses is called a class A network; a network using class B addresses is called a class B network; a network using class C addresses is called a class C network.
  2. The network number of a class A network is 8 bits, the number is small, but the number of allowed host interfaces is large; the first bit is always 0, and the address space is: 0.0.0.0~127.255.255.255.
  3. The network number of Class B network is 16 bits, which is between Class A and Class C networks; the first two digits are always 10, and the address space is: 128.0.0.0~191.255.255.255.
  4. The network number of a class C network is 24 bits, and there are many, but the number of host interfaces allowed is very small; the first three bits are always 110, and the address space is: 192.0.0.0~223.255.255.255.

Note:

Host (Host), usually refers to the collective name of routers and computers. And the IP address of an interface of the host is often referred to as the host IP address for short.

Multicast address: Multicast can realize one-to-many message delivery.

IP address type

  • website address
    • The network number is X, and each bit of the host number is 0.
    • It cannot be assigned to a specific host interface for use.

  • broadcast address
    • The network number is X, and each bit of the host number is 1.
    • It cannot be assigned to a specific host interface for use.

  • available address
  • Also known as the host address, it can be assigned to a specific host interface for use.
  • Calculation of the number of available addresses in a network segment:
  • If the number of host bits in a network segment is n bits, the number of IP addresses is: 2ⁿ, and the number of available IP addresses is: 2ⁿ-2 (minus the network address and broadcast address).

IP address calculation

  • Example: What are the network address, broadcast address, and available addresses of the class B address 172.16.10.1/16?

  • Network address: Set all the host bits of the network address to 0, and the result is the network address of the network where the IP address is located.
  • Broadcast address: Set all the host bits of the network address to 1, and the result is the broadcast address of the network where the IP address is located.
  • Number of P addresses: 2ⁿ, n is the number of host bits.
  • Number of available IP addresses: 2ⁿ-2, n is the number of host bits.
  • Answers to practice questions:
    • Network address: 10.0.0.0/8
    • Broadcast address: 10.255.255.255
    • Number of IP addresses: 224
    • Number of available IP addresses: 224-2
    • Available IP address range: 10.0.0.1/8~10.255.255.254/8

Private network IP address

  • Public IP address: IP addresses are uniformly assigned by IANA to ensure the uniqueness of any IP address on the Internet. The IP address here refers to the public network IP address.
  • Private network IP address: In fact, some networks do not need to be connected to the Internet, such as the network in a closed laboratory of a university, as long as the IP addresses of network devices in the same network do not conflict. In the IP address space, some addresses are reserved in each of the three types of addresses A, B, and C, which are called private network IP addresses.
    • Class A: 10.0.0.0~10.255.255.255/8
    • Class B: 172.16.0.0~172.31.255.255/12
    • Class C: 192.168.0.0~192.168.255.255/16
  • In order to solve the problem of IP address shortage, the concept of private address was proposed. Private addresses refer to internal network or host addresses, which can only be used in a certain internal network and cannot be used in public networks.
    • Public IP address: A network device connected to the Internet must have a public IP address assigned by ICANN.
    • Private network IP address: The use of private network IP addresses allows the network to be expanded more freely, because the same private network IP address can be reused in different private networks.
  • Private network connected to the Internet: Since the private network uses a private network IP address, it is not allowed to connect to the Internet. Later, driven by actual needs, many private networks also hope to be able to connect to the Internet, so as to realize the communication between the private network and the Internet, and realize the communication between the private network and the private network through the Internet. The interconnection between the private network and the Internet must be implemented using Network Address Translation (NAT) technology.
  • Note:
    • NAT (Network Address Translation), network address translation, its basic function is to realize the conversion between the private network IP address and the public network IP address.
    • IANA (Internet Assigned Numbers Authority), the Internet Assigned Numbers Authority.

special IP address

  • 255.255.255
    • This address is called a limited broadcast address, and it can be used as the destination IP address of an IP packet.
    • After receiving an IP packet whose destination IP address is a limited broadcast address, the router stops forwarding the IP packet.
  • 0.0.0.0
    • If this address is used as a network address, it means the network address of "any network"; if this address is used as a host interface address, it means the IP address of "a host interface on this network".
    • For example: when a host interface has not obtained its own IP address during the startup process, it can send a DHCP request message to the network with the destination IP address as the limited broadcast address and the source IP address as 0.0. After your own request, you can assign yourself an available IP address.
  • 127.0.0.0/8
    • This address is a loopback address, which can be used as the destination IP address of an IP message. Its role is to test the software system of the device itself.
    • It is impossible for an IP packet generated by a device and whose destination IP address is the loopback address to leave the device itself.
  • 169.254.0.0/16
    • If a network device is set to obtain an IP address automatically, but the device does not find an available DHCP server on the network, then the device will use an address in the 169.254.0.0/16 network segment to obtain the IP address. Temporary correspondence.
  • Note: DHCP (Dynamic Host Configuration Protocol), a dynamic host configuration protocol, is used to dynamically allocate network configuration parameters, such as IP addresses.

IPv4 vs IPv6

  • The IPv4 addresses managed by the global IP address assignment agency, IANA (Internet Assigned Numbers Authority), were completely exhausted in 2011. With the allocation of the last IPv4 public network address and the increasing number of users and devices accessing the public network, the problem of IPv4 address depletion is becoming more and more serious. This is the biggest driving force for IPv6 to replace IPv4.

Why subnetting

  • The address division of "classful addressing" is too rigid, and the division granularity is too large, so a large number of host numbers cannot be fully utilized, resulting in a large waste of IP address resources.
  • Therefore, subnetting can be used to reduce address waste, that is, VLSM (Variable Length Subnet Mask), variable length subnet mask. Divide a large classful network into several small subnets, making the use of IP addresses more scientific.

How to Divide Subnets - Original Network Segment Analysis

  • For example: 192.168.10.0/24 network segment

  • Suppose there is a class C network segment address: 192.168.10.0; by default, the netmask is 24 bits, including 24 network bits and 8 host bits.
  • It can be known by calculation that there are 256 IP addresses in such a network.

How to Subnet - Borrow from Host

  • Borrow bits from the host to form a subnet.
  • Variable length subnet mask, VLSM (Variable Length Subnet Mask)

  • Now, "borrow" 1 bit from the original 24-bit network bit to the host bit, so that the network bit is expanded to 25 bits, and the corresponding host bit is reduced to 7 bits, and the borrowed bit is the subnet bit , then the network mask becomes 25 bits, that is, 255.255.255.128, or /25.
  • Subnet bit: The value can be 0 or 1, and two new subnets are obtained.
  • Through calculation, we can know that there are 128 IP addresses in the network.

How to Subnet - Calculating Subnet Network Addresses

  • Calculate the network address, the host bits are all 0:
    • If the subnet bit has a value of 0, the network address is 192.168.10.0/25.
    • If the subnet bit has a value of 1, the network address is 192.168.10.128/25.

How to Subnet - Calculating the Subnet Broadcast Address

  • Calculate the broadcast address, the host bits are all 1:
    • If the subnet bit has a value of 0, the network address is 192.168.10.127/25.
    • If the subnet bit has a value of 1, the network address is 192.168.10.255/25.

Exercise: Calculating Subnets (1)

Exercise: Calculating Subnets (2)

  • The network addresses of the subnets are:
    • 192.168.1.0/28
    • 192.168.1.16/28
    • 192.168.1.32/28
    • 192.168.1.48/28
    • 192.168.1.64/28
    • 192.168.1.80/28
    • 192.168.1.96/28
    • 192.168.1.112/28
    • 192.168.1.128/28
    • 192.168.1.144/28
    • 192.168.1.160/28
    • 192.168.1.176/28
    • 192.168.1.192/28
    • 192.168.1.208/28
    • 192.168.1.224/28
    • 192.168.1.240/28

ICMP protocol

  • Internet Control Message Protocol ICMP (Internet Control Message Protocol) is an auxiliary protocol of the IP protocol.
  • The ICMP protocol is used to transmit various error and control information between network devices, and plays a vital role in collecting various network information, diagnosing and eliminating various network faults, etc.

  • In order to forward IP datagrams more efficiently and improve the chances of successful exchange of datagrams, the ICMP protocol is used at the network layer. ICMP allows hosts or devices to report error conditions and provide reports on abnormal conditions.
  • ICMP message:
    • ICMP messages are encapsulated in IP packets. When the value of Protocol in the IP packet header is 1, it indicates the ICMP protocol.
    • Field explanation:
  • The format of the ICMP message depends on the Type and Code fields, where the Type field is the message type, and the Code field contains the specific parameters of the message type.
  • The checksum field is used to check the integrity of the message.
  • The message contains 32-bit variable parameters. This field is generally not used and is usually set to 0.
  • −In the ICMP redirection message, this field is used to specify the IP address of the gateway, and the host redirects the message to the specified gateway according to this address.
  • −In the Echo request message, this field contains the identifier and sequence number, and the source side associates the received reply message with the Echo request message sent by the local side according to these two parameters. Especially when the source end sends multiple Echo request messages to the destination end, it is necessary to make a one-to-one correspondence between the Echo request messages and the reply messages according to the identifier and sequence number.

Basic configuration commands for IP addresses

  1. Enter interface view

  • Through this command, you can enter the specified interface view and configure related attributes of the interface.
  • interface-type interface-number : Specifies the interface type and interface number. Spaces may or may not be entered between the interface type and interface number.
  1. Configure the IP address of the interface

  • In the interface view, use this command to configure an IP address for an interface on a network device to realize network interconnection.
  • ip-address : Specifies the IP address of the interface in dotted decimal notation.
  • mask : Specifies the subnet mask in dotted decimal notation.
  • mask-length : specifies the length of the mask, in integer form, and the value range is 0 to 32.

Interface Introduction

  • Physical interface: The physical interface refers to the actual interface on the network device. It is divided into a service interface responsible for service transmission and a management interface responsible for device management, such as GE service interface and MEth management interface.
  • Logical interface: Logical interface refers to the interface that can realize the data exchange function but does not exist physically, and needs to be established through configuration, and needs to undertake service transmission, such as VLANIF interface and loopback interface.
    • Loopback interface: When the user needs an IP address of an interface whose status is always Up, the user can select the IP address of the loopback interface.
    • Once a loopback interface is created, its physical status and link protocol status are always Up, even if no IP address is configured on the interface.
    • After the IP address is configured on the loopback interface, it can be advertised externally. An IP address with a 32-bit mask can be configured on the loopback interface to save address space.
    • The loopback interface cannot encapsulate any link layer protocol, so there is no negotiation problem at the data link layer, and its protocol status is always Up.
  • The device discards packets whose destination address is not the local IP address and whose outbound interface is the local loopback interface.

Network IP address planning

  • IP address planning should be considered in combination with network structure, routing protocols, traffic planning, and service rules. The planning of IP addresses should correspond to the network level as much as possible, and should be a top-down planning.
  • In general: The goals of IP address planning are: easy to manage, easy to expand, and high utilization.

  • Planning Principles:
    • Uniqueness: In an IP network, no two hosts can use the same IP address.
    • Continuity: Consecutive addresses are easy to carry out route summarization in the hierarchical network, which greatly reduces the routing table, improves the efficiency of route calculation, and accelerates route convergence.
    • Scalability: Address allocation must be reasonably reserved at each level, and the continuity required for routing summary can be guaranteed when the network scale expands. Avoid address and route replanning caused by network expansion.
    • Structured and service-related: Address planning is combined with network topology and network bearer services to facilitate routing planning and QoS deployment. A good IP address planning makes each address have actual meaning, and you can roughly judge the device and corresponding service to which the address belongs when you see an address.

Guess you like

Origin blog.csdn.net/weixin_45988710/article/details/131523315