路由器
路由器的工作原理
路由表
路由器中维护的路由条目的集合
路由器根据路由表选择路径
路由表的形成
直连网段:配置IP地址,端口up状态,形成直连路由
非直连网段:需要静态路由或者动态路由将网段添加到路由表中
静态路由
手工配置,单向的,缺乏灵活性
可精准管理
默认路由
默认路由属于静态路由,
网段是0.0.0.0 0
当找不到对应的网段时,找默认路由转发数据
路由器的转发数据包封装过程
如图所示,通过路由器事项两个网段的PC4与PC5通信
第一步:PC4 ARP广播 发送IP号为192.168.2.1/24,MAK 地址为ff-ff-ff-ff-ff-ff,
第二部:AR4的E1端口接受到信号,在路由表中找到192.168.2.0/24网段对应的接口为E2,发送单播给PC4,IP地址192.168.1.1/24,MAK地址为00-00-00-00-11-11,告诉PC4我的MAC 地址为00-00-00-00-22-22,
第三步:PC4单播发送MAC地址是00-00-00-00-22-22,IP地址是192.168.21.1/24
第四步:AR4接受到信息,将信息传给E2接口,E2接口对应的MAK地址是00-00-00-00-33-33
第五步:AR4接口广播,发送IP地址是192.168.2.1/24,MAK地址是ff-ff-ff-ff-ff-ff,
第六步:AP5的E1接口和AR4的E2接口在同一网段,并且要寻找的192.168.2.0/24网段在自己的路由表中,单播发送MAK地址00-00-00-00-33-33,告诉他我的E1接口的MAK地址是00-00-00-00-44-44
第七部:AR4的E2接口接受到信号,并记录AR5的E2接口的端口号,并单播发送MAK地址是00-00-00-00-44-44
第八步:AP5将信息传给E2接口,E2接口的MAK地址是00-00-00-00-55-55
第九步:AR5的E2接口广播寻找192.168.2.1/24,MAK地址是ff-ff-ff-ff-ff-ff
第十步:PC5发现寻找的IP地址是自己,单播发送信息给AR5的E2接口,告诉他自己的MAK地址是00-00-00-00-66-66
第十一步:AR5记录到PC5的MAK地址,单播发送信号给PC5目的IP是192.168.2.1/24,MAC地址是00-00-00-00-66-66
从而实现PC4与PC5之间的通讯。
静态路由配置
display ip routing-table 查看路由表
ip route-static 最终目的地址的网段号 下一跳地址
ip route-static 192.168.1.0 24 10.0.0.2
ip route-static 0.0.0.0 0 10.0.0.0.2 设置默认路由
浮动路由设置
ip route-static 最终目的地址的网段号 下一跳地址 preference 70
设置优先级为70
shutdpwn e0/0/0 关闭e0/0/0接口
作业
一
1,设置每台设备和端口的IP
PC1与PC2连通
查看路由表
配置浮动路由,关闭R1和r2的链路
PC1与PC2连通
再次查看路由表
192.168.20.0/24 优先级有60改为70
二
1,配置每个设备和端口IP
r1命令配置
Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sysn r1
[r1]int g0/0/0
[r1-GigabitEthernet0/0/0]ip add 192.168.1.1 24
Apr 2 2021 16:02:26-08:00 r1 %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP
on the interface GigabitEthernet0/0/0 has entered the UP state.
[r1-GigabitEthernet0/0/0]int g0/0/1
[r1-GigabitEthernet0/0/1]ip add 192.168.2.1 24
Apr 2 2021 16:02:57-08:00 r1 %%01IFNET/4/LINK_STATE(l)[1]:The line protocol IP
on the interface GigabitEthernet0/0/1 has entered the UP state.
[r1-GigabitEthernet0/0/1]int g0/0/2
[r1-GigabitEthernet0/0/2]ip add 192.168.10.1 24
[r1-GigabitEthernet0/0/2]
Apr 2 2021 16:03:35-08:00 r1 %%01IFNET/4/LINK_STATE(l)[2]:The line protocol IP
on the interface GigabitEthernet0/0/2 has entered the UP state.
[r1-GigabitEthernet0/0/2]q
[r1]ip ro
[r1]ip route-s
[r1]ip route-static 0.0.0.0 0 192.168.10.2
r2命令配置
[Huawei]sysn r2
[r2]int g0/0/0
[r2-GigabitEthernet0/0/0]ip add 192.168.10.2 24
Apr 2 2021 16:04:30-08:00 r2 %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP
on the interface GigabitEthernet0/0/0 has entered the UP state.
[r2-GigabitEthernet0/0/0]int g0/0/1
[r2-GigabitEthernet0/0/1]ip add 192.168.20.1 24
Apr 2 2021 16:05:07-08:00 r2 %%01IFNET/4/LINK_STATE(l)[1]:The line protocol IP
on the interface GigabitEthernet0/0/1 has entered the UP state.
[r2-GigabitEthernet0/0/1]q
[r2]ip ro
[r2]ip route-s
[r2]ip route-static 10.0.0.1 8 192.168.20.2
Info: The destination address and mask of the configured static route mismatched
, and the static route 10.0.0.0/8 was generated.
[r2]ip rout
[r2]ip route-s
[r2]ip route-static 10.0.0.0 8 192.168.20.2
Error: The route already exists.
[r2]ip ro
[r2]ip route-s
[r2]ip route-static 192.168.1.0 24 192.168.20.1
Error: The next-hop address is invalid.
[r2]ip ro
[r2]ip route-s
[r2]ip route-static 192.168.1.0 24 192.168.10.1
[r2]ip ro
[r2]ip route-st
[r2]ip route-static 192.168.2.0 24 192.168.10.1
r3命令配置
sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sysn r3
[r3]int g0/0/0
[r3-GigabitEthernet0/0/0]ip add 192.168.20.2 24
Apr 2 2021 16:06:00-08:00 r3 %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP
on the interface GigabitEthernet0/0/0 has entered the UP state.
[r3-GigabitEthernet0/0/0]int g0/0/1
[r3-GigabitEthernet0/0/1]ip add 10.0.0.1 8
Apr 2 2021 16:06:50-08:00 r3 %%01IFNET/4/LINK_STATE(l)[1]:The line protocol IP
on the interface GigabitEthernet0/0/1 has entered the UP state.
[r3-GigabitEthernet0/0/1]
Please check whether system data has been changed, and save data in time
Configuration console time out, please press any key to log on
sys
Enter system view, return user view with Ctrl+Z.
[r3]ip ro
[r3]ip route-s
[r3]ip route-static 192.168.1.0 24 192.168.20.1
[r3]ip ro
[r3]ip route-s
[r3]ip route-static 192.168.2.0 24 192.168.20.1
[r3]
PC1连通服务器
PC2连通服务器
三
1,配置每台设备和端口IP
r1配置命令sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sysn r1
[r1]int g0/0/0
[r1-GigabitEthernet0/0/0]ip add 10.0.2.2
^
Error:Incomplete command found at ‘^’ position.
[r1-GigabitEthernet0/0/0]int g0/0/1
[r1-GigabitEthernet0/0/1]ip add 10.0.1.1 8
Apr 2 2021 16:35:29-08:00 r1 %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP
on the interface GigabitEthernet0/0/1 has entered the UP state.
[r1-GigabitEthernet0/0/1]int g0/0/2
[r1-GigabitEthernet0/0/2]ip add 192.168.10.2
^
Error:Incomplete command found at ‘^’ position.
[r1-GigabitEthernet0/0/2]ip add 192.168.10.2 24
Apr 2 2021 16:37:01-08:00 r1 %%01IFNET/4/LINK_STATE(l)[1]:The line protocol IP
on the interface GigabitEthernet0/0/2 has entered the UP state.
[r1-GigabitEthernet0/0/2]
[r1-GigabitEthernet0/0/2]q
[r1]ip ro
[r1]ip route-st
[r1]ip route-static 192.168.20.0 24 10.0.2.1
[r1]ip ro
[r1]ip routes
[r1]ip route-s
[r1]ip route-static 192.168.30.0 24 10.0.1.2
R2配置命令
sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sysn r2
[r2]int g0/0/0
[r2-GigabitEthernet0/0/0]ip add 192.168.20.2 24
Apr 2 2021 16:32:55-08:00 r2 %%01IFNET/4/LINK_STATE(l)[2]:The line protocol IP
on the interface GigabitEthernet0/0/0 has entered the UP state.
[r2-GigabitEthernet0/0/0]int
^
Error: Unrecognized command found at ‘^’ position.
[r2-GigabitEthernet0/0/0]int g0/0/1
[r2-GigabitEthernet0/0/1]ip add 10.0.2.1 8
Apr 2 2021 16:33:32-08:00 r2 %%01IFNET/4/LINK_STATE(l)[3]:The line protocol IP
on the interface GigabitEthernet0/0/1 has entered the UP state.
[r2-GigabitEthernet0/0/1]
Please check whether system data has been changed, and save data in time
Configuration console time out, please press any key to log on
sys Enter system view, return user view with Ctrl+Z. [r2]ip ro [r2]ip route-s [r2]ip route-static 192.168.10.0 24 10.0.2.2 [r2]ip ro [r2]ip route-s [r2]ip route-static 192.168.30.0 24 10.0.2.2r3配置命令
sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sysn r3
[r3]int g0/0/0
[r3-GigabitEthernet0/0/0]ip add 10.0.1.2 8
Apr 2 2021 16:37:55-08:00 r3 %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP
on the interface GigabitEthernet0/0/0 has entered the UP state.
[r3-GigabitEthernet0/0/0]int g0/0/1
[r3-GigabitEthernet0/0/1]ip add 192.168.30.2 24
Apr 2 2021 16:38:43-08:00 r3 %%01IFNET/4/LINK_STATE(l)[1]:The line protocol IP
on the interface GigabitEthernet0/0/1 has entered the UP state.
[r3-GigabitEthernet0/0/1]q
[r3]ip ro
[r3]ip route -s
[r3]ip route-s
[r3]ip route-static 192.168.10.0 24 10.0.1.1
[r3]ip ro
[r3]ip route-
[r3]ip route-static 192.168.20.0 24 10.0.1.1
PC1连通PC2与PC3
PC2连通PC1与PC3
PC3连通PC2与PC1