路由器工作原理及静态路由

一、路由器

1.路由器概述

1.路由:从源主机到目标主机的转发过程
2.路由器:能够将数据包转发到正确的目的地,并在转发过程中选择最佳路径的设备(路由器的工作原理:根据路由表转发数据)
如图:主机1.1(网段1.0)要发送数据到4.1(网段4.0),首先数据会通过E0接口到达路由器A,发现数据内包含源IP地址主机1.1,目的IP地址主机4.1,为4.0网段,这时路由器A会查询路由表,发现4.0网段应该往S0接口上发送,即通过S0接口到达路由器B,路由器B收到数据包,看到目的IP为4.1,为4.0网段,然后查询自己的路由表,发现需要往E0接口上发送,随后通过E0接口发送到主机4.1。在这里插入图片描述

3.路由表:1.路由器中维护的路由条目的集合 2.路由器根据路由表做路径选择
4.直连网段:与路由器直连网段,配置IP地址端口up状态自动学习
非直连网段:需要静态路由或动态路由配置加入路由表
5.选取最优路径标准
a.子网掩码长度最长的最优先匹配
b.选取路由协议中优先级最小的最优先匹配
c.相同路由协议的情况下选取metric值最小的最优先匹配
每个路由协议metric值定义的都不相同静态路由和路由优先级有关,这个人为指定的,RIP协议和跳数有关,跳数越小越优先,OSPF协议和带宽有关,带宽越大越优先,metric度量值时cost花销

路由协议 优先级
DIRECT 0
OSPF 10
IS-IS 15
STATIC 60
RIP 100
OSPF ASE 150
OSPF NSSA 150
IBGP 256
EBGP 256

2.路由器工作过程(源IP目标IP不变,MAC地址变得)

在这里插入图片描述
上图,以下简称主机A 主机B 网关为AE0 路由接口AE1,BE1,BE0 主机只知道网关IP地址 网关为路由器A的E0接口
若主机A想要发送数据包给主机B,但是两台主机不在同一网段,所以需要经过网关。
主机A查询自己的ARP缓存表,没有网关的MAC地址,所以要进行一次ARP请求。
源IP地址与源MAC地址是主机A自己的,目标IP地址为AE0的IP地址,目的MAC地址为AE0的MAC地址(广播地址),网关接收到后进行回应,得到网关AE0的MAC地址。数据加上源IP与源MAC为主机A的,目的IP为主机B, 目的MAC为AE0的进行封装,这时数据包到达路由器A,解封装后数据包含主机A的源IP地址,目的IP地址为主机B的IP地址,路由器查询路由表发现应该通过E1接口转发到路由器B。
进行ARP请求,源IP地址和源MAC地址为AE1的,目的IP目的MAC地址为BE1的IP地址和MAC地址(广播地址),路由器BE1响应回复,得到BE1的MAC地址,然后将数据加上源IP地址为主机A的IP地址,源MAC地址为AE1的MAC地址,目的IP为主机B的IP地址,目的MAC地址为BE1的MAC地址进行封装
数据到路由器B,路由器B解封装,内包含目的IP为主机B的IP地址,路由器B查询路由表,发现为直连路由应该走E0出口,E0向主机B发送ARP请求,源IP地址源MAC地址的为BE0的,目标IP为主机B的IP地址,目的MAC地址为广播地址,主机B响应回复,得到主机B的MAC地址,这时,数据加上源IP为主机A的IP地址,源MAC地址为BE0的MAC地址,目的IP和目的MAC地址为主机B的IP和MAC地址,数据到达主机B

二、静态路由(小型网络建议5条内)

1.相关概念

1.静态路由由管理员手工配置是单向的
2.缺乏灵活性
3.命令配置
默认路由:ip route-static 0.0.0.0 0.0.0.0 192.168.12.1
IP route-static 目标网段 子网掩码 下一跳
静态路由:ip route-static 192.168.10.0 255.255.255.0 192.168.12.1
查看路由表
display ip routing-table
4.默认路由:是静态路由的一种特数形态,它属于静态路由的一种,使用条件只能在末梢末节网络,相连的路由不能设置默认路由会产生信令风暴造成数据反复传输占用带宽

2.静态路由配置

在这里插入图片描述

RI配置

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配置

与R1配置相同添加192.168.1.0 的网段和172.168.1.0网段

的静态路由
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配置

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.

猜你喜欢

转载自blog.csdn.net/weixin_53567573/article/details/112511480