取消
显示结果 
搜索替代 
您的意思是: 
cancel
2463
查看次数
0
有帮助
3
评论
碧云天
Spotlight
Spotlight
本帖最后由 碧云天 于 2020-2-3 22:03 编辑
一.概述
思科路由器添加静态路由,不考虑其他参数,只考虑接口和下一跳地址的话,有三种配置方式:
1.只写出站接口地址:这种一般在点到点网络中采用
2.只写下一跳地址:这种一般在MA网络中采用
3.同时写出站接口地址和下一跳地址:这种听闫辉老师的NP视频,建议在MA网络中也采用,视频中说的TCP/IP路由技术卷一错误我在书中没有找到具体地方,有可能书的作者在写静态路由下一跳为非直连网络地址的时候,没有添加出站接口,而只是静态路由下一跳地址为直连网络地址的时候,才同时填写了出站接口和下一跳地址,或只写了下一跳地址,这样是可以实现选路的。
测试总结(MA网络)1:
1.静态路由如果同时添加接口和下一跳地址,路由器会在配置的接口立即发送arp请求,确定下一跳地址对应的mac地址
---只添加直连的下一跳地址,也会立即发送arp请求对应的地址的mac,非直连的下一跳地址,因为不知道走哪个接口,所以不会发
2.当下一跳地址为直连地址时,如果得到对应的arp回复,会直接加入arp缓存中
3.当下一跳地址为非直接地址时,需要对应接口所在广播域的其他路由器的接口启用代理arp,并符合代理arp工作的条件
4.路由器接收到代理arp的回复,会先判断,如果它没有到非直连网络的路由(即应答者IP地址所在的网段是否可达),不会加入arp缓存中
5.如果有到非直连网络的路由(这时这个路由只是作为是否加入arp缓存的一个条件),对选路没有任何影响
测试总结(MA网络)2:另外一种情况
1..静态路由添加的时候,下一跳地址为非直连网络的地址,并且没有配置出站接口
2.这时路由器不会发出arp请求,这时前面那个判断是否加入加入arp缓存的非直连网络的路由就会排上用场
3.如果这时,这个到非直连网络的路由同时添加了出站接口和直连地址,或者只是添加了直连地址,它就确定了选路,到非直连网段第一跳只会走指定那个IP走。
代理arp工作的条件:

  • 判断arp的请求者与被请求者是否在不同网段
  • 有源与目的的路由条目
  • 接口arp功能开启

二.测试拓扑
190053qnj9armpps2zn66z.png

二.基本配置
1.R4路由器

interface Ethernet0/0
ip address 100.1.1.4 255.255.255.0
no shutdown
2.R5路由器
interface Ethernet0/0
ip address 100.1.1.5 255.255.255.0
no shutdown
interface Ethernet0/1
ip address 200.2.2.5 255.255.255.0
no shutdown
3.R6路由器
interface Ethernet0/0
ip address 100.1.1.6 255.255.255.0
no shutdown
interface Ethernet0/1
ip address 200.2.2.6 255.255.255.0
no shutdown
4.R7路由器
interface Loopback0
ip address 10.0.1.1 255.255.255.0
interface Loopback1
ip address 10.1.0.1 255.255.255.0
interface Loopback2
ip address 10.2.0.1 255.255.255.0
interface Loopback3
ip address 10.3.0.1 255.255.255.0
interface Ethernet0/0
ip address 200.2.2.7 255.255.255.0
no shutdown
三.路由配置
---只是测试R4不同路由的添加方式,所以R4的路由先不添加
1.R5和R6路由器

ip route 10.0.1.0 255.255.255.0 200.2.2.7
ip route 10.1.0.0 255.255.255.0 200.2.2.7
ip route 10.2.0.0 255.255.255.0 200.2.2.7
ip route 10.3.0.0 255.255.255.0 200.2.2.7
2.R7路由器
ip route 100.1.1.0 255.255.255.0 Ethernet0/0
四.第一种情况:R4到R7身后网络的路由同时添加出站接口和下一跳地址

---此时R4没有配置任何路由,如果已经配置了路由,需要清除所有路由配置,让后shutdown e0/0接口,再clear arp-cache,再no shutdown e0/0

1.R4路由器先debug arp

2.此时如果配置静态路由同时指定了出站接口和下一跳地址,可以看到路由发出了arp请求,并且对回复的arp做了过滤,因为路由器没有到200.2.2.0网段的路由

R4(config-if)#do debug arp
ARP packet debugging is on
R4(config-if)#ip route 10.0.1.0 255.255.255.0 Ethernet0/0 200.2.2.7
R4(config)#
*Feb 2 08:31:09.899: IP ARP: creating incomplete entry for IP address: 200.2.2.7 interface Ethernet0/0
*Feb 2 08:31:09.899: IP ARP: sent req src 100.1.1.4 aabb.cc00.4000,
dst 200.2.2.7 0000.0000.0000 Ethernet0/0
*Feb 2 08:31:09.899: IP ARP rep filtered src 200.2.2.7 aabb.cc00.5000, dst 100.1.1.4 aabb.cc00.4000 wrong cable, interface Ethernet0/0
*Feb 2 08:31:09.899: IP ARP rep filtered src 200.2.2.7 aabb.cc00.6000, dst 100.1.1.4 aabb.cc00.4000 wrong cable, interface Ethernet0/0
R4(config)#
3.路由器添加到非直连网络的路由,这时三种选择,只添加出站接口,只添加直连的下一跳地址,同时添加出站接口和下一跳地址,假定同时添加出站接口和下一跳地址
R4(config)#ip route 200.2.2.0 255.255.255.0 e0/0 10.1.1.5
R4(config)#
*Feb 2 09:20:41.793: IP ARP: creating incomplete entry for IP address: 10.1.1.5 interface Ethernet0/0
*Feb 2 09:20:41.793: IP ARP: sent req src 100.1.1.4 aabb.cc00.4000,
dst 10.1.1.5 0000.0000.0000 Ethernet0/0
R4(config)#do show arp
Protocol Address Age (min) Hardware Addr Type Interface
Internet 10.1.1.5 0 Incomplete ARPA
Internet 100.1.1.4 - aabb.cc00.4000 ARPA Ethernet0/0
这时可以看到,即使添加了路由,200.2.2.7的mac地址没有出现在arp缓存中,因为路由器不会老是发arp请求包,可以先添加这条路由,再添加下一条地址为非直连网络的路由,也可以直接ping一个包
从下面的日志可以看到,200.2.2.7的mac地址已经加入的arp缓存中,并且后到的会冲掉先到的

R4(config)#do ping 10.0.1.1 repeat 1
Type escape sequence to abort.
Sending 1, 100-byte ICMP Echos to 10.0.1.1, timeout is 2 seconds:
*Feb 2 09:21:56.293: IP ARP: creating incomplete entry for IP address: 200.2.2.7 interface Ethernet0/0
*Feb 2 09:21:56.293: IP ARP: sent req src 100.1.1.4 aabb.cc00.4000,
dst 200.2.2.7 0000.0000.0000 Ethernet0/0
*Feb 2 09:21:56.294: IP ARP: rcvd rep src 200.2.2.7 aabb.cc00.5000, dst 100.1.1.4 Ethernet0/0
*Feb 2 09:21:56.294: IP ARP: rcvd rep src 200.2.2.7 aabb.cc00.6000, dst 100.1.1.4 Ethernet0/0.
Success rate is 0 percent (0/1)
R4(config)#do show arp
Protocol Address Age (min) Hardware Addr Type Interface
Internet 100.1.1.4 - aabb.cc00.4000 ARPA Ethernet0/0
Internet 200.2.2.7 0 aabb.cc00.6000 ARPA Ethernet0/0
R4(config)#
再ping一个包就通了,因为已经200.2.2.7的mac地址
R4(config)#do ping 10.0.1.1 repeat 1
Type escape sequence to abort.
Sending 1, 100-byte ICMP Echos to 10.0.1.1, timeout is 2 seconds:
!
Success rate is 100 percent (1/1), round-trip min/avg/max = 1/1/1 ms
R4(config)#
4.这时把R5的e0/0接口shutdown,还是可以ping通的
--因为从上面的mac地址来看,是R6的接口地址,而不是ip route 200.2.2.0 255.255.255.0 e0/0 100.1.1.5指定的R5的
R5(config-if)#no sh
R5(config-if)#
*Feb 2 09:24:07.522: %LINK-3-UPDOWN: Interface Ethernet0/0, changed state to up
*Feb 2 09:24:08.529: %LINEPROTO-5-UPDOWN: Line protocol on Interface Ethernet0/0, changed state to up
R5(config-if)#
R4(config)#do ping 10.0.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.0.1.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms
R4(config)#
五.第二种情况:R4到R7身后网络的路由只添加下一跳地址
---此时R4没有配置任何路由,如果已经配置了路由,需要清除所有路由配置,让后shutdown e0/0接口,再clear arp-cache,再no shutdown e0/0
1.R4路由器先debug arp
2.此时如果配置静态路由同时只指定下一跳地址,可以看到并没有发出arp请求
R4(config)#do debug arp
ARP packet debugging is on
R4(config)#ip route 10.0.1.0 255.255.255.0 200.2.2.7
R4(config)#do show arp
Protocol Address Age (min) Hardware Addr Type Interface
Internet 100.1.1.4 - aabb.cc00.4000 ARPA Ethernet0/0
R4(config)#
3.此时如果添加添加到非直连网络的路由时指定了下一跳地址,或者既指定了出站接口和下一跳地址,是可以确定选路的
--比如同时添加出站接口和下一跳地址为R5接口地址
R4(config)#ip route 200.2.2.0 255.255.255.0 e0/0 100.1.1.5
R4(config)#
*Feb 2 09:08:57.409: IP ARP: creating incomplete entry for IP address: 100.1.1.5 interface Ethernet0/0
*Feb 2 09:08:57.409: IP ARP: sent req src 100.1.1.4 aabb.cc00.4000,
dst 100.1.1.5 0000.0000.0000 Ethernet0/0
*Feb 2 09:08:57.409: IP ARP: rcvd rep src 100.1.1.5 aabb.cc00.5000, dst 100.1.1.4 Ethernet0/0
R4(config)#
4.这时R4 ping 10.0.1.1可以ping通
R4(config)#do ping 10.0.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.0.1.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/2/5 ms
R4(config)#
5.但是这时如果shutdown R5的e0/0接口,并且在R7上开启debug ip icmp
R5(config-if)#shutdown
R5(config-if)#
*Feb 2 09:10:47.651: %LINK-5-CHANGED: Interface Ethernet0/0, changed state to administratively down
*Feb 2 09:10:48.655: %LINEPROTO-5-UPDOWN: Line protocol on Interface Ethernet0/0, changed state to down
R5(config-if)#
R7#debug ip icmp
ICMP packet debugging is on
R7#
6.R4再ping ping 10.0.1.1已经不通了,在R7上面也不由icmp到达的包
--说明走R5的路由起了选路作用,只是因为R5接口的问题,才导致数据包无法正常到达R7
R4#show ip route | begin Gateway
Gateway of last resort is not set
10.0.0.0/24 is subnetted, 1 subnets
S 10.0.1.0 [1/0] via 200.2.2.7
100.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C 100.1.1.0/24 is directly connected, Ethernet0/0
L 100.1.1.4/32 is directly connected, Ethernet0/0
S 200.2.2.0/24 [1/0] via 100.1.1.5, Ethernet0/0
R4#
评论
one-time
Level 13
Level 13
感谢楼主分享,谢谢~
liukaiyang
Level 1
Level 1
感谢分享
likuo
Spotlight
Spotlight
增加知识点。
入门指南

使用上面的搜索栏输入关键字、短语或问题,搜索问题的答案。

我们希望您在这里的旅程尽可能顺利,因此这里有一些链接可以帮助您快速熟悉思科社区:









快捷链接