OSPF配置

TIM截图20181109111218.jpg

配置R1 R2 R3各个接口ip

[R1]interface GigabitEthernet 0/0/0
[R1-GigabitEthernet0/0/0]IP address 10.0.13.1 24
[R1-GigabitEthernet0/0/0]QU
[R1]interface GigabitEthernet 0/0/1
[R1-GigabitEthernet0/0/1]ip address 10.0.12.1 24    
[R1-GigabitEthernet0/0/1]qu
[R1]interface LoopBack 0
[R1-LoopBack0]ip address 10.0.1.1 24
[R1-LoopBack0]qu
[R1]display ip interface brief 
*down: administratively down
^down: standby
(l): loopback
(s): spoofing
The number of interface that is UP in Physical is 3
The number of interface that is DOWN in Physical is 2
The number of interface that is UP in Protocol is 3
The number of interface that is DOWN in Protocol is 2

Interface                         IP Address/Mask      Physical   Protocol  
GigabitEthernet0/0/0              10.0.13.1/24         up         up        
GigabitEthernet0/0/1              10.0.12.1/24         down       down      
GigabitEthernet0/0/2              unassigned           down       down      
LoopBack0                         10.0.1.1/24          up         up(s)     
NULL0                             unassigned           up         up(s)     
[R2]interface GigabitEthernet 0/0/1 
[R2-GigabitEthernet0/0/1]ip address 10.0.12.2 24
[R2-GigabitEthernet0/0/1]qu
[R2]interface LoopBack 0
[R2-LoopBack0]ip address 10.0.2.2 24    
[R2-LoopBack0]display ip interface brief 
*down: administratively down
^down: standby
(l): loopback
(s): spoofing
The number of interface that is UP in Physical is 3
The number of interface that is DOWN in Physical is 2
The number of interface that is UP in Protocol is 3
The number of interface that is DOWN in Protocol is 2

Interface                         IP Address/Mask      Physical   Protocol  
GigabitEthernet0/0/0              unassigned           down       down      
GigabitEthernet0/0/1              10.0.12.2/24         up         up        
GigabitEthernet0/0/2              unassigned           down       down      
LoopBack0                         10.0.2.2/24          up         up(s)     
NULL0                             unassigned           up         up(s) 
[R3]interface GigabitEthernet 0/0/0
[R3-GigabitEthernet0/0/0]ip address 10.0.13.2 24
[R3-GigabitEthernet0/0/0]qu
[R3]interface LoopBack 0
[R3-LoopBack0]ip address 10.0.3.3 24
[R3-LoopBack0]qu
[R3]interface LoopBack 3
[R3-LoopBack3]ip address 172.16.0.1 24
[R3-LoopBack3]qu
[R3]display ip interface brief 
*down: administratively down
^down: standby
(l): loopback
(s): spoofing
The number of interface that is UP in Physical is 4
The number of interface that is DOWN in Physical is 2
The number of interface that is UP in Protocol is 4
The number of interface that is DOWN in Protocol is 2

Interface                         IP Address/Mask      Physical   Protocol  
GigabitEthernet0/0/0              10.0.13.2/24         up         up        
GigabitEthernet0/0/1              unassigned           down       down      
GigabitEthernet0/0/2              unassigned           down       down      
LoopBack0                         10.0.3.3/24          up         up(s)     
LoopBack3                         172.16.0.1/24        up         up(s)     
NULL0                             unassigned           up         up(s) 

开启ospf

在R1上面开启ospf

[R1]ospf 1 router-id 10.0.1.1 
[R1-ospf-1]area 0
[R1-ospf-1-area-0.0.0.0]network 10.0.13.0 0.0.0.255 
[R1-ospf-1-area-0.0.0.0]network 10.0.12.0 0.0.0.255
[R1-ospf-1-area-0.0.0.0]network 10.0.1.0 0.0.0.255

在R2上面开启ospf

[R2]ospf 1 router-id 10.0.2.2 
[R2-ospf-1]area 0
[R2-ospf-1-area-0.0.0.0]network 10.0.12.0 0.0.0.255
[R2-ospf-1-area-0.0.0.0]network 10.0.2.0 0.0.0.255

在R2上面开启ospf

[R3]ospf 1 router-id 10.0.3.3
[R3-ospf-1]a    
[R3-ospf-1]area 0
[R3-ospf-1-area-0.0.0.0]network 10.0.3.0 0.0.0.255
[R3-ospf-1-area-0.0.0.0]network 10.0.13.0 0.0.0.255

在R1上面查看邻居关系

