Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the working principle of IP routing in Linux system

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

What is the working principle of IP routing in Linux system? aiming at this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

Maybe you know how to use the command netstat or route on Linux systems to find (or even add / delete) existing routes. But when you do this, you may not know how IP routing works. This article will help you understand how IP routing works and how it works. IP routing involves the forwarding of IP data packets. If the host is directly connected to the destination host, then the host can send IP messages directly to the destination host, which is a relatively simple process. For example, through peer-to-peer links or over the network sharing. If the host is not directly connected to the destination host, the host sends the IP message to the default router, and then the router decides where to send the IP message.

IP routing involves the forwarding of IP data packets. If the host is directly connected to the destination host, then the host can send IP messages directly to the destination host, which is a relatively simple process. For example, through peer-to-peer links or over the network sharing. If the host is not directly connected to the destination host, the host sends the IP message to the default router, and then the router decides where to send the IP message.

Routing principle

The fundamental difference between an ordinary host and a router is that the host does not forward a message from one interface to another, while the router can forward the message.

Today, most multiuser systems can be configured to be used as routers. Therefore, a common routing algorithm can be used on a router, as well as on an ordinary host. When a host can be used as a router, we usually say that the host is embedded in the function of the router. This kind of host with embedded router function does not usually forward messages unless we configure it to enable this function.

The IP layer maintains a routing table that it uses to decide what to do next when it receives a Datagram. When a data message is received from the network side, the IP layer first checks whether the IP address of the message is the same as that of the host itself.

If the IP address in the data packet is the host's own address, then the message will be sent to the corresponding protocol in the transport layer. If the IP address in the message is not the host's own address, and the host is configured with routing function, the message will be forwarded; otherwise, the message will be discarded.

The data in the routing table generally exists in the form of entries. A typical routing table entry contains the following main entries:

● destination IP address: this field represents the IP address of the destination. This IP address can be the address of a host or a network address. If the entry contains a host address, its host ID is marked non-zero; if the entry contains a network address, its host ID is marked zero.

IP address of ● 's next router: the reason why we use the term "next" is that the next router is not always the destination router, but it is likely to be an intermediate router. The entry gives the address of the next router to forward IP packets received from the corresponding interface.

● flag: this field provides another set of important information, such as whether the destination IP address (mentioned earlier) is a host address or a network address. In addition, you can tell from the flag that the next router (mentioned earlier) is really a router or a directly connected interface.

● network interface specification: a network interface specification for some data packets, which is propagated along with the message.

How does basic routing work?

Therefore, if we want to describe the routing process simply and vividly now, we will see that once the IP layer of the host (configured to have routing capabilities) receives a packet from the network side, it will verify the destination IP address in the packet, and if this IP is not the IP address of the host, the packet will be forwarded through the routing table.

If the * * fields of any entry exactly match the destination IP address (host) or partially match the destination IP address (network), it indicates the IP address of the next router. This is an important message because it tells the host directly which "next router" the packet should be forwarded to. All other fields in the entry will provide more auxiliary information to make decisions for route forwarding.

In the previous paragraph, we established a basic understanding of the routing forwarding process, but if we try to learn more, we must take a look at some of the following details about the routing table algorithm.

● first, the routing table searches for an entry in the destination IP address field that is exactly the same as the destination IP address in the Datagram. This means that the host ID of the IP address matches the network ID exactly. If found, the packet is sent to the appropriate interface or intermediate router.

If ● does not find an exact matching IP, it then goes on to search for a matching network ID. If found, the packet is forwarded to the designated router. So we see that all hosts on this network are managed by a single entry in this routing table.

● if neither of the above conditions match, the packet will be forwarded to a "default router".

● if the above steps fail, that is, there is no default router, then the packet cannot be forwarded in the end. Any undeliverable Datagram will generate an error that the ICMP host is unreachable or the ICMP network is unreachable, and the error is returned to the application that generated the Datagram.

Sometimes people ask, why are there two types of entries in the routing table? Why do you need network-related entries when you have more accurate host entries? Um... It is a great advantage to include network-related routing entries in the routing table. The advantage is that having an entry associated with a complete network can avoid including all individual host entries in this network (which is a huge amount of data). This reduces the size of the routing table to an acceptable order of magnitude, which is very good.

Commands to view routing table information

You can use the netstat command to view routing table information, as shown below:

\ $netstat-rn Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 192.168.2.0 0.0.0.0 255.255.255.0 U 000 eth0 169.254.0.0 0.0.0.0 255.255.0.0 U 000 eth0 0.0.0.0 192.168.2.1 0.0.0 UG 000 eth0 its output provides details about the destination IP address and gateway. The flag "U" indicates that the router is reachable; "G" indicates that the router is connected to a gateway (router). If this flag is not set, then we can assume that the host is directly connected to the target.

The answer to the question about the working principle of IP routing in Linux system is shared here. I hope the above content can be of some help to everyone. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report