直连路由的不足 不能去往非本身直连的其余网段(地方)
非直连路由:须要静态路由或动态路由,将网段添加到路由表中
问题?AR1上没有到达以下的网段路由网络
23.1.1.0/24 2.2.2.2/32 3.3.3.3/32
静态路由通常适用于结构简单的网络。不过,即便是在复杂网络环境中,合理地配置一些静态路由也能够改进网络的性能ide
A. [Huawei]ip route-static 目标网段 目标网段掩码 下一跳 B. [Huawei]ip route-static 目标网段 目标网段掩码 出接口 C. [Huawei]ip route-static 目标网段 目标网段掩码 出接口 下一跳 推荐使用该方式
[R1]ip route-static 23.1.1.0 24 12.1.1.2(下一跳) 串行链路 [R1]ip route-static 23.1.1.0 24 GigabitEthernet 0/0/0(出接口) 以太网 [R1]ip route-static 23.1.1.0 24 GigabitEthernet 0/0/0 12.1.1.2(出接口+下一跳)
目标网段:目标网段
目标网段掩码:掩码 能够写255.255.255.0 或者24
下一跳:到达目的地的下一站性能
[R1]display ip routing-table protocol static 查看路由表中的静态路由
注意:ping 3.3.3.3 SIP:12.1.1.1 DIP:3.3.3.3
由于R1配置接口IP地址后,只有12.1.1.0/24和1.1.1.1/32的直连路由,没有去往目标3.3.3.3的非直连路由,那么,咱们能够在R1上面配置以下静态路由到达3.3.3.3学习
ip route-static 3.3.3.3 255.255.255.255 g0/0/0 12.1.1.2
配置完成后,R1上面ping 3.3.3.3 发现没法ping通
由于数据在传递的过程当中,R1发现到达3.3.3.3得下一跳是12.1.1.2 是R2设备,那么R1会把这个数据传递给R2设备,此时R2设备上没有到达3.3.3.3的路由,R2设备会丢弃这个报文
那咱们能够在R2上面写静态路由,使其到达3.3.3.3路由测试
ip route-static 3.3.3.3 255.255.255.255 g0/0/1 23.1.1.3
配置完成后,R1上面ping 3.3.3.3 发现没法ping通
由于数据在传递的过程当中,R1发现到达3.3.3.3得下一跳是12.1.1.2 是R2设备,那么R1会把这个数据传递给R2设备,R2设备到达3.3.3.3的下一跳是23.1.1.3 是R3设备,而3.3.3.3路由恰好是R3自身的直连路由,因此,R3会接收这个数据。
可是,数据在传递过程当中,数据既能够发过去,数据也要可以回来,即发数据是R1到R3 回数据是R3到R1 因为R3上面没有到达12.1.1.0/24网段的路由,因此R3没法回应数据code
ip route-static 12.1.1.0 255.255.255.255 g0/0/1 23.1.1.2
在R3上面写完到达23.1.1.0的路由条目后,会把回应的数据包交给R2,R2发现到达12.1.1.0网段是本身的直连,所以把数据包交给R1blog
<R1>ping 3.3.3.3 PING 3.3.3.3: 56 data bytes, press CTRL_C to break Reply from 3.3.3.3: bytes=56 Sequence=1 ttl=254 time=40 ms Reply from 3.3.3.3: bytes=56 Sequence=2 ttl=254 time=30 ms Reply from 3.3.3.3: bytes=56 Sequence=3 ttl=254 time=50 ms Reply from 3.3.3.3: bytes=56 Sequence=4 ttl=254 time=20 ms Reply from 3.3.3.3: bytes=56 Sequence=5 ttl=254 time=40 ms --- 3.3.3.3 ping statistics --- 5 packet(s) transmitted 5 packet(s) received 0.00% packet loss round-trip min/avg/max = 20/36/50 ms <R1>
AR1的配置:接口
ip route-static 3.3.3.3 255.255.255.255 12.1.1.2
AR2的配置:ip
ip route-static 3.3.3.3 255.255.255.255 23.1.1.3
AR3的配置:资源
ip route-static 1.1.1.1 255.255.255.255 23.1.1.2
AR2的配置:
ip route-static 1.1.1.1 255.255.255.255 12.1.1.1
测试以下: <R1>ping -a 1.1.1.1 3.3.3.3 PING 3.3.3.3: 56 data bytes, press CTRL_C to break Reply from 3.3.3.3: bytes=56 Sequence=1 ttl=254 time=30 ms Reply from 3.3.3.3: bytes=56 Sequence=2 ttl=254 time=40 ms Reply from 3.3.3.3: bytes=56 Sequence=3 ttl=254 time=30 ms Reply from 3.3.3.3: bytes=56 Sequence=4 ttl=254 time=40 ms Reply from 3.3.3.3: bytes=56 Sequence=5 ttl=254 time=30 ms --- 3.3.3.3 ping statistics --- 5 packet(s) transmitted 5 packet(s) received 0.00% packet loss round-trip min/avg/max = 30/34/40 ms
AR1的配置:
ip route-static 2.2.2.2 255.255.255.255 12.1.1.2
AR2的配置:
ip route-static 1.1.1.1 255.255.255.255 12.1.1.1
测试以下:
<R1>ping -a 1.1.1.1 2.2.2.2 PING 2.2.2.2: 56 data bytes, press CTRL_C to break Reply from 2.2.2.2: bytes=56 Sequence=1 ttl=255 time=140 ms Reply from 2.2.2.2: bytes=56 Sequence=2 ttl=255 time=20 ms Reply from 2.2.2.2: bytes=56 Sequence=3 ttl=255 time=30 ms Reply from 2.2.2.2: bytes=56 Sequence=4 ttl=255 time=30 ms Reply from 2.2.2.2: bytes=56 Sequence=5 ttl=255 time=30 ms --- 2.2.2.2 ping statistics --- 5 packet(s) transmitted 5 packet(s) received 0.00% packet loss round-trip min/avg/max = 20/50/140 ms
AR2的配置:
ip route-static 3.3.3.3 255.255.255.255 23.1.1.3
AR3的配置:
ip route-static 2.2.2.2 255.255.255.255 23.1.1.2
测试以下:
<R2>ping -a 2.2.2.2 3.3.3.3 PING 3.3.3.3: 56 data bytes, press CTRL_C to break Reply from 3.3.3.3: bytes=56 Sequence=1 ttl=255 time=70 ms Reply from 3.3.3.3: bytes=56 Sequence=2 ttl=255 time=30 ms Reply from 3.3.3.3: bytes=56 Sequence=3 ttl=255 time=30 ms Reply from 3.3.3.3: bytes=56 Sequence=4 ttl=255 time=30 ms Reply from 3.3.3.3: bytes=56 Sequence=5 ttl=255 time=30 ms --- 3.3.3.3 ping statistics --- 5 packet(s) transmitted 5 packet(s) received 0.00% packet loss round-trip min/avg/max = 30/38/70 ms
AR1以下配置:
ip route-static 2.2.2.2 255.255.255.255 12.1.1.2 ip route-static 3.3.3.3 255.255.255.255 12.1.1.2 ip route-static 23.1.1.0 255.255.255.0 12.1.1.2
AR2以下配置:
ip route-static 1.1.1.1 255.255.255.255 12.1.1.1 ip route-static 3.3.3.3 255.255.255.255 23.1.1.3
AR3以下配置:
ip route-static 1.1.1.1 255.255.255.255 23.1.1.2 ip route-static 12.1.1.0 255.255.255.255 23.1.1.2 ip route-static 2.2.2.2 255.255.255.255 23.1.1.2
测试以下:
<R1>ping 2.2.2.2 PING 2.2.2.2: 56 data bytes, press CTRL_C to break Reply from 2.2.2.2: bytes=56 Sequence=1 ttl=255 time=30 ms Reply from 2.2.2.2: bytes=56 Sequence=2 ttl=255 time=10 ms Reply from 2.2.2.2: bytes=56 Sequence=3 ttl=255 time=30 ms Reply from 2.2.2.2: bytes=56 Sequence=4 ttl=255 time=30 ms Reply from 2.2.2.2: bytes=56 Sequence=5 ttl=255 time=20 ms --- 2.2.2.2 ping statistics --- 5 packet(s) transmitted 5 packet(s) received 0.00% packet loss round-trip min/avg/max = 10/24/30 ms <R1>ping 3.3.3.3 PING 3.3.3.3: 56 data bytes, press CTRL_C to break Reply from 3.3.3.3: bytes=56 Sequence=1 ttl=254 time=50 ms Reply from 3.3.3.3: bytes=56 Sequence=2 ttl=254 time=30 ms Reply from 3.3.3.3: bytes=56 Sequence=3 ttl=254 time=30 ms Reply from 3.3.3.3: bytes=56 Sequence=4 ttl=254 time=30 ms Reply from 3.3.3.3: bytes=56 Sequence=5 ttl=254 time=20 ms --- 3.3.3.3 ping statistics --- 5 packet(s) transmitted 5 packet(s) received 0.00% packet loss round-trip min/avg/max = 20/32/50 ms <R1>ping 23.1.1.3 PING 23.1.1.3: 56 data bytes, press CTRL_C to break Reply from 23.1.1.3: bytes=56 Sequence=1 ttl=254 time=30 ms Reply from 23.1.1.3: bytes=56 Sequence=2 ttl=254 time=40 ms Reply from 23.1.1.3: bytes=56 Sequence=3 ttl=254 time=40 ms Reply from 23.1.1.3: bytes=56 Sequence=4 ttl=254 time=50 ms Reply from 23.1.1.3: bytes=56 Sequence=5 ttl=254 time=40 ms --- 23.1.1.3 ping statistics --- 5 packet(s) transmitted 5 packet(s) received 0.00% packet loss round-trip min/avg/max = 30/40/50 ms <R1>ping -a 1.1.1.1 2.2.2.2 PING 2.2.2.2: 56 data bytes, press CTRL_C to break Reply from 2.2.2.2: bytes=56 Sequence=1 ttl=255 time=30 ms Reply from 2.2.2.2: bytes=56 Sequence=2 ttl=255 time=30 ms Reply from 2.2.2.2: bytes=56 Sequence=3 ttl=255 time=30 ms Reply from 2.2.2.2: bytes=56 Sequence=4 ttl=255 time=30 ms Reply from 2.2.2.2: bytes=56 Sequence=5 ttl=255 time=20 ms --- 2.2.2.2 ping statistics --- 5 packet(s) transmitted 5 packet(s) received 0.00% packet loss round-trip min/avg/max = 20/28/30 ms <R1>ping -a 1.1.1.1 3.3.3.3 PING 3.3.3.3: 56 data bytes, press CTRL_C to break Reply from 3.3.3.3: bytes=56 Sequence=1 ttl=254 time=50 ms Reply from 3.3.3.3: bytes=56 Sequence=2 ttl=254 time=30 ms Reply from 3.3.3.3: bytes=56 Sequence=3 ttl=254 time=30 ms Reply from 3.3.3.3: bytes=56 Sequence=4 ttl=254 time=30 ms Reply from 3.3.3.3: bytes=56 Sequence=5 ttl=254 time=30 ms --- 3.3.3.3 ping statistics --- 5 packet(s) transmitted 5 packet(s) received 0.00% packet loss round-trip min/avg/max = 30/34/50 ms <R1>ping -a 1.1.1.1 23.1.1.3 PING 23.1.1.3: 56 data bytes, press CTRL_C to break Reply from 23.1.1.3: bytes=56 Sequence=1 ttl=254 time=30 ms Reply from 23.1.1.3: bytes=56 Sequence=2 ttl=254 time=30 ms Reply from 23.1.1.3: bytes=56 Sequence=3 ttl=254 time=30 ms Reply from 23.1.1.3: bytes=56 Sequence=4 ttl=254 time=30 ms Reply from 23.1.1.3: bytes=56 Sequence=5 ttl=254 time=40 ms --- 23.1.1.3 ping statistics --- 5 packet(s) transmitted 5 packet(s) received 0.00% packet loss round-trip min/avg/max = 30/32/40 ms <R1>
默认路由通常来末节点配置 好处就是仅仅用一条路由代替全部路由条目
[Huawei]ip route-static 0.0.0.0 0 下一跳
R1的配置
ip route-static 2.2.2.2 255.255.255.255 12.1.1.2 ip route-static 3.3.3.3 255.255.255.255 12.1.1.2 ip route-static 23.1.1.0 255.255.255.0 12.1.1.2
简化本R1的配置
ip route-static 0.0.0.0 0 12.1.1.2 表明R1想要去往任何非直连路由都把数据包交给R2设备
简化本R3的配置
ip route-static 0.0.0.0 0.0.0.0 23.1.1.2 表明R3想要去往任何非直连路由都把数据包交给R2设备
思考以下:为何R2上面不能写默认路由?写了以后有什么问题出现?
由于R2设备处于R1和R3之间,若是在R2上面写默认路由
ip route-static 0.0.0.0 0 12.1.1.1 ip route-static 0.0.0.0 0 23.1.1.3
若是此时R1想要访问3.3.3.3,R1把数据包丢给R2的时候,R2此时有两个下一跳 一个是R1 一个是R3 那R2究竟是丢给R1呢仍是R3呢?因此,R2上面建议你们写明细路由,不要写默认路由
在串行接口上,能够经过指定下一跳地址或出接口或出接口+下一跳来配置静态路由
[RTA]ip route-static 192.168.2.0 24 10.0.12.2 [RTA]ip route-static 192.169.2.0 24 s1/0/0 [RTA]ip route-static 192.169.2.0 24 s1/0/0 10.0.12.2
在广播型的接口(如以太网接口)上配置静态路由时,必需要指定下一跳地址
[RTA]ip route-static 192.168.2.0 24 10.0.123.2 [RTA]ip route-static 192.169.2.0 24 G0/0/0 10.0.123.2
思考一下?为何不能用出接口呢?
AR1上访问2.2.2.2的时候,能够经过路径AR1-AR3-AR2 或者AR1-AR4-AR2 的负载分担
AR1的配置:
ip route-static 2.2.2.2 255.255.255.255 13.1.1.3 ip route-static 2.2.2.2 255.255.255.255 14.1.1.4
查看AR1的路由表
<R1>display ip routing-table protocol static Route Flags: R - relay, D - download to fib ------------------------------------------------------------------------------ Public routing table : Static Destinations : 1 Routes : 2 Configured Routes : 2 Static routing table status : <Active> Destinations : 1 Routes : 2 Destination/Mask Proto Pre Cost Flags NextHop Interface 2.2.2.2/32 Static 60 0 RD 13.1.1.3 GigabitEthernet 0/0/0 Static 60 0 RD 14.1.1.4 GigabitEthernet 0/0/1 Static routing table status : <Inactive> Destinations : 0 Routes : 0 <R1>
测试一下,利用tracert进行路由追踪
<R1>tracert -a 1.1.1.1 2.2.2.2 traceroute to 2.2.2.2(2.2.2.2), max hops: 30 ,packet length: 40,press CTRL_C t o break 1 13.1.1.3 130 ms 20 ms 14.1.1.4 30 ms 2 24.1.1.2 30 ms 20 ms 30 ms <R1>tracert -a 1.1.1.1 2.2.2.2 traceroute to 2.2.2.2(2.2.2.2), max hops: 30 ,packet length: 40,press CTRL_C t o break 1 14.1.1.4 140 ms 20 ms 10 ms 2 24.1.1.2 100 ms 20 ms 20 ms <R1>
浮动路由就是只让主链路进行工做,备链路不让转发流量
当主链路出现问题的时候,路由器会选择备用的链路,当主链路恢复的时候 路由器会选择主链路
在AR1上面的配置:
ip route-static 2.2.2.2 255.255.255.255 13.1.1.3 默认优先级是60 ip route-static 2.2.2.2 255.255.255.255 14.1.1.4 preference 70
查看AR1的路由表
[R1]display ip routing-table protocol static Route Flags: R - relay, D - download to fib ------------------------------------------------------------------------------ Public routing table : Static Destinations : 1 Routes : 2 Configured Routes : 2 Static routing table status : <Active> Destinations : 1 Routes : 1 Destination/Mask Proto Pre Cost Flags NextHop Interface 2.2.2.2/32 Static 60 0 RD 13.1.1.3 GigabitEthernet 0/0/0 Static routing table status : <Inactive> Destinations : 1 Routes : 1 Destination/Mask Proto Pre Cost Flags NextHop Interface 2.2.2.2/32 Static 70 0 R 14.1.1.4 GigabitEthernet 0/0/1 [R1]
当AR1的主链路down时候
[R1-GigabitEthernet0/0/0]shutdown Nov 16 2019 12:27:14-08:00 R1 %%01IFPDT/4/IF_STATE(l)[8]:Interface GigabitEthern et0/0/0 has turned into DOWN state. [R1]display ip routing-table protocol static Route Flags: R - relay, D - download to fib ------------------------------------------------------------------------------ Public routing table : Static Destinations : 1 Routes : 2 Configured Routes : 2 Static routing table status : <Active> Destinations : 1 Routes : 1 Destination/Mask Proto Pre Cost Flags NextHop Interface 2.2.2.2/32 Static 70 0 RD 14.1.1.4 GigabitEthernet 0/0/1 Static routing table status : <Inactive> Destinations : 1 Routes : 1 Destination/Mask Proto Pre Cost Flags NextHop Interface 2.2.2.2/32 Static 60 0 13.1.1.3 Unknown [R1]
当AR1的主用链路恢复正常时
[R1-GigabitEthernet0/0/0]undo shutdown Nov 16 2019 12:28:25-08:00 R1 %%01IFPDT/4/IF_STATE(l)[10]:Interface GigabitEther net0/0/0 has turned into UP state. [R1]display ip routing-table protocol static Route Flags: R - relay, D - download to fib ------------------------------------------------------------------------------ Public routing table : Static Destinations : 1 Routes : 2 Configured Routes : 2 Static routing table status : <Active> Destinations : 1 Routes : 1 Destination/Mask Proto Pre Cost Flags NextHop Interface 2.2.2.2/32 Static 60 0 RD 13.1.1.3 GigabitEthernet 0/0/0 Static routing table status : <Inactive> Destinations : 1 Routes : 1 Destination/Mask Proto Pre Cost Flags NextHop Interface 2.2.2.2/32 Static 70 0 R 14.1.1.4 GigabitEthernet 0/0/1 [R1]
静态路由---不能动态的根据现网拓扑的改变而改变能不能开发一款协议出来,让网络设备之间进行交换各类路由网段协议呢?因而在早期提出了rip协议 由于当时的网络结构比较简单,RIP协议可以颇有的胜任,而如今网络结构比较庞大,RIP协议已经不能知足于如今的网络当中,因此咱们企业网络中广泛都是OSPF路由协议,RIP协议咱们如今只是做为一个学习的一个协议而已,现网中几乎不用RIP协议