Router working principle and static routing

1. Router

1. Router overview

1. Routing: the process of forwarding from the source host to the target host.
2. Router: a device capable of forwarding data packets to the correct destination and selecting the best path during the forwarding process (the working principle of a router: forwarding data according to the routing table) )
As shown in the figure: Host 1.1 (network segment 1.0) wants to send data to 4.1 (network segment 4.0). First, the data will reach router A through the E0 interface. It is found that the data contains the source IP address host 1.1 and the destination IP address host 4.1, which is 4.0 At this time, router A will query the routing table and find that the 4.0 network segment should be sent to the S0 interface, that is, reach the router B through the S0 interface. Router B receives the data packet and sees that the destination IP is 4.1, which is the 4.0 network segment. Then query its own routing table and find that it needs to be sent to the E0 interface, and then sent to the host 4.1 through the E0 interface.Insert picture description here

3. Routing table: 1. The collection of routing entries maintained in the router 2. The router makes path selection according to the routing table
4. Directly connected network segment: The network segment is directly connected to the router, and the IP address port is configured to automatically learn the
non-directly connected network. Segment: static routing or dynamic routing configuration needs to be added to the routing table
5. Select the optimal path standard
a. The most preferred match with the longest subnet mask
b. Select the most preferred match with the smallest priority among the
routing protocols c. The same routing protocol In the case of selecting the smallest metric value, the most preferred match. The
metric value defined by each routing protocol is different. Static routing is related to the routing priority. This is manually specified. The RIP protocol is related to the number of hops. The smaller the number of hops, the more preferred. OSPF The protocol is related to the bandwidth. The larger the bandwidth, the higher the priority. The cost is spent on the metric value.

Routing Protocol priority
DIRECT 0
OSPF 10
IS-IS 15
STATIC 60
RIP 100
OSPF ASE 150
OSPF NSSA 150
IBGP 256
EBGP 256

2. The working process of the router (the source IP and destination IP remain unchanged, but the MAC address becomes)

Insert picture description here
The above picture, hereafter referred to as host A, host B, gateway is AE0, routing interface AE1, BE1, BE0, host only knows the gateway IP address, gateway is E0 interface of router A,
if host A wants to send data packets to host B, but the two hosts are not the same Network segment, so it needs to pass through the gateway.
Host A queries its own ARP cache table and does not have the MAC address of the gateway, so an ARP request is required.
The source IP address and source MAC address are host A's own, the destination IP address is the IP address of AE0, and the destination MAC address is the MAC address (broadcast address) of AE0. The gateway responds after receiving it and obtains the MAC address of gateway AE0. The data plus the source IP and source MAC are host A, the destination IP is host B, and the destination MAC is AE0 for encapsulation. At this time, the data packet arrives at router A. After decapsulation, the data contains the source IP address and destination IP address of host A. For the IP address of host B, the router queries the routing table and finds that it should be forwarded to router B through the E1 interface.
Make an ARP request, the source IP address and source MAC address are AE1, the destination IP destination MAC address is the IP address and MAC address of BE1 (broadcast address), router BE1 responds and gets the MAC address of BE1, and then adds the data to the source The IP address is the IP address of host A, the source MAC address is the MAC address of AE1, the destination IP is the IP address of host B, and the destination MAC address is the MAC address of BE1. Encapsulate the
data to router B. Router B decapsulates and contains the destination. IP is the IP address of host B. Router B looks up the routing table and finds that it should take the E0 exit for the direct route. E0 sends an ARP request to host B. The source IP address is the source MAC address of BE0, and the destination IP is the IP of host B. Address, the destination MAC address is the broadcast address, and host B responds and gets the MAC address of host B. At this time, the data plus the source IP is the IP address of host A, the source MAC address is the MAC address of BE0, the destination IP and the destination MAC The address is the IP and MAC address of host B, and the data arrives at host B

2. Static routing (within 5 recommended for small networks)

1. Related concepts

1. The static route is manually configured by the administrator and is one-way
2. Inflexible
3. Command configuration
Default route: ip route-static 0.0.0.0 0.0.0.0 192.168.12.1
IP route-static The subnet mask of the target network segment is next Hop
Static routing: ip route-static 192.168.10.0 255.255.255.0 192.168.12.1
View the routing table
display ip routing-table
4. Default routing: a special form of static routing, it is a kind of static routing, use conditions Only in the peripheral network, the connected route cannot be set as the default route, which will cause a signaling storm and cause repeated data transmission to occupy bandwidth

2. Static routing configuration

Insert picture description here

RI placement