[R1-ospf-1-area-0.0.0.0]display ospf peer brief 

     OSPF Process 1 with Router ID 10.0.1.1
          Peer Statistic Information
 ----------------------------------------------------------------------------
 Area Id          Interface                        Neighbor id      State    
 0.0.0.0          GigabitEthernet0/0/0             10.0.3.3         Full        
 0.0.0.0          GigabitEthernet0/0/1             10.0.2.2         Full        
 ----------------------------------------------------------------------------

在R2上面测试ospf路由

[R2-ospf-1]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.0.1.1/32  OSPF    10   1           D   10.0.12.1       GigabitEthernet
0/0/1
       10.0.2.0/24  Direct  0    0           D   10.0.2.2        LoopBack0
       10.0.2.2/32  Direct  0    0           D   127.0.0.1       LoopBack0
     10.0.2.255/32  Direct  0    0           D   127.0.0.1       LoopBack0
       10.0.3.3/32  OSPF    10   2           D   10.0.12.1       GigabitEthernet
0/0/1
      10.0.12.0/24  Direct  0    0           D   10.0.12.2       GigabitEthernet
0/0/1
      10.0.12.2/32  Direct  0    0           D   127.0.0.1       GigabitEthernet
0/0/1
    10.0.12.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet
0/0/1
      10.0.13.0/24  OSPF    10   2           D   10.0.12.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-ospf-1]ping 10.0.12.2
  PING 10.0.12.2: 56  data bytes, press CTRL_C to break
    Reply from 10.0.12.2: bytes=56 Sequence=1 ttl=255 time=1 ms
    Reply from 10.0.12.2: bytes=56 Sequence=2 ttl=255 time=1 ms
    Reply from 10.0.12.2: bytes=56 Sequence=3 ttl=255 time=1 ms
    Reply from 10.0.12.2: bytes=56 Sequence=4 ttl=255 time=1 ms
    Reply from 10.0.12.2: bytes=56 Sequence=5 ttl=255 time=1 ms

  --- 10.0.12.2 ping statistics ---
    5 packet(s) transmitted
    5 packet(s) received
    0.00% packet loss
    round-trip min/avg/max = 1/1/1 ms

[R2-ospf-1]ping 10.0.3.3
  PING 10.0.3.3: 56  data bytes, press CTRL_C to break
    Reply from 10.0.3.3: bytes=56 Sequence=1 ttl=254 time=30 ms
    Reply from 10.0.3.3: bytes=56 Sequence=2 ttl=254 time=20 ms
    Reply from 10.0.3.3: bytes=56 Sequence=3 ttl=254 time=30 ms
    Reply from 10.0.3.3: bytes=56 Sequence=4 ttl=254 time=30 ms
    Reply from 10.0.3.3: bytes=56 Sequence=5 ttl=254 time=30 ms

  --- 10.0.3.3 ping statistics ---
    5 packet(s) transmitted
    5 packet(s) received
    0.00% packet loss
    round-trip min/avg/max = 20/28/30 ms

修改 OSPF hello 和 dead 时间参数

查看接口默认的hello dead 时间

[R1]display ospf interface GigabitEthernet 0/0/1

     OSPF Process 1 with Router ID 10.0.1.1
         Interfaces 


 Interface: 10.0.12.1 (GigabitEthernet0/0/1)
 Cost: 1       State: DR        Type: Broadcast    MTU: 1500  
 Priority: 1
 Designated Router: 10.0.12.1
 Backup Designated Router: 10.0.12.2
 Timers: Hello 10 , Dead 40 , Poll  120 , Retransmit 5 , Transmit Delay 1 

将GigabitEthernet0/0/1 的OSPF hello和dead时间分别修改为15秒和60秒。

[R1]interface GigabitEthernet 0/0/1
[R1-GigabitEthernet0/0/1]ospf timer hello 15
[R1-GigabitEthernet0/0/1]ospf timer dead 60
[R1-GigabitEthernet0/0/1]display ospf interface GigabitEthernet 0/0/1

     OSPF Process 1 with Router ID 10.0.1.1
         Interfaces 


 Interface: 10.0.12.1 (GigabitEthernet0/0/1)
 Cost: 1       State: DR        Type: Broadcast    MTU: 1500  
 Priority: 1
 Designated Router: 10.0.12.1
 Backup Designated Router: 10.0.12.2
 Timers: Hello 15 , Dead 60 , Poll  120 , Retransmit 5 , Transmit Delay 1 

修改hello dead时间后,端口接口由于时间配置不同将无法同步信息,导致其无法创建邻居关系,请对端接口的时间也进行更改。

OSPF 缺省路由发布

在R3上添加默认路由,并发布到ospf中

[R3]ip route-static 0.0.0.0 0.0.0.0 LoopBack 3
[R3]ospf 1
[R3-ospf-1]default-route-advertise

在R2中查看是否有默认路由出现

[R2-GigabitEthernet0/0/1]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   O_ASE   150  1           D   10.0.12.1       GigabitEthernet
0/0/1
       10.0.1.1/32  OSPF    10   1           D   10.0.12.1       GigabitEthernet
0/0/1
       10.0.2.0/24  Direct  0    0           D   10.0.2.2        LoopBack0
       10.0.2.2/32  Direct  0    0           D   127.0.0.1       LoopBack0
     10.0.2.255/32  Direct  0    0           D   127.0.0.1       LoopBack0
       10.0.3.3/32  OSPF    10   2           D   10.0.12.1       GigabitEthernet
0/0/1
      10.0.12.0/24  Direct  0    0           D   10.0.12.2       GigabitEthernet
0/0/1
      10.0.12.2/32  Direct  0    0           D   127.0.0.1       GigabitEthernet
0/0/1
    10.0.12.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet
0/0/1
      10.0.13.0/24  OSPF    10   2           D   10.0.12.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

控制 OSPF DR/BDR 的选举

查看R1 GigabitEthernet 0/0/0接口角色

[R1]display ospf interface GigabitEthernet 0/0/0

     OSPF Process 1 with Router ID 10.0.1.1
         Interfaces 


 Interface: 10.0.13.1 (GigabitEthernet0/0/0)
 Cost: 1       State: DR        Type: Broadcast    MTU: 1500  
 Priority: 1
 Designated Router: 10.0.13.1
 Backup Designated Router: 10.0.13.2
 Timers: Hello 10 , Dead 40 , Poll  120 , Retransmit 5 , Transmit Delay 1 

查看R3 GigabitEthernet 0/0/0接口角色

[R3]display ospf interface GigabitEthernet 0/0/0

     OSPF Process 1 with Router ID 10.0.3.3
         Interfaces 


 Interface: 10.0.13.2 (GigabitEthernet0/0/0)
 Cost: 1       State: BDR       Type: Broadcast    MTU: 1500  
 Priority: 1
 Designated Router: 10.0.13.1
 Backup Designated Router: 10.0.13.2
 Timers: Hello 10 , Dead 40 , Poll  120 , Retransmit 5 , Transmit Delay 1 

2个接口的ospf权重为1,根据router id来判断DR BDR角色,由于R1的值router id更小,R1的接口为DR

更改R1的ospf权重值

[R1]interface GigabitEthernet 0/0/0
[R1-GigabitEthernet0/0/0]ospf dr-priority 100

更改R3的ospf权重值

[R3]interface GigabitEthernet 0/0/0
[R3-GigabitEthernet0/0/0]ospf dr-priority 200

默认情况下,DR/BDR的选举采用的是非抢占模式。路由器优先级修改后,不会自动重新选举DR。因此,需要重置R1和R3间的OSPF邻居关系。

先关闭然后再打开R1和R3上的Gigabit Ethernet 0/0/0接口,重置R1和R3间的OSPF邻居关系。

[R3-GigabitEthernet0/0/0]shutdown 
[R3-GigabitEthernet0/0/0]undo shutdown 

查看DR BDR

[R1-GigabitEthernet0/0/0]display ospf interface GigabitEthernet 0/0/0

     OSPF Process 1 with Router ID 10.0.1.1
         Interfaces 


 Interface: 10.0.13.1 (GigabitEthernet0/0/0)
 Cost: 1       State: BDR       Type: Broadcast    MTU: 1500  
 Priority: 100
 Designated Router: 10.0.13.2
 Backup Designated Router: 10.0.13.1
 Timers: Hello 10 , Dead 40 , Poll  120 , Retransmit 5 , Transmit Delay 1 
[R3-GigabitEthernet0/0/0]display ospf interface GigabitEthernet 0/0/0

     OSPF Process 1 with Router ID 10.0.3.3
         Interfaces 


 Interface: 10.0.13.2 (GigabitEthernet0/0/0)
 Cost: 1       State: DR        Type: Broadcast    MTU: 1500  
 Priority: 200
 Designated Router: 10.0.13.2
 Backup Designated Router: 10.0.13.1
 Timers: Hello 10 , Dead 40 , Poll  120 , Retransmit 5 , Transmit Delay 1 
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 199,175评论 5 466
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 83,674评论 2 376
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 146,151评论 0 328
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,597评论 1 269
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,505评论 5 359
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 47,969评论 1 275
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,455评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,118评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,227评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,213评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,214评论 1 328
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,928评论 3 316
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,512评论 3 302
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,616评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,848评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,228评论 2 344
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 41,772评论 2 339

推荐阅读更多精彩内容