banner
leaf

leaf

It is better to manage the army than to manage the people. And the enemy.
follow
substack
tg_channel

Knowledge of IP

1. Understanding IP Addresses#

Basic Understanding of IP Addresses#

In the TCP/IP address reference model, it is located at the third layer, which is the network layer.

The main function of the network layer is to enable communication between hosts, also known as point-to-point (end-to-end) communication.

image

  • What is the relationship between the network layer and the data link layer? Some friends may find it difficult to distinguish between IP addresses (network layer) and MAC addresses (data link layer).

Actually, it is easy to differentiate. As we know, the function of an IP address is for communication between hosts, while the function of a MAC address is to enable communication between two devices that are "directly connected." The IP address is responsible for communication between two networks that are "not directly connected."

For example, if Xiao Lin wants to travel to a distant place, he creates an itinerary that requires taking a plane, subway, and bus to reach his destination. For this, Xiao Lin needs to buy plane tickets, subway tickets, etc.

Both plane tickets and subway tickets are for specific destinations, and each ticket can only move within a certain "interval." Here, "within the interval" is like the data link in a communication network.

Moving within the interval corresponds to the data link layer, acting as the transmission function between two nodes within the interval. The starting point within the interval is like the source MAC address, and the destination point is like the destination MAC address.

The entire travel itinerary is equivalent to the network layer, serving the function of remote positioning. The start of the journey is like the source IP address, and the end of the journey is like the destination IP address.

image

If Xiao Lin only has the itinerary but no tickets, he cannot take the transportation to reach his destination. Conversely, if he has tickets but no itinerary, it would also be difficult to reach the destination because Xiao Lin wouldn't know which vehicle to take or where to transfer.

Therefore, only by having both the tickets for a certain interval and the overall travel itinerary can one ensure reaching the destination. Similarly, in computer networks, both the "data link layer" and the "network layer" are needed to achieve communication to the final target address.

Another important point is that although we change transportation methods during the journey, the starting and destination addresses of the trip remain unchanged.

In fact, in the transmission of data packets in a network, the source IP address and destination IP address do not change during transmission (provided that NAT is not used), while the source MAC address and destination MAC address keep changing.

2. IPv4 Protocol#

In TCP/IP network communication, to ensure normal communication, each device needs to be configured with the correct IP address; otherwise, normal communication cannot be achieved.

An IPv4 address is represented by a 32-bit positive integer, and IP addresses are processed in binary by computers.

Humans use a dotted-decimal notation for convenience, which means dividing the 32-bit IP address into 4 groups of 8 bits each, separated by a ".", and converting each group into decimal.

image

Thus, the maximum value of an IP address is

image

Theoretically, a maximum of 4.3 billion computers can connect to the network. In practice, IP addresses are not configured based on the number of hosts. Devices like servers and routers have more than two network interfaces, meaning they can have more than two IP addresses.

image

Therefore, it is actually impossible for all 4.3 billion computers to connect to the network. Moreover, IP addresses consist of a "network identifier" and a "host identifier," so the actual number of computers that can connect to the network is much less.

Some friends may have questions: now not only computers have IP addresses, but also phones, tablets, and other electronic devices have IP addresses. Logically, this should exceed 4.3 billion. How can so many IP addresses be supported?

This is because a technology called NAT allows the number of connectable computers to exceed 4.3 billion. The NAT technology will be discussed and explained further later.

Classification of IP Addresses#

At the birth of the Internet, IP addresses seemed abundant, so computer scientists designed classified addresses.

IP addresses are classified into five types: Class A, Class B, Class C, Class D, and Class E.

image

The yellow part in the image indicates the classification number used to distinguish the types of IP addresses.

What are Class A, B, and C addresses?

For Classes A, B, and C, they are mainly divided into two parts: the network number and the host number. This is easy to understand; for example, Xiao Lin is in Building 1, Room 101 of Area A, while you are in Building 1, Room 101 of Area B.

We can use the following table to clearly see the address ranges and maximum number of hosts corresponding to Classes A, B, and C.

image

Why subtract 2? Because in IP addresses, there are two special IP addresses: one where the host number is all 1s and one where it is all 0s.

image

The host number all being 1s designates all hosts in a certain network for broadcasting, while the host number all being 0s designates a certain network. Therefore, during allocation, these two cases should be excluded.

What is the use of the broadcast address?

The broadcast address is used to send packets between hosts connected on the same link.

An example of broadcasting in a school class is when the class monitor usually shouts, "Class, stand up!" When classmates hear this, do they all stand up? This statement has a broadcasting meaning.

When the host number is all 1s, it indicates the broadcast address of that network. For example, representing 172.20.0.0/16 in binary is as follows:

  10101100.00010100.00000000.00000000 

Changing all the host part of this address to 1s forms the broadcast address:

  10101100.00010100.11111111.11111111 

Converting this address to decimal gives 172.20.255.255.

Broadcast addresses can be divided into local broadcast and directed broadcast.

Broadcasting within the same network is called local broadcast. For example, if the network address is 192.168.0.0/24, the broadcast address is 192.168.0.255. Since this broadcast address's packets will be filtered by routers, they will not reach other links outside of 192.168.0.0/24. Broadcasting between different networks is called directed broadcast. For example, a host with the network address 192.168.0.0/24 sends a packet to the target address 192.168.1.255/24. The router receiving this packet will forward the data to 192.168.1.0/24, allowing all hosts from 192.168.1.1 to 192.168.1.254 to receive this packet. (Due to certain security issues with directed broadcasts, they are usually set not to forward on routers.)

image

What are Class D and E addresses?

Class D and Class E addresses do not have host numbers and cannot be used for host IP addresses. Class D is often used for multicast, while Class E is a reserved classification that is not currently in use.

image

What is the use of multicast addresses?

Multicast is used to send packets to all hosts within a specific group.

Using the class example again, if the teacher says, "Students in the last row, come up to solve this math problem," the teacher specifies the students in the last row, which is the meaning of multicast.

Since broadcasts cannot penetrate routers, if you want to send the same packet to other subnets, you can use multicast, which can penetrate routers.

image

  • The multicast addresses used in Class D have the first four bits as 1110, indicating that it is a multicast address, while the remaining 28 bits are the multicast group number.

The usable range for multicast is from 224.0.0.0 to 239.255.255.255, divided into the following three categories:

224.0.0.0 to 224.0.0.255 are reserved multicast addresses that can only be used within a local area network, and routers will not forward them. 224.0.1.0 to 238.255.255.255 are user-available multicast addresses that can be used on the Internet. 239.0.0.0 to 239.255.255.255 are locally scoped multicast addresses, meant for internal use within a specific local range.

Advantages of IP Address Classification#

Whether it is a router or a host resolving an IP address, we check whether the first bit of the IP address is 0. If it is 0, it is a Class A address, allowing us to quickly identify the network address and host address.

The classification judgment methods for the other classes are as follows:

image

Thus, the advantage of this classified address is its simplicity and clarity, making routing (based on network addresses) straightforward.

Disadvantages of IP Address Classification#

Disadvantage 1: There is no address hierarchy within the same network. For example, a company may use a Class B address, but it might need to classify addresses based on production, testing, and development environments. However, this IP address classification lacks the functionality to divide address hierarchies, resulting in a lack of address flexibility.

Disadvantage 2: Classes A, B, and C have an awkward situation where they do not match well with real networks.

Class C addresses can accommodate too few hosts, only 254, which may not be enough for a typical internet café.

On the other hand, Class B addresses can accommodate too many hosts, over 60,000 machines in one network, which most companies cannot reach, resulting in wasted addresses.

Both of these disadvantages can be addressed by CIDR (Classless Inter-Domain Routing).

Classless Inter-Domain Routing (CIDR)#

Due to the many shortcomings of IP address classification, a classless addressing scheme was proposed later, namely CIDR.

This method no longer has the concept of classified addresses; the 32-bit IP address is divided into two parts: the network number and the host number.

How is the network number and host number divided?

The representation is a.b.c.d/x, where /x indicates that the first x bits belong to the network number, and x ranges from 0 to 32, making IP addresses more flexible.

For example, 10.100.122.2/24, this address representation is CIDR, where /24 indicates that the first 24 bits are the network number and the remaining 8 bits are the host number.

image

Another way to separate the network number and host number is through a subnet mask, which means masking the host number, leaving the network number. By performing a bitwise AND operation between the subnet mask and the IP address, the network number can be obtained.

image

Why separate the network number and host number?

Because for two computers to communicate, they first need to determine whether they are in the same broadcast domain, i.e., whether their network addresses are the same. If the network addresses are the same, it indicates that the recipient is on the same network, allowing the data packet to be sent directly to the target host.

In the routing addressing process, routers find the corresponding network number in this way, and then forward the data packet to the corresponding network.

image

How to Perform Subnetting?#

As we know, we can use subnet masks to divide the network number and host number. In fact, subnet masks also serve the purpose of dividing subnets.

Subnetting essentially divides the host address into two parts: the subnet network address and the subnet host address. The form is as follows:

image

An IP address without subnetting: network address + host address. An IP address after subnetting: network address + (subnet network address + subnet host address).

Assuming we perform subnetting on a Class C address with a network address of 192.168.1.0, using a subnet mask of 255.255.255.192 for subnetting. In a Class C address, the first 24 bits are the network number, and the last 8 bits are the host number. According to the subnet mask, we can borrow 2 bits from the 8-bit host number to serve as the subnet number.

image

Since the subnet network address is divided into 2 bits, there will be 4 subnet addresses: 00, 01, 10, and 11, as shown in the following diagram:

image

The four subnets after division are shown in the following table:

image

Public IP Addresses and Private IP Addresses#

In Class A, B, and C addresses, there are actually public IP addresses and private IP addresses.

image

The IP addresses we usually use in offices, homes, and schools are generally private IP addresses. These addresses allow internal IT personnel to manage and allocate them themselves, and they can be reused. Therefore, a private IP address in your school can be the same as one in my school.

Just like every residential area has its own building numbers and door numbers, your home can be 101, Building 1, Area A, while my home can also be 101, Building 1, Area B, with no issues. However, once you leave the residential area, you need to use a public IP address like No. 666, Zhongshan Road, which is uniformly allocated by the state, and no two residential areas can have the same address.

Thus, public IP addresses are allocated by a unified organization. For instance, if you want to start a blog website, you need to apply for and purchase a public IP address so that people worldwide can access it. Moreover, public IP addresses must generally remain unique across the entire Internet.

image

Who Manages Public IP Addresses?#

Private IP addresses are usually managed by internal IT personnel, while public IP addresses are managed by the ICANN organization, known in Chinese as the "Internet Corporation for Assigned Names and Numbers."

IANA is one of ICANN's agencies responsible for allocating Internet IP addresses, distributed in layers by continent.

image

  • ARIN: North America
  • LACNIC: Latin America and some Caribbean islands
  • RIPE NCC: Europe, the Middle East, and Central Asia
  • AFRINIC: Africa
  • APNIC: Asia-Pacific region

In China, it is managed by CNNIC, the only designated organization for global IP address management in China.

IP Addresses and Routing Control#

The network address part of the IP address is used for routing control.

The routing control table records the network address and the address to which it should be sent next. Both hosts and routers have their own routing control tables.

When sending an IP packet, the first step is to determine the target address in the IP packet header, then find the record with the same network address in the routing control table. Based on this record, the IP packet is forwarded to the corresponding next router. If there are multiple records with the same network address in the routing control table, the one with the longest match (i.e., the most bits in common) is chosen.

The following network link diagram illustrates this:

image

Host A wants to send an IP packet with a source address of 10.1.1.30 and a target address of 10.1.2.10. Since there is no matching network address for the target address 10.1.2.10 in Host A's routing table, the packet is forwarded to the default route (Router 1). Router 1 receives the IP packet and also checks its routing table for a matching network address record for the target address. Finding a match, it forwards the IP data packet to Router 2 at address 10.1.0.2. Router 2 receives it and similarly checks its routing table, finds a match, and sends the IP packet out from its interface 10.1.2.1, ultimately forwarding the IP data packet to the target host through a switch.

The local machine uses a special IP address, 127.0.0.1, known as the loopback address. A hostname with the same meaning is localhost. When using this IP or hostname, the data packet does not go out to the network.

IP Fragmentation and Reassembly#

The maximum transmission unit (MTU) of each data link is different; for example, the MTU for FDDI data links is 4352 bytes, while for Ethernet, it is 1500 bytes.

The reason for the different MTUs is that each type of data link serves different purposes. Different purposes allow for different MTUs.

Among them, the most common data link is Ethernet, with an MTU of 1500 bytes.

When the size of an IP packet exceeds the MTU, the IP packet will be fragmented.

After fragmentation, the reassembly of the IP packet can only be done by the target host; routers will not perform reassembly.

Assuming the sender sends a large data packet of 4000 bytes, if it needs to be transmitted over an Ethernet link, it must be fragmented into 3 smaller packets for transmission, which will then be reassembled by the receiver into the large data packet.

image

During fragmented transmission, if any fragment is lost, the entire IP datagram becomes invalid. Therefore, TCP introduces the maximum segment size (MSS), meaning fragmentation is done at the TCP layer, not by the IP layer. Thus, for UDP, we should avoid sending a datagram larger than the MTU.

IPv6 Addresses#

Finally, let's talk about IPv6.

IPv4 addresses are 32 bits long, providing approximately 4.2 billion addresses, but IPv4 addresses were already exhausted by 2011.

However, IPv6 addresses are 128 bits long, allowing for an astonishing number of assignable addresses. It is said that IPv6 can ensure that every grain of sand on Earth can be assigned an IP address.

But beyond having more addresses, IPv6 also offers better security and scalability, meaning that IPv6 can provide a better network experience compared to IPv4.

However, because IPv4 and IPv6 are not compatible with each other, not only do our computers and devices need to support it, but network operators also need to upgrade existing equipment, which may be one reason for the slow adoption rate of IPv6.

Highlights of IPv6#

IPv6 is not just about having more assignable addresses; it also has many highlights.

  • IPv6 can be automatically configured, allowing for automatic IP address assignment even without a DHCP server, making it truly plug-and-play.
  • The IPv6 header has a fixed length of 40 bytes, eliminating the header checksum, simplifying the header structure, reducing the load on routers, and greatly improving transmission performance.
  • IPv6 has features to combat IP address spoofing and prevent line eavesdropping, significantly enhancing security.

IPv6 Address Identification Method#

The length of an IPv4 address is 32 bits, represented in groups of 8 bits using dotted-decimal notation.

The length of an IPv6 address is 128 bits, represented in groups of 16 bits, separated by colons ":".

image

If there are consecutive zeros, these zeros can be omitted and replaced with two colons "::". However, an IP address can only contain two consecutive colons once.

image

Structure of IPv6 Addresses#

Similar to IPv4, IPv6 also identifies the type of IP address through the first few bits.

IPv6 addresses mainly consist of the following types:

  • Unicast addresses, used for one-to-one communication
  • Multicast addresses, used for one-to-many communication
  • Anycast addresses, used for communication with the nearest node, where the nearest node is determined by the routing protocol
  • No broadcast address

image

Types of IPv6 Unicast Addresses#

For one-to-one communication, IPv6 addresses are mainly divided into three types, each with different valid ranges.

  • For link-local unicast communication, which does not pass through routers, link-local unicast addresses can be used. IPv4 does not have this type.
  • For internal unicast communication, unique local addresses can be used, equivalent to IPv4 private IPs.
  • For Internet communication, global unicast addresses can be used, equivalent to IPv4 public IPs.

image

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.