u t m
undo terminal m
Info: Current terminal monitor is off.
sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname r1
[r1]user-interface console 0
[r1-ui-console0]idle-timeout 0 0
[r1-ui-console0]q
[r1]int loopb
[r1]int LoopBack 0
[r1-LoopBack0]ip add 192.168.1.10 24
[r1-LoopBack0]q
[r1]int g0/0/0
[r1-GigabitEthernet0/0/0]ip add 10.1.1.2 24
[r1-GigabitEthernet0/0/0]q
[r1]ip route-static 10.1.2.1 24 10.1.1.3
Info: The destination address and mask of the configured static route mismatched
, and the static route 10.1.2.0/24 was generated.
[r1]int g0/0/0
[r1-GigabitEthernet0/0/0]undo shutd
[r1-GigabitEthernet0/0/0]undo shutdown
Info: Interface GigabitEthernet0/0/0 is not shutdown.
[r1-GigabitEthernet0/0/0]q
[r1]ping 10.1.1.3
PING 10.1.1.3: 56 data bytes, press CTRL_C to break
Reply from 10.1.1.3: bytes=56 Sequence=1 ttl=255 time=70 ms
Reply from 10.1.1.3: bytes=56 Sequence=2 ttl=255 time=40 ms
Reply from 10.1.1.3: bytes=56 Sequence=3 ttl=255 time=50 ms
Reply from 10.1.1.3: bytes=56 Sequence=4 ttl=255 time=30 ms
Reply from 10.1.1.3: bytes=56 Sequence=5 ttl=255 time=40 ms

R2 configuration

Same as R1 configuration, add the 192.168.1.0 network segment and the 172.168.1.0 network segment

的静态路由
undo terminal monitor
Info: Current terminal monitor is off.
user-inte
sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname r2
[r2]user-int
[r2]user-interface co
[r2]user-interface console 0
[r2-ui-console0]idle-t
[r2-ui-console0]idle-timeout 0 0
[r2-ui-console0]int g0/0/0
[r2-GigabitEthernet0/0/0]ip add 10.1.1.3 24
[r2-GigabitEthernet0/0/0]undo shut
[r2-GigabitEthernet0/0/0]undo shutdown
Info: Interface GigabitEthernet0/0/0 is not shutdown.
[r2-GigabitEthernet0/0/0]int g0/0/1
[r2-GigabitEthernet0/0/1]ip add 10.1.2.3 24
[r2-GigabitEthernet0/0/1]q
r2]int g0/0/0
[r2-GigabitEthernet0/0/0]undo s
[r2-GigabitEthernet0/0/0]undo static-route
^
Error:Incomplete command found at ‘^’ position.
[r2-GigabitEthernet0/0/0]undo sht
[r2-GigabitEthernet0/0/0]undo shut
[r2-GigabitEthernet0/0/0]undo shutdown
Info: Interface GigabitEthernet0/0/0 is not shutdown.
[r2-GigabitEthernet0/0/0]int g 0/0/1
[r2-GigabitEthernet0/0/1]undo shut
[r2-GigabitEthernet0/0/1]undo shutdown
Info: Interface GigabitEthernet0/0/1 is not shutdown.
[r2-GigabitEthernet0/0/1]q
[r2]ip rou
[r2]ip route-
[r2]ip route-static 192.168.1.10 24 10.1.1.2
Info: The destination address and mask of the configured static route mismatched
, and the static route 192.168.1.0/24 was generated.
[r2]ip rou
[r2]ip route-s
[r2]ip route-static 172.16.1.10 24 10.1.2.4
Info: The destination address and mask of the configured static route mismatched
, and the static route 172.16.1.0/24 was generated.

R3 configuration

undo terminal m
undo terminal monitor
Info: Current terminal monitor is off.
sys
system-view
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname sw3
[sw3]user-in
[sw3]user-interface co
[sw3]user-interface console 0
[sw3-ui-console0]idle-t
[sw3-ui-console0]idle-timeout 0 0
[sw3-ui-console0]int g0/0/0
[sw3-GigabitEthernet0/0/0]ip add 10.1.2.4 24
[sw3-GigabitEthernet0/0/0]q
[sw3]int loopb
[sw3]int LoopBack 0
[sw3-LoopBack0]ip add 172.16.1.10 24
[sw3-LoopBack0]q
[sw3]int g0/0/0
[sw3-GigabitEthernet0/0/0]undo shutdown
Info: Interface GigabitEthernet0/0/0 is not shutdown.
[sw3-GigabitEthernet0/0/0]q
[sw3]ip rou
[sw3]ip route-s
[sw3]ip route-static 10.1.1.0 24 10.1.2.3
[sw3]ip rou
[sw3]ip route-
[sw3]ip route-static 192.168.1.10 24 10.1.2.3
Info: The destination address and mask of the configured static route mismatched
and the static route 192.168.1.0/24 was generated.

Guess you like

Origin blog.csdn.net/weixin_53567573/article/details/112511480