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 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 end-to-end communication.

image

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

It is actually 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 facilitate communication between two directly connected devices. 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 faraway 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 limited range. Here, "within the range" is like the data link in a communication network.

Moving within the range is equivalent to the data link layer, acting as the transmission function between two nodes within the range. The starting point within the range 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 endpoint 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 with both, having tickets for a certain range and an 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 destination 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), only 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.

For convenience, humans use a dotted-decimal notation, which divides the 32-bit IP address into 4 groups of 8 bits each, separated by a ".", 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, connecting all 4.3 billion computers to the network is actually impossible. 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 even fewer.

Some friends may question that now not only computers have IP addresses, but also phones, tablets, and other electronic devices, which 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 dawn 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 primarily 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 under a certain network, used for broadcasting. 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 within the same link.

An example of broadcasting in a school class is when the class monitor usually shouts, "Class, stand up!" When the classmates hear this, do they all stand up? This phrase 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 

When this address is represented in decimal, it becomes 172.20.255.255.

Broadcast addresses can be divided into local broadcasts and direct broadcasts.

Local broadcasts occur within the same network. For example, if the network address is 192.168.0.0/24, the broadcast address is 192.168.0.255. Since packets sent to this broadcast address will be blocked by routers, they will not reach other links outside of 192.168.0.0/24. Direct broadcasts occur between different networks. 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 direct broadcasts, they are usually set not to forward on routers.)

image

What are Class D and E addresses?

Class D and 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 are Class D addresses, where the first four bits are 1110, indicating that it is a multicast address, and 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; 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 administered multicast addresses, valid only within a specific local scope.

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 for the remaining types is as follows:

image

Thus, the advantage of this classification of addresses is that it is simple and clear, and routing (based on network addresses) is 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 may need to classify address hierarchies based on production, testing, and development environments. However, this IP address classification does not have the functionality to classify address hierarchies, leading to 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.

The maximum number of hosts that a Class C address can contain is too small, only 254, which may not even be enough for an internet café.

On the other hand, the maximum number of hosts that a Class B address can contain is too large, with over 60,000 machines under one network, which is generally beyond the scale of most enterprises, 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 disadvantages of IP address classification, a classless addressing scheme, CIDR, was proposed later.

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 to divide the network number and host number?

The representation is a.b.c.d/x, where /x indicates that the first x bits belong to the network number, and x can range 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 the subnet mask, which means to mask 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 the 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 packets to the corresponding network.

image

How to Perform Subnetting?#

As we know, we can use the subnet mask to separate the network number and host number. In fact, the subnet mask also serves the purpose of subnetting.

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

image

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

Assuming we perform subnetting on a Class C address with the network address 192.168.1.0, using a subnet mask of 255.255.255.192 for subnetting. The first 24 bits of the Class C address 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 as the subnet number.

image

With the subnet network address divided into 2 bits, there will be 4 subnet addresses: 00, 01, 10, 11, as shown in the diagram below:

image

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

image

Public IP Addresses and Private IP Addresses#

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

image

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

Just like every community has its own building numbers and door numbers, your community can have a house called Building 1, Room 101, while my community can also have a house called Building 1, Room 101 without any issue. However, once outside the community, you need to carry the public IP address, such as Zhongshan Road 666 (public IP address), which is uniformly allocated by the state, and two communities cannot both be called Zhongshan Road 666.

Thus, public IP addresses are uniformly allocated by an organization. For example, 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, which stands for the Internet Corporation for Assigned Names and Numbers.

IANA is one of the agencies under ICANN, responsible for allocating Internet IP addresses in a tiered manner by continent.

image

ARIN for North America, LACNIC for Latin America and some Caribbean islands, RIPE NCC for Europe, the Middle East, and Central Asia, AFRINIC for Africa, and APNIC for the Asia-Pacific region. In China, it is managed by CNNIC, which is the only designated organization for global IP address management in China.

IP Addresses and Routing Control#

The network address portion of an IP address is used for routing control.

The routing control table records the network address and the next address to which it should be sent to the router. 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 from the routing control table. Based on that 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 is chosen.

The following network link diagram serves as an example:

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 matches the network address record with the target address in Router 1's routing table, finds a match, and forwards the IP data packet to Router 2 at 10.1.0.2. Router 2 receives it, compares it with its own routing table, finds a match, and sends the IP packet out through Router 2's interface at 10.1.2.1, ultimately forwarding the IP data packet to the target host via 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 varies, such as FDDI data link MTU being 4352 bytes, and Ethernet's MTU being 1500 bytes.

The reason for the different MTUs of each data link 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 occurs at the TCP layer rather than 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.

In addition to having more addresses, IPv6 also offers better security and scalability, which means that IPv6 can provide a better network experience compared to IPv4.

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

Highlights of IPv6#

IPv6 not only has more assignable addresses but also has many other highlights.

IPv6 can be auto-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 network security features to counteract IP address spoofing and prevent line eavesdropping, significantly enhancing security.

IPv6 Address Representation#

IPv4 addresses are 32 bits long, represented in groups of 8 bits using dotted-decimal notation.

IPv6 addresses are 128 bits long, represented in groups of 16 bits, with each group separated by a colon ":".

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 include the following types:

  • Unicast address, used for one-to-one communication
  • Multicast address, used for one-to-many communication
  • Anycast address, 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, there are three main types of unicast addresses, each with different valid ranges.

  • For link-local unicast communication, which does not go through routers, link-local unicast addresses can be used. This type does not exist in IPv4.
  • For internal network 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.