这里写目录标题
引言
路者,道也。路就是往来通行的地方。由,则是经过,比如必由之路,就是必须要经过的道路或地方。
顾名思义,路由就是选择路径的意思。
一、路由器
1.路由器的作用
- 路由
- 选择路径
2.路由器工作原理
根据路由表转发数据
3.路由表的形成
路由表实在路由器中维护的路由条目的集合,分为直连网段和非直连网段。
- 直连网段:本地接口自动形成
- 非直连网段:需要手动添加进路由器
二、静态路由、动态路由及浮动路由
1.静态路由
静态路由是由管理员手动添加的路由
优点:配置灵活,节省链路开销
缺点:当拓扑发生改变时,需要管理员每一台路由器都得修改配置。
静态路由适合比较简单的网络拓扑
2.动态路由
动态路由时路由器通过路由协议自动学习的路由
动态路由适合比较复杂的网络拓扑
3.默认路由
默认路由是一种特殊的静态路由,是当路由表中与数据包的目的地址之间没有匹配表项时路由器做出的选择。如果没有默认路由,那么目的地址在路由表中没有匹配表项的数据包将被丢弃。
表示形式:0.0.0.0 /0
只能在末梢网络中使用
4.浮动路由
浮动路由是指配置二条静态路由,默认选取链路质量优的作为主路径,当主路径出现故障时,由带宽较小的备份路由顶替,保持网络的不中断。
三、项目基本配置
1.拓扑图
2.项目要求
- 实现全网互通。
- 设置10.1.2.0 24 为备份链路,10.1.1.0 24 为主链路,默认走主链路通信,当主链路失效后,备份链路能立即变为主链路。
3.配置
PC1:
PC2:
PC3:
PC4:
交换机LSW1配置:
<Huawei>undo terminal monitor
Info: Current terminal monitor is off.
<Huawei>system-view
Enter system view, return user view with Ctrl+Z.
[Huawei-ui-console0]idle-timeout 0 0
[Huawei-ui-console0]sysname SW1
[SW1]vlan bat 2 3
Info: This operation may take a few seconds. Please wait for a moment...done.
[SW1]int e0/0/2
[SW1-Ethernet0/0/2]port link-type access
[SW1-Ethernet0/0/2]port default vlan 2
[SW1-Ethernet0/0/2]int e0/0/3
[SW1-Ethernet0/0/3]port link-type access
[SW1-Ethernet0/0/3]port default vlan 3
[SW1-Ethernet0/0/3]int g0/0/1
[SW1-GigabitEthernet0/0/1]port link-type trunk
[SW1-GigabitEthernet0/0/1]port trunk allow-pass vlan all
交换机LSW2:
<Huawei>undo terminal monitor
Info: Current terminal monitor is off.
<Huawei>system-view
Enter system view, return user view with Ctrl+Z.
[Huawei]user-interface console 0
[Huawei-ui-console0]idle-timeout 0 0
[SWB]sysname SWB
[SWB]vlan bat 4 5
Info: This operation may take a few seconds. Please wait for a moment...done.
[SWB]int e0/0/1
[SWB-Ethernet0/0/1]port link-type access
[SWB-Ethernet0/0/1]port default vlan 4
[SWB-Ethernet0/0/1]int e0/0/3
[SWB-Ethernet0/0/3]port link-type access
[SWB-Ethernet0/0/3]port default vlan 5
[SWB-Ethernet0/0/3]q
[SWB]int g0/0/1
[SWB-GigabitEthernet0/0/1]port link-type trunk
[SWB-GigabitEthernet0/0/1]port trunk allow-pass vlan all
路由器R1:
<Huawei>undo terminal monitor
Info: Current terminal monitor is off.
<Huawei>system-view
Enter system view, return user view with Ctrl+Z.
[Huawei]user-interface console 0
[Huawei-ui-console0]idle-timeout 0 0
[Huawei-ui-console0]sysname R1
[R1]int g0/0/2
[R1-GigabitEthernet0/0/2]undo shutdown
Info: Interface GigabitEthernet0/0/2 is not shutdown.
[R1-GigabitEthernet0/0/2]int g0/0/2.2
[R1-GigabitEthernet0/0/2.2]dot1q termination vid 2
[R1-GigabitEthernet0/0/2.2]ip address 192.168.2.1 24
[R1-GigabitEthernet0/0/2.2]arp broadcast enable
[R1-GigabitEthernet0/0/2.2]q
[R1]int g0/0/2.3
[R1-GigabitEthernet0/0/2.3]dot1q termination vid 3
[R1-GigabitEthernet0/0/2.3]ip address 192.168.3.1 24
[R1-GigabitEthernet0/0/2.3]arp broadcast enable
[R1-GigabitEthernet0/0/2.3]q
[R1]int g0/0/0
[R1-GigabitEthernet0/0/0]undo shutdown
Info: Interface GigabitEthernet0/0/0 is not shutdown.
[R1-GigabitEthernet0/0/0]ip address 10.1.1.1 24
[R1]ip route-static 0.0.0.0 0 10.1.1.2
[R1-GigabitEthernet0/0/0]int g0/0/1
[R1-GigabitEthernet0/0/1]undo shutdown
Info: Interface GigabitEthernet0/0/1 is not shutdown.
[R1-GigabitEthernet0/0/1]ip address 10.1.2.1 24
[R1]ip route-static 0.0.0.0 0 10.1.2.2 preference 65
[R1-GigabitEthernet0/0/1]q
路由器R2:
<Huawei>undo terminal monitor
Info: Current terminal monitor is off.
<Huawei>system-view
Enter system view, return user view with Ctrl+Z.
[Huawei]user-interface console 0
[Huawei-ui-console0]idle-timeout 0 0
[Huawei-ui-console0]sysname R2
[R2]int g0/0/2
[R2-GigabitEthernet0/0/2]undo shutdown
Info: Interface GigabitEthernet0/0/2 is not shutdown.
[R2-GigabitEthernet0/0/2]int g0/0/2.4
[R2-GigabitEthernet0/0/2.4]dot1q termination vid 4
[R2-GigabitEthernet0/0/2.4]ip address 192.168.4.1 24
[R2-GigabitEthernet0/0/2.4]arp broadcast enable
[R2-GigabitEthernet0/0/2.4]q
[R2]int g0/0/2.5
[R2-GigabitEthernet0/0/2.5]dot1q termination vid 5
[R2-GigabitEthernet0/0/2.5]ip address 192.168.5.1 24
[R2-GigabitEthernet0/0/2.5]arp broadcast enable
[R2-GigabitEthernet0/0/2.5]q
[R2]int g0/0/0
[R2-GigabitEthernet0/0/0]undo shutdown
Info: Interface GigabitEthernet0/0/0 is not shutdown.
[R2-GigabitEthernet0/0/0]ip add
[R2-GigabitEthernet0/0/0]ip address 10.1.1.2 24
[R2-GigabitEthernet0/0/0]q
[R2]ip route-static 0.0.0.0 0 10.1.1.1
[R2]int g0/0/1
[R2-GigabitEthernet0/0/1]undo shutdown
Info: Interface GigabitEthernet0/0/1 is not shutdown.
[R2-GigabitEthernet0/0/1]ip address 10.1.2.2 24
[R2-GigabitEthernet0/0/1]q
[R2]ip route-static 0.0.0.0 0 10.1.2.1 preference 65
4.测试
至此,PC1与PC2、PC3、PC4之间都能互通。
然后关闭主链路,继续测试:
测试结果如下:
PC1与PC2、PC3、PC4之间依然能够互通。
总结
1.数据包经过路由器,MAC地址要重新封装。
2.路由器通过路由表转发数据包。
3.静态路由需要双向逐跳配置。
4.默认路由可以简化路由器路由表配置,简洁高效。