一、实验:
image.png
步骤一:按照上图连接设备,配置各设备接口IP
步骤二:在各设备上配置OSPF:
SW1:
ospf 1
area 0
netw 192.168.12.1 0.0.0.0
SW2:
ospf 1
area 0
netw 192.168.12.2 0.0.0.0
netw 192.168.23.2 0.0.0.0
SW3:
ospf 1
area 0
netw 192.168.23.3 0.0.0.0
步骤三:引入缺省路由
首先,在SW2上创建一条静态默认路由
ip route-static 0.0.0.0 0 192.168.12.1
此时在SW2上ping 1.1.1.1,发现可以ping通:
Ping 1.1.1.1 (1.1.1.1): 56 data bytes, press CTRL_C to break
56 bytes from 1.1.1.1: icmp_seq=0 ttl=255 time=1.000 ms
56 bytes from 1.1.1.1: icmp_seq=1 ttl=255 time=0.000 ms
56 bytes from 1.1.1.1: icmp_seq=2 ttl=255 time=1.000 ms
56 bytes from 1.1.1.1: icmp_seq=3 ttl=255 time=2.000 ms
56 bytes from 1.1.1.1: icmp_seq=4 ttl=255 time=0.000 ms
但在SW3上由于没有默认路由,所以ping不通1.1.1.1:
Ping 1.1.1.1 (1.1.1.1): 56 data bytes, press CTRL_C to break
Request time out
Request time out
Request time out
Request time out
Request time out
然后在SW2上的OSPF进程中引入默认路由:
ospf 1
default-route-advertise
再查看SW2、SW3上的路由表:
SW2:
Destinations : 17 Routes : 17
Destination/Mask Proto Pre Cost NextHop Interface
0.0.0.0/0 Static 60 0 192.168.12.1 GE0/0
0.0.0.0/32 Direct 0 0 127.0.0.1 InLoop0
127.0.0.0/8 Direct 0 0 127.0.0.1 InLoop0
127.0.0.0/32 Direct 0 0 127.0.0.1 InLoop0
127.0.0.1/32 Direct 0 0 127.0.0.1 InLoop0
127.255.255.255/32 Direct 0 0 127.0.0.1 InLoop0
192.168.12.0/24 Direct 0 0 192.168.12.2 GE0/0
192.168.12.0/32 Direct 0 0 192.168.12.2 GE0/0
192.168.12.2/32 Direct 0 0 127.0.0.1 InLoop0
192.168.12.255/32 Direct 0 0 192.168.12.2 GE0/0
192.168.23.0/24 Direct 0 0 192.168.23.2 GE0/1
192.168.23.0/32 Direct 0 0 192.168.23.2 GE0/1
192.168.23.2/32 Direct 0 0 127.0.0.1 InLoop0
192.168.23.255/32 Direct 0 0 192.168.23.2 GE0/1
224.0.0.0/4 Direct 0 0 0.0.0.0 NULL0
224.0.0.0/24 Direct 0 0 0.0.0.0 NULL0
255.255.255.255/32 Direct 0 0 127.0.0.1 InLoop0
SW3:
Destinations : 14 Routes : 14
Destination/Mask Proto Pre Cost NextHop Interface
0.0.0.0/0 O_ASE2 150 1 192.168.23.2 GE0/1
0.0.0.0/32 Direct 0 0 127.0.0.1 InLoop0
127.0.0.0/8 Direct 0 0 127.0.0.1 InLoop0
127.0.0.0/32 Direct 0 0 127.0.0.1 InLoop0
127.0.0.1/32 Direct 0 0 127.0.0.1 InLoop0
127.255.255.255/32 Direct 0 0 127.0.0.1 InLoop0
192.168.12.0/24 O_INTRA 10 2 192.168.23.2 GE0/1
192.168.23.0/24 Direct 0 0 192.168.23.3 GE0/1
192.168.23.0/32 Direct 0 0 192.168.23.3 GE0/1
192.168.23.3/32 Direct 0 0 127.0.0.1 InLoop0
192.168.23.255/32 Direct 0 0 192.168.23.3 GE0/1
224.0.0.0/4 Direct 0 0 0.0.0.0 NULL0
224.0.0.0/24 Direct 0 0 0.0.0.0 NULL0
255.255.255.255/32 Direct 0 0 127.0.0.1 InLoop0
发现SW3上已经学习到了SW2引入的外部路由。
此时在SW3上再次ping 1.1.1.1,发现已经能够ping通:
Ping 1.1.1.1 (1.1.1.1): 56 data bytes, press CTRL_C to break
56 bytes from 1.1.1.1: icmp_seq=0 ttl=254 time=2.000 ms
56 bytes from 1.1.1.1: icmp_seq=1 ttl=254 time=2.000 ms
56 bytes from 1.1.1.1: icmp_seq=2 ttl=254 time=1.000 ms
56 bytes from 1.1.1.1: icmp_seq=3 ttl=254 time=1.000 ms
56 bytes from 1.1.1.1: icmp_seq=4 ttl=254 time=2.000 ms
二、外部路由cost计算方法:
缺省情况下,引入的外部路由为O_ASE2。
第一类外部路由O_ASE1:认为引入的外部路由可靠性较高
链路总开销=外部路由缺省开销+ASBR到接收者的开销
第二类外部路由O_ASE2:认为引入的外部路由可靠性较低
链路总开销=外部路由缺省开销
外部路由缺省开销=1(可更改)
三、更改外部路由类别
首先在SW2上取消引入默认路由命令:
ospf 1
undo default-route-advertise
然后输入以下命令:
ospf 1
default-route-advertise type 1
此时查看SW3的路由表:
Destinations : 14 Routes : 14
Destination/Mask Proto Pre Cost NextHop Interface
0.0.0.0/0 O_ASE1 150 3 192.168.23.2 GE0/1
0.0.0.0/32 Direct 0 0 127.0.0.1 InLoop0
127.0.0.0/8 Direct 0 0 127.0.0.1 InLoop0
127.0.0.0/32 Direct 0 0 127.0.0.1 InLoop0
127.0.0.1/32 Direct 0 0 127.0.0.1 InLoop0
127.255.255.255/32 Direct 0 0 127.0.0.1 InLoop0
192.168.12.0/24 O_INTRA 10 2 192.168.23.2 GE0/1
192.168.23.0/24 Direct 0 0 192.168.23.3 GE0/1
192.168.23.0/32 Direct 0 0 192.168.23.3 GE0/1
192.168.23.3/32 Direct 0 0 127.0.0.1 InLoop0
192.168.23.255/32 Direct 0 0 192.168.23.3 GE0/1
224.0.0.0/4 Direct 0 0 0.0.0.0 NULL0
224.0.0.0/24 Direct 0 0 0.0.0.0 NULL0
255.255.255.255/32 Direct 0 0 127.0.0.1 InLoop0
发现SW3上学习的外部路由类型已经变为O_ASE1。
此时分别改变SW2、SW3上的接口cost值:
SW2:
int g0/0
ospf cost 10
SW3:
int g0/1
ospf cost 20
查看SW3上的路由表,发现引入的外部路由cost已经改变:1+10+20=31。
Destinations : 14 Routes : 14
Destination/Mask Proto Pre Cost NextHop Interface
0.0.0.0/0 O_ASE1 150 31 192.168.23.2 GE0/1
0.0.0.0/32 Direct 0 0 127.0.0.1 InLoop0
127.0.0.0/8 Direct 0 0 127.0.0.1 InLoop0
127.0.0.0/32 Direct 0 0 127.0.0.1 InLoop0
127.0.0.1/32 Direct 0 0 127.0.0.1 InLoop0
127.255.255.255/32 Direct 0 0 127.0.0.1 InLoop0
192.168.12.0/24 O_INTRA 10 30 192.168.23.2 GE0/1
192.168.23.0/24 Direct 0 0 192.168.23.3 GE0/1
192.168.23.0/32 Direct 0 0 192.168.23.3 GE0/1
192.168.23.3/32 Direct 0 0 127.0.0.1 InLoop0
192.168.23.255/32 Direct 0 0 192.168.23.3 GE0/1
224.0.0.0/4 Direct 0 0 0.0.0.0 NULL0
224.0.0.0/24 Direct 0 0 0.0.0.0 NULL0
255.255.255.255/32 Direct 0 0 127.0.0.1 InLoop0
四、更改外部路由缺省开销
首先在SW2上取消引入默认路由命令。
然后输入以下命令:
default-route-advertise type 1 cost 5
查看SW3上的路由表,发现引入的外部路由cost已经改变:5+10+20=35
Destinations : 14 Routes : 14
Destination/Mask Proto Pre Cost NextHop Interface
0.0.0.0/0 O_ASE1 150 35 192.168.23.2 GE0/1
0.0.0.0/32 Direct 0 0 127.0.0.1 InLoop0
127.0.0.0/8 Direct 0 0 127.0.0.1 InLoop0
127.0.0.0/32 Direct 0 0 127.0.0.1 InLoop0
127.0.0.1/32 Direct 0 0 127.0.0.1 InLoop0
127.255.255.255/32 Direct 0 0 127.0.0.1 InLoop0
192.168.12.0/24 O_INTRA 10 30 192.168.23.2 GE0/1
192.168.23.0/24 Direct 0 0 192.168.23.3 GE0/1
192.168.23.0/32 Direct 0 0 192.168.23.3 GE0/1
192.168.23.3/32 Direct 0 0 127.0.0.1 InLoop0
192.168.23.255/32 Direct 0 0 192.168.23.3 GE0/1
224.0.0.0/4 Direct 0 0 0.0.0.0 NULL0
224.0.0.0/24 Direct 0 0 0.0.0.0 NULL0
255.255.255.255/32 Direct 0 0 127.0.0.1 InLoop0
如果在SW2上只是改变外部路由缺省cost,没有指定是type 1:
default-route-advertise cost 5
则查看SW3上的路由表,引入的外部路由cost为外部路由缺省cost=5。
Destinations : 14 Routes : 14
Destination/Mask Proto Pre Cost NextHop Interface
0.0.0.0/0 O_ASE2 150 5 192.168.23.2 GE0/1
0.0.0.0/32 Direct 0 0 127.0.0.1 InLoop0
127.0.0.0/8 Direct 0 0 127.0.0.1 InLoop0
127.0.0.0/32 Direct 0 0 127.0.0.1 InLoop0
127.0.0.1/32 Direct 0 0 127.0.0.1 InLoop0
127.255.255.255/32 Direct 0 0 127.0.0.1 InLoop0
192.168.12.0/24 O_INTRA 10 30 192.168.23.2 GE0/1
192.168.23.0/24 Direct 0 0 192.168.23.3 GE0/1
192.168.23.0/32 Direct 0 0 192.168.23.3 GE0/1
192.168.23.3/32 Direct 0 0 127.0.0.1 InLoop0
192.168.23.255/32 Direct 0 0 192.168.23.3 GE0/1
224.0.0.0/4 Direct 0 0 0.0.0.0 NULL0
224.0.0.0/24 Direct 0 0 0.0.0.0 NULL0
255.255.255.255/32 Direct 0 0 127.0.0.1 InLoop0