目录
路由概述
路由:从源主机到目标主机的转发过程
路由器的工作原理:根据路由表转发数据
路由表:
定义:路由器中维护的路由条目的集合
作用:路由器根据路由表做路劲选择
路由表的形成:
直连路由——本地接口配置IP地址和子网掩码,端口开启后,形成的路由
非直连路由——不是本地接口配置的IP地址和子网掩码,接口开启后,形成的路由
PS:对非直线路由的学习,有两种方式,一种管理员手动添加——静态路由,一种是路由器通过路由协议自动学习的方式——动态路由
静态路由
静态路由协议只能用于小规模的的企业网络,大型企业网络用的是动态路由协议
静态路由的优点:配置灵活,管理员手动配置,节省链路开销
静态路由的缺点:当拓扑发送改变的,需要管理员去每台路由器上修改路由配置
特点:管理员添加的路由传输方向是单向的
ps:建立五条以内的非直线路由用静态路由协议,五条以上用动态路由协议
展示,先搭建拓补图
R1:
R2:
R3:
PC2 PING PC1 能否通过
静态路由命令
IP route-static 目的网段、子网掩码 下一跳入接口IP
下一跳:指的是路由数据转发方向的下一台路由器
路由指明方向有两种方法
1、指明该条路由本地路由器接口
2、指明该条路由下一跳入接口IP
动态路由
距离矢量(Distance-Vector,DV)算法,是相邻的路由器之间互相交换整个路由表,并进行矢量的叠加,最后学习到整个路由表。
链路状态是一个层次式的,执行该算法的路由器不是简单的从相邻的路由器学习路由,而是把路由器分成区域,收集区域内所有路由器的链路状态信息,根据链路状态信息生成网络拓扑结构,每一个路由器再根据拓扑图计算出路由。
选取最优路由时的标准
1、子网掩码长度最长的,最优先匹配
2、选取路由协议中优先级最小的,最优先匹配
优先级:DIRECT:0
OSPF:10
IS-IS:15
STATTC:60
RIR:100
OSPF ASE:150
OSPF NSSA:150
IBGP:256
EBGP:256
3、相同路由协议情况下,选取mertric值最小的,最优先匹配
每种协议mertric值定义的都不相同,静态路由和路由优先级有关,这个是人为指定的,RIP协议和跳转有关;跳数越小越优先,OSPF协议和带宽有关,带宽最大的优先。metric是用来判断链路质量优劣的
4、如果以上都没有路由可以匹配上,就匹配默认路由
默认路由
表现形式:0.0.0.0/0——匹配所有网段
作用:当路由器在路由表中找不到目标网络的路由条目时,路由器把请求转发到默认路由
条件:默认路由是静态路由的一种特殊形成,它属于静态路由的一种,使用它只能在末梢/末节网络中使用。
命令:IP route-static 0.0.0.0 0 下一跳入接口网段
补充:出口网关的所有数据是丢给和出网关对接的运营商路由器的入接口IP,需要用到默认路由
浮动路由
浮动路由指的是配置俩条静态路由,默认选取链路质量优(带宽大)作为主路由,当主路劲出现故障时,由带宽较小的备份路劲顶替主路径。作用时保持网络的不中断,浮动路由在同一时刻,数据只会由一条链路进行转发
AR1:
<Huawei>undo terminal monitor //关闭弹窗信息
Info: Current terminal monitor is off.
<Huawei>system-view //进入系统视图
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 e1/0/0 //进入e1/0/0接口
[R1-Ethernet1/0/0]undo shutdown //开启接口
Info: Interface Ethernet1/0/0 is not shutdown.
[R1-Ethernet1/0/0]ip address 192.168.1.1 24 //给接口设置一个IP地址及子网掩码长度
[R1-Ethernet1/0/0]int g0/0/1 //进入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.1.1 24//设置IP地址和子网掩码
[R1-GigabitEthernet0/0/1]int e1/0/1//进入e1/0/1接口
[R1-Ethernet1/0/1]undo shutdown //开启接口
Info: Interface Ethernet1/0/1 is not shutdown.
[R1-Ethernet1/0/1]ip address 10.1.2.1 24//设置IP地址和子网掩码长度
[R1-Ethernet1/0/1]q
[R1]display ip routing-table //查看路由信息
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 13 Routes : 13
Destination/Mask Proto Pre Cost Flags NextHop Interface
10.1.1.0/24 Direct 0 0 D 10.1.1.1 GigabitEthernet
0/0/1
10.1.1.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/1
10.1.1.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/1
10.1.2.0/24 Direct 0 0 D 10.1.2.1 Ethernet1/0/1
10.1.2.1/32 Direct 0 0 D 127.0.0.1 Ethernet1/0/1
10.1.2.255/32 Direct 0 0 D 127.0.0.1 Ethernet1/0/1
127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0
127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
192.168.1.0/24 Direct 0 0 D 192.168.1.1 Ethernet1/0/0
192.168.1.1/32 Direct 0 0 D 127.0.0.1 Ethernet1/0/0
192.168.1.255/32 Direct 0 0 D 127.0.0.1 Ethernet1/0/0
255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
[R1]ip route-static 0.0.0.0 0 10.1.1.2 //默认主路径
[R1]ip route-static 0.0.0.0 0 10.1.2.2 preference 65 //备选路径,给一个优先级(大于60即可)
[R1]display ip routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 14 Routes : 14
Destination/Mask Proto Pre Cost Flags NextHop Interface
0.0.0.0/0 Static 60 0 RD 10.1.1.2 GigabitEthernet
0/0/1
10.1.1.0/24 Direct 0 0 D 10.1.1.1 GigabitEthernet
0/0/1
10.1.1.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/1
10.1.1.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/1
10.1.2.0/24 Direct 0 0 D 10.1.2.1 Ethernet1/0/1
10.1.2.1/32 Direct 0 0 D 127.0.0.1 Ethernet1/0/1
10.1.2.255/32 Direct 0 0 D 127.0.0.1 Ethernet1/0/1
127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0
127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
192.168.1.0/24 Direct 0 0 D 192.168.1.1 Ethernet1/0/0
192.168.1.1/32 Direct 0 0 D 127.0.0.1 Ethernet1/0/0
192.168.1.255/32 Direct 0 0 D 127.0.0.1 Ethernet1/0/0
255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
//此时静态路由只有一条默认路径,不会显示备选路径
R2:
<Huawei>undo terminal monitor //关闭弹窗信息
Info: Current terminal monitor is off.
<Huawei>system-view //进入系统视图
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname R2 //重命名R2
[R2]user-interface console 0
[R2-ui-console0]idle-timeout 0 0//永不超时
[R2-ui-console0]q
[R2]int g0/0/0//进入g0/0/1 接口
[R2-GigabitEthernet0/0/0]undo shutdown //开启接口
Info: Interface GigabitEthernet0/0/0 is not shutdown.
[R2-GigabitEthernet0/0/0]ip address 10.1.1.2 24 //设置IP地址和子网掩码
[R2-GigabitEthernet0/0/0]int e1/0/1
[R2-Ethernet1/0/1]undo shutdown
Info: Interface Ethernet1/0/1 is not shutdown.
[R2-Ethernet1/0/1]ip address 10.1.2.2 24
[R2-Ethernet1/0/1]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.3.2 24
[R2-GigabitEthernet0/0/1]q
[R2]display ip routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 13 Routes : 13
Destination/Mask Proto Pre Cost Flags NextHop Interface
10.1.1.0/24 Direct 0 0 D 10.1.1.2 GigabitEthernet
0/0/0
10.1.1.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
10.1.1.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
10.1.2.0/24 Direct 0 0 D 10.1.2.2 Ethernet1/0/1
10.1.2.2/32 Direct 0 0 D 127.0.0.1 Ethernet1/0/1
10.1.2.255/32 Direct 0 0 D 127.0.0.1 Ethernet1/0/1
10.1.3.0/24 Direct 0 0 D 10.1.3.2 GigabitEthernet
0/0/1
10.1.3.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/1
10.1.3.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/1
127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0
127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
[R2]ip route-static 192.168.1.0 24 10.1.1.1//默认主路径,添加静态路由(目的网段,子网掩码,下一跳入接口IP地址)
[R2]ip route-static 192.168.1.0 24 10.1.2.1 preference 65//备选路径
[R2]ip route-static 172.16.1.0 24 10.1.3.3//添加静态路由(目的网段,子网掩码,下一跳入接口IP地址)
R3;
<Huawei>undo terminal monitor
Info: Current terminal monitor is off.
<Huawei>system-view
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname R3
[R3]user-interface console 0
[R3-ui-console0]idle-timeout 0 0
[R3-ui-console0]q
[R3]int g0/0/0
[R3-GigabitEthernet0/0/0]undo shutdown
Info: Interface GigabitEthernet0/0/0 is not shutdown.
[R3-GigabitEthernet0/0/0]ip address 10.1.3.3 24
[R3-GigabitEthernet0/0/0]int e1/0/0
[R3-Ethernet1/0/0]undo shutdown
Info: Interface Ethernet1/0/0 is not shutdown.
[R3-Ethernet1/0/0]ip address 172.16.1.3 24
[R3-Ethernet1/0/0]q
[R3]display ip routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 10 Routes : 10
Destination/Mask Proto Pre Cost Flags NextHop Interface
10.1.3.0/24 Direct 0 0 D 10.1.3.3 GigabitEthernet
0/0/0
10.1.3.3/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
10.1.3.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0
127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
172.16.1.0/24 Direct 0 0 D 172.16.1.3 Ethernet1/0/0
172.16.1.3/32 Direct 0 0 D 127.0.0.1 Ethernet1/0/0
172.16.1.255/32 Direct 0 0 D 127.0.0.1 Ethernet1/0/0
255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
[R3]ip route-static 0.0.0.0 0 10.1.3.2//默认路由,下一跳入接口IP地址
测试一下
PC>ping 172.16.1.10
Ping 172.16.1.10: 32 data bytes, Press Ctrl_C to break
From 172.16.1.10: bytes=32 seq=1 ttl=125 time=31 ms
From 172.16.1.10: bytes=32 seq=2 ttl=125 time=32 ms
From 172.16.1.10: bytes=32 seq=3 ttl=125 time=15 ms
From 172.16.1.10: bytes=32 seq=4 ttl=125 time=32 ms
From 172.16.1.10: bytes=32 seq=5 ttl=125 time=31 ms
--- 172.16.1.10 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 15/28/32 ms
PC>tracert 172.16.1.10//追踪一下,如何到达目的IP地址的
traceroute to 172.16.1.10, 8 hops max
(ICMP), press Ctrl+C to stop
1 192.168.1.1 <1 ms 16 ms 15 ms
2 10.1.1.2 31 ms 16 ms 31 ms//走的是g接口
3 10.1.3.3 16 ms 16 ms 31 ms
4 172.16.1.10 15 ms 32 ms 31 ms
当我们关闭主路径,再看它的路径
总结
路由协议(英语:Routing protocol)是一种指定数据包转送方式的网上协议。Internet网络的主要节点设备是路由器,路由器通过路由表来转发接收到的数据。转发策略可以是人工指定的(通过静态路由、策略路由等方法)。