BBR1]
router ospf 100
pass f0/0
使用之前可以看到下面三条路由全部由f0/0
学习到
[Copy to clipboard]
CODE:
O E2 103.0.0.0/8 [110/20] via 219.146.241.1, 16:30:59, FastEthernet0/0
O IA 192.168.4.0/24 [110/66] via 219.146.241.1, 16:30:59, FastEthernet0/0
O 219.146.243.0/24 [110/65] via 219.146.241.1, 16:30:59, FastEthernet0/0
[验证结果]
使用之后看到全部由s1/1学习
[Copy to clipboard]
CODE:
O N2 103.0.0.0/8 [110/20] via 219.146.242.2, 00:00:07, Serial1/1
O IA 192.168.4.0/24 [110/194] via 219.146.242.2, 00:00:07, Serial1/1
O IA 219.146.243.0/24 [110/129] via 219.146.242.2, 00:00:07, Serial1/1
注意,实际上两个ospf连接中使用passiveinterface会导致接口down掉,因为hell包被cut
被动接口的意义在于使某个接口只接收路由更新而不发送更新,一般用于DDR
但是有些情况下,比如两个wan的ospf或eigrp,被动接口将导致HELLO包和Keepalive的发送导致无法建立邻居关系
所以被动接口有一定的局限性
有一个解决
方案是使用distribust-list制造一个伪被动接口,举例
router eigrp 100
net x.x.x.x
distri 11 out f0/0
access-list 11 deny any
这样的话,hello包还是正常的发送,邻居关系建立,但是任何更新都将被过滤
[路由更新过滤]
[BBR1]
router ospf 100
distribute-list 11 in s1/0.1
access-list 11 deny 192.168.2.0 0.0.0.255
access-list 11 permit any
实验之前我们可以看到192.168.2.0在BBR2上是通过s1/0.1学习来的,也就是从FR学习来的
[Copy to clipboard]
CODE:
O 192.168.2.0/24 [110/65] via 10.0.0.2, 00:00:04, Serial1/0.1
我们在BBR1上面实施distribute-list后,通过access-list定义禁止了192.168.2.0的更新
然后再在BBR1上查看的时候,关于192.168.2.0的路由条目已经消失,说明过滤成功
在BBR1上面使用 distribute-list 11 out f0/0的时候会得到提示
[Copy to clipboard]
CODE:
BBR1(config-router)#distribute-list 10 out f0/0
% Interface not allowed with OUT for
OSPF 被动接口的局限性会完全组织端口发送路由更新,有时候我们需要只是抑制些路由的更新,就要用到路由更新列表
[策略路由]
[BBR1]
access-list 19 permit 192.168.4.0 0.0.0.255
access-list 20 permit 192.168.3.0 0.0.0.255
route-map ip1 permit 10
match ip address 19
set interface s1/1
route-map ip2 permit 20
match ip address 20
set interface f0/0
int s1/0.1 mu
ip policy route-map ip1
ip policy route-map ip2
定义在BBR1上面让通过FR来自192.168.4.0的数据包,走s1/1的线路
定义在BBR1上面让通过FR来自192.168.3.0的数据保,走f0/0的线路
为了查看过程,我们先定义一个方便debug的ACL
access-list 101 permit icmp any 219.146.242.0 0.0.0.255
access-list 101 deny icmp any any
然后在BBR1上面debug ip pac 101
我们在192.168.4.0上面,ping 219.146.242.2
查看,结果如下
[验证结果]
[Copy to clipboard] CODE: 18:53:31: IP: tableid=0, s=192.168.4.1 (Serial1/0.1), d=219.146.242.1 (FastEthernet0/0), routed via RIB 18:53:31: IP: s=192.168.4.1 (Serial1/0.1), d=219.146.242.1 (Serial1/1), g=219.146.242.1, len 100, forward 18:53:31: IP: tableid=0, s=192.168.4.1 (Serial1/0.1), d=219.146.242.1 (FastEthernet0/0), routed via RIB 18:53:31: IP: s=192.168.4.1 (Serial1/0.1), d=219.146.242.1 (Serial1/1), g=219.146.242.1, len 100, forward 18:53:31: IP: tableid=0, s=192.168.4.1 (Serial1/0.1), d=219.146.242.1 (FastEthernet0/0), routed via RIB 18:53:31: IP: s=192.168.4.1 (Serial1/0.1), d=219.146.242.1 (Serial1/1), g=219.146.242.1, len 100, forward 18:53:31: IP: tableid=0, s=192.168.4.1 (Serial1/0.1), d=219.146.242.1 (FastEthernet0/0), routed via RIB 18:53:31: IP: s=192.168.4.1 (Serial1/0.1), d=219.146.242.1 (Serial1/1), g=219.146.242.1, len 100, forward 18:53:31: IP: tableid=0, s=192.168.4.1 (Serial1/0.1), d=219.146.242.1 (FastEthernet0/0), routed via RIB 18:53:31: IP: s=192.168.4.1 (Serial1/0.1), d=219.146.242.1 (Serial1/1), g=219.146.242.1, len 100, forward (Serial1/1), g=219.146.242.1, len 100, forward
|
可以看到上面来自4.0段的IP从s1/1出去
[Copy to clipboard] CODE: 19:03:39: IP: tableid=0, s=192.168.3.1 (Serial1/0.1), d=219.146.242.1 (FastEthernet0/0), routed via RIB 19:03:39: IP: s=192.168.3.1 (Serial1/0.1), d=219.146.242.1 (FastEthernet0/0), g=219.146.241.2, len 100, forward 19:03:39: IP: tableid=0, s=192.168.3.1 (Serial1/0.1), d=219.146.242.1 (FastEthernet0/0), routed via RIB 19:03:39: IP: s=192.168.3.1 (Serial1/0.1), d=219.146.242.1 (FastEthernet0/0), g=219.146.241.2, len 100, forward 19:03:39: IP: tableid=0, s=192.168.3.1 (Serial1/0.1), d=219.146.242.1 (FastEthernet0/0), routed via RIB 19:03:39: IP: s=192.168.3.1 (Serial1/0.1), d=219.146.242.1 (FastEthernet0/0), g=219.146.241.2, len 100, forward 19:03:40: IP: tableid=0, s=192.168.3.1 (Serial1/0.1), d=219.146.242.1 (FastEthernet0/0), routed via RIB 19:03:40: IP: s=192.168.3.1 (Serial1/0.1), d=219.146.242.1 (FastEthernet0/0), g=219.146.241.2, len 100, forward 19:03:40: IP: tableid=0, s=192.168.3.1 (Serial1/0.1), d=219.146.242.1 (FastEthernet0/0), routed via RIB 19:03:40: IP: s=192.168.3.1 (Serial1/0.1), d=219.146.242.1 (FastEthernet0/0), g=219.146.241.2, len 100, forward (FastEthernet0/0), g=219.146.241.2, len 100, forward
|
可以看到上面来自3.0段的IP从F0/0出去
要记住策略路由最基本的步骤
1,定义一个IP范围,Acl
2,定义一个RouterMAP
Match ACL范围的IP
Set 动作
Action 动作
3,定义好了以后要在某个接口上
应用 ip policy router-map mapname
[路由单项重发布以及AD/Metric更改]
[SW1]
router ospf 100
distance 40 [使用Distance
命令修改默认
管理距离]
distance 40 x.x.x.x 255.255.255.255[使用Distance 命令修改默认某条特定路由的管理距离]
redistribute rip sub metric 30 [修改metric]
[SR1]
int lo0
ip add 105.0.0.1 255.0.0.0
int lo1
ip add 106.0.0.1 255.0.0.0
router rip
net 105.0.0.0
net 106.0.0.0
[SR2]
int lo0
ip add 107.0.0.1 255.0.0.0
int lo1
ip add 108.0.0.1 255.0.0.0
router rip
net 107.0.0.0
net 108.0.0.0
增加这两个lo接口
地址是为了下一步实验
举例: 作为边界
路由器经常会学习到到达同一目的地的两条不同
协议的路由,比如RIP和EIGRP
然后这两种协议不具备可比性,一个是跳数,一个是带宽也延迟,那么就要比较管理距离,一个是120一个是90
肯定要选择EIGRP,那么我们可以通过Distance命令来让它优先选择RIP而不是EIGRP
他们只对本地有效,另外要注意它的意义所在,例如
router rip
distance 40
router ospf 100
distance 30
第一个是只有通过RIP学习到的路由更改AD为40
第二个是只有通过OSPF 100学习到的路由更改AD为30
到底什么学习来的,sh ip route的时候看前面的路由标识,R或者O或者其他
[使用Distance 命令修改默认管理距离] 修改之前,学习到的外部OSPF路由都是默认的110管理距离
[Copy to clipboard] CODE: C 102.0.0.0/8 is directly connected, FastEthernet1/3 O N2 103.0.0.0/8 [110/20] via 219.146.244.2, 00:00:02, FastEthernet1/4 C 101.0.0.0/8 is directly connected, FastEthernet1/2 O IA 172.17.0.0/16 [110/129] via 219.146.242.1, 00:00:02, Serial0/1 O IA 172.16.0.0/16 [110/192] via 219.146.242.1, 00:00:02, Serial0/1 O IA 172.19.0.0/16 [110/129] via 219.146.242.1, 00:00:02, Serial0/1 O IA 172.18.0.0/16 [110/193] via 219.146.242.1, 00:00:02, Serial0/1
|
....
通过distance 40命令修改之后,所有的通过ospf 100学习来的路由AD变为我们指定的40
[Copy to clipboard] CODE: C 102.0.0.0/8 is directly connected, FastEthernet1/3 O N2 103.0.0.0/8 [40/20] via 219.146.244.2, 00:00:18, FastEthernet1/4 C 101.0.0.0/8 is directly connected, FastEthernet1/2 O IA 172.17.0.0/16 [40/129] via 219.146.242.1, 00:00:18, Serial0/1 O IA 172.16.0.0/16 [40/192] via 219.146.242.1, 00:00:18, Serial0/1 O IA 172.19.0.0/16 [40/129] via 219.146.242.1, 00:00:18, Serial0/1 O IA 172.18.0.0/16 [40/193] via 219.146.242.1, 00:00:18, Serial0/1
|
[使用Distance 命令修改默认某条特定路由的管理距离]
所有的通过ospf 100学习来的路由都将被更改AD,如果我们只是希望更改某一条外部路由的metric
通过distance 扩展命令就不用根据进程号来进行管理距离的改变,而是根据从哪儿学习来的路由
这里我们拿RIP来实验
修改之前我们先再SW1上面查看学习到的RIP路由
[Copy to clipboard]
CODE:
R 106.0.0.0/8 [120/1] via 101.0.0.1, 00:00:11, FastEthernet1/2
R 105.0.0.0/8 [120/1] via 101.0.0.1, 00:00:12, FastEthernet1/2
R 108.0.0.0/8 [120/1] via 102.0.0.1, 00:00:16, FastEthernet1/3
R 107.0.0.0/8 [120/1] via 102.0.0.1, 00:00:22, FastEthernet1/3
都是从101.0.0.1学习来SR1的RIP路由,从102.0.0.1学习来SR2的RIP路由
我们现在让从101.0.0.1学习来的RIP路由的AD变为40
那么执行
router rip
distance 40 101.0.0.1 255.255.255.255
[Copy to clipboard]
CODE:
R 106.0.0.0/8 [40/1] via 101.0.0.1, 00:00:02, FastEthernet1/2
R 105.0.0.0/8 [40/1] via 101.0.0.1, 00:00:14, FastEthernet1/2
R 108.0.0.0/8 [120/1] via 102.0.0.1, 00:00:06, FastEthernet1/3
R 107.0.0.0/8 [120/1] via 102.0.0.1, 00:00:12, FastEthernet1/3
[distribute rip sub metric 30]
更改我们先查看学习到的RIP路由的Metric
[Copy to clipboard]
CODE:
SW2#sh ip route
O N2 102.0.0.0/8 [110/20] via 219.146.244.1, 00:00:02, FastEthernet1/4
O N2 108.0.0.0/8 [110/20] via 219.146.244.1, 00:00:02, FastEthernet1/4
O N2 106.0.0.0/8 [110/20] via 219.146.244.1, 00:00:03, FastEthernet1/4
O N2 107.0.0.0/8 [110/20] via 219.146.244.1, 00:00:03, FastEthernet1/4
O N2 105.0.0.0/8 [110/20] via 219.146.244.1, 00:00:03, FastEthernet1/4
...........
我们在SW1上面redistribute rip sub metric 30以后,再看SW2
[Copy to clipboard]
CODE:
SW2#sh ip route
CODE:
C 102.0.0.0/8 is directly connected, FastEthernet1/3
O N2 103.0.0.0/8 [110/20] via 219.146.244.2, 00:00:02, FastEthernet1/4
C 101.0.0.0/8 is directly connected, FastEthernet1/2
O IA 172.17.0.0/16 [110/129] via 219.146.242.1, 00:00:02, Serial0/1
O IA 172.16.0.0/16 [110/192] via 219.146.242.1, 00:00:02, Serial0/1
O IA 172.19.0.0/16 [110/129] via 219.146.242.1, 00:00:02, Serial0/1
O IA 172.18.0.0/16 [110/193] via 219.146.242.1, 00:00:02, Serial0/1
....
通过distance 40命令修改之后,所有的通过ospf 100学习来的路由AD变为我们指定的40
O N2 102.0.0.0/8 [110/30] via 219.146.244.1, 00:00:02, FastEthernet1/4
O N2 108.0.0.0/8 [110/30] via 219.146.244.1, 00:00:02, FastEthernet1/4
O N2 106.0.0.0/8 [110/30] via 219.146.244.1, 00:00:03, FastEthernet1/4
O N2 107.0.0.0/8 [110/30] via 219.146.244.1, 00:00:03, FastEthernet1/4
O N2 105.0.0.0/8 [110/30] via 219.146.244.1, 00:00:03, FastEthernet1/4
.........
router ospf 100
redistribute rip sub metric 30
结果的意思表明是通过ospf 100学习到的RIP路由的metric更改为30,一定要理解含义
跟前面的distance语法区分开