IP address routing and dynamic routing protocol (6)
Routing is one of the most important functions of IP addresses. The selected data packets can be generated by a local host or another host. In one case, the host must be configured as a router. Otherwise, the datagram obtained through the network interface will be discarded If the destination address is not the local machine.
There is a daemon, which is usually a user process. In Unix systems, most common daemon programs are routing programs and gateway programs (daemon refers to processes running in the background, which indicates that the entire system performs some operations. Daemon is generally started during system boot and always exists during system running ).
Simple route table
Run the netstat-rn command and output the following:
Destination Gateway Genmask Flags MSS Window irtt Iface
152.188.7.255.192.168.8.1 0.0.0.0 UGH 0 0 eth0
Default 192.168.8.1 0.0.0.0 UG 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
192.168.8.20.0.0.0.0 255.255.255.0 U 0 0 0 eth0
The first line indicates that if the destination address is 192.168.8.20.then the gateway (router) forwards the group to 192.168.8.1.
For a given vro, five different labels can be printed:
U this vro can use
G. The router is connected to a gateway (vro). If there is no sign, the destination address is directly connected.
H. The router is connected to a host, that is, the destination address is a complete host address.
D. The route is created by the redirection message.
M The route has been modified by the redirection message
The flag is very important. It distinguishes between indirect routes and direct routes. The difference is that not only the IP address of the destination end, but also the link layer address, the gateway is specified. When searching a route table for a destination address, the host address must exactly match the destination address. If not, the host address matches the network address; the network address only needs to match the network number and subnet number of the destination address.
The output 2nd rows are default routes. Each host has one or more default routes. This indicates that if no specific route is found in the routing table, the group is sent to the vro192.168.192.168.8.1.
This indicates that the current host can access other network systems over the Internet by taking advantage of this channel.
No route to the destination
In the previous section, we assumed that all table items matching can be found in the search of the route table, even if the matching is a default route. However, if no default item exists in the routing table and no matching item is found, what will happen.
The result depends on whether the IP datagram is generated by the host or forwarded. If the datagram is generated locally, an error is returned to the application that sends the datagram ("host inaccessible error" or "Network inaccessible error "). If the packet is forwarded, an error message that is inaccessible to the ICMP Host is sent to the original sender.
ICMP redirect error
We assume that the host sends an IP datagram to R1, because R1 is the default route of the host.
When R1 receives the datagram and checks its route table, it finds that R2 is the next stop to send the datagram. When he sends the datagram to R2, the interface that R1 detects that he is sending a datagram is the same as the interface for reaching the datagram (that is, the port on which R1 receives the datagram is the same as the port on which he wants to send it out ). In this way, the router is sent with a redirection packet to provide clues to the original sender.
R1 sends an ICMP redirection packet to the host, telling the host to send the datagram to R2 instead of R1 ,.
Redirection generally allows hosts with few routing information to gradually establish a more complete route table. When the host is started, the routing table can have only one Default table item. Once the default route fails to be sent, the default router will notify the router to redirect the route table and allow the host to modify the route table accordingly. ICMP redirection allows TCP/IP hosts to select routes without having to have intelligent features. Instead, all the smart features are placed on the router side. The host only learns from the redirection message.
ICMP Router packet discovery
Generally, you can initialize a route table by specifying a static route in the configuration file. This method is often used to set the default route. Another method is to use ICMP to advertise messages and request packets.
Generally, the host needs to broadcast or multicast a router request packet after guidance. One or more routers have a router notification message. In addition, routers regularly broadcast or multicast messages to send their router notification packets, and run each host being monitored to update their route table.
ICMP route request message format:
ICMP Router notification message:
The router can advertise multiple addresses in one message. The address book refers to the number of addresses contained in the message; The address item size refers to the number of 32 bits for each vro address; the survival time refers to the effective time (in seconds) of the advertised address ). Priority indicates the priority of the IP address as the default router address.
Dynamic Route Selection
The communication between routers uses the RIP Protocol (Routing Infromation Protocol). Most TCP/IP implementations provide this widely used Protocol.
When the communication between the adjacent routers has been notified of the network connected by each of the other routers, a dynamic route is selected. Vrouters must communicate with each other using the routing protocol. There are many such routing protocols. A process on a vro。 becomes a routing daemon. It runs the routing protocol and communicates with its adjacent vrouters. The routing daemon updates the route table in the kernel based on the information it receives from the neighboring router.
Dynamic Routing does not change the kernel's routing method on the IP layer (that is, IP routing ). The kernel searches the route table to find the host route and network route. And the default routing method has not changed. Only the information placed in the route table has changed-when the route changes over time, the route is dynamically added or deleted by the route daemon, rather than from the route program in the boot program file.
The routing daemon adds the routing policy to the system, selects a route, and adds it to the routing table. If the daemon finds that there are multiple routes to the same sink, it (in some way) selects the best route and adds it to the routing table. If the routing daemon finds that a link is disconnected (possibly because the router crashes or the route is poor), it can delete the affected route or add a route to bypass the problem.
In a system like the internet, many different routing protocols are used. The Internet is composed of multiple sets of self-made systems. Each self-made system has its own routing protocol. A company or university is often defined as a self-made system. Each self-made system can select the routing Protocol between routers in the self-made system. This protocol is called the Internal Gateway Protocol IGP (Interior Gateway protocol) or the intra-Domain routing Protocol (interadomain routing protocol ). The most common IGP routing information protocol RIP. (The function of the routing protocol is to provide the optimal path and add it to the routing table. It provides a better route table solution for the topic to view the route table)