IP A router connects multiple IP Network equipment , Its main task is to go through the process IP Each of the routers IP Searching for an optimal transmission path for data packets .
Routing table is a table that records the data of various transmission paths , It is divided into static routing table and dynamic routing table .
Static routing table is a fixed routing table in advance , It will not change with the change of network structure .
Dynamic routing table a routing table automatically adjusted by a certain routing algorithm .
IP Packet forwarding process :
IP Data packet according to ARP Check whether there is a target host in the cache MAC address , If there is, it will be directly packaged into a frame and sent to the destination host , If not, broadcast one over the local area network ARP request , And then the purpose IP The host returned a ARP data packet , There's a target host in it MAC address .
When IP Purpose of the packet IP When the local network segment is no longer available ,A To the “ Default gateway ” issue ARP package , and “ Default gateway ” Of IP The address is already in A Set in system software . this IP The address actually corresponds to the router M At the entrance of IP address . therefore A Yes “ Default gateway ” Of IP Address broadcast one ARP On request , Router M Of E0 Oral MAC Reply to A, here A Packet encapsulation into frames , objective MAC Replace with M Of E0 mouth MAC. Then the link layer sends data frames to the default router , After arriving at the router, unpack it IP network layer , Get the purpose IP Network segment of , Then you need to use the information in the routing table above .
Find the related table entries according to the routing table , Get the next hop and the entrance and exit MAC address , therefore IP Package repackaging as source mac Is the current router exit MAC, objective MAC It is the data frame of the next hop router ( Frame rewriting ), Then it is sent through the link layer , Until the destination segment is reached . After arriving at the destination network segment, according to the destination IP Destination host .
Detailed work of router :
Note the getway Values are the direct forward and next hop router address , If the purpose IP Routing table hit , Forward it directly ,getway It will be displayed as *.
route Command to view routing table information
Take a look at the routing table below
The role of routing table :
Here, a destination segment corresponds to an exit
This host has two network interfaces , A network interface is connected to the 192.168.10.0/24 network , Another network interface is connected to the
192.168.56.0/24 network ;
Routing table Destination Is the destination network address ,Genmask Subnet Mask ,Gateway It's the next hop address ,Iface It's sending and receiving
mouth ,Flags Medium U Flag indicates that the entry is valid ( Some can be disabled entry ),G The flag indicates that the next hop address of this entry belongs to a router
address , No, G The entry of the flag indicates that the destination network address is a network directly connected to the local interface , No router forwarding ;
Example of forwarding process 1:
If the destination address of the packet to be sent is 192.168.56.3
And the subnet mask on the first line reach 192.168.56.0, The destination address does not match the first line
And then add the subnet mask in the second line reach 192.168.56.0, This is the destination network address of the second line , So from eth1 Interface send out
go ;
because 192.168.56.0/24 just Yes and eth1 Interface directly connected network , So it can be sent directly to the destination host , There is no need to transfer through the router
hair ;
Example of forwarding process 2:
If the destination address of the packet to be sent is 202.10.1.2
Compare with the first few items in the routing table , It doesn't match ;
By default route entry , from eth0 The interface is sent out , To 192.168.10.1 Router ;
from 192.168.10.1 The router determines the next hop address according to its routing table ;
Technology