1. 程式人生 > 實用技巧 >ospf命令

ospf命令

https://blog.51cto.com/sweetpotato/1410762

1、配置步驟

1、配置loopback介面地址: //用於產生路由器的Router ID
Router(config)#interface loopback 0
Router(config-if)#ip address IP地址 掩碼

2、啟動OSPF路由程序: //本路由器的程序號,用於標識同一路由器上的多個OSPF程序
Router(config)#router ospf 程序號

3、指定OSPF協議執行的介面和所在區域:
Router(config-router)#network 網路號 反向掩碼 area 區域號
/*說明: **網路號:可以是網路地址、子網地址、介面地址 **反向掩碼:即子網掩碼的反碼(例如:192.168.2.0/28的反向掩碼為:0.0.0.15<-->因為子網掩碼為255.255.255.240,所以反向掩碼為:0.0.0.<255-240=15>) **區域號:指明網路所屬區域,此處是0-->骨幹區域(非0則為常規區域;單區域必須為骨幹區域哈) */

2、修改介面的cost值:

//修改介面的cost值(OSPF路由器在介面上使用cost值來決定最佳路徑,cost=10^8/BW)
Router(config-if)#ip ospf cost number

//舉例:
Router(config)#inteface s0
Router(config-if)#ip ospf cost 1000 //取值範圍1~65535

3、配置OSPF計時器:

//配置OSPF計時器(為了交換資訊,相鄰路由器必須有相同的hello和dead間隔,通常dead時間是hello時間的4倍)
Router(config-if)#ip ospf hello-interval 時間(s)
Router(config-if)#ip ospf dead-interval 時間(s)

4、Router ID的配置命令:

Router(config)#router ospf 程序號 //啟用OSPF
Router(config-router)#router-id IP_Address //指定Router-ID

5、OSPF彙總命令:

Router(config-router)#area 區域號
range 要彙總的IP 掩碼

6、驗證OSPF配置:

//驗證OSPF配置:
//檢視鄰居表
Router#show ip ospf neighbor
//檢視鏈路狀態資料庫
Router#show ip ospf database
//檢視路由表
Router#show ip route
//檢視OSPF的配置
Router#show ip ospf
//檢視OSPF介面資料結構
Router#show ip ospf interface 介面
Router#show ip ospf interface brief
//檢視配置檔案中有關OSPF的配置資訊
Router#show running-config | s r o

mpls2# show ip ospf
 OSPF Routing Process, Router ID: 192.168.122.164
 Supports only single TOS (TOS0) routes
 This implementation conforms to RFC2328
 RFC1583Compatibility flag is disabled
 OpaqueCapability flag is disabled
 Initial SPF scheduling delay 0 millisec(s)
 Minimum hold time between consecutive SPFs 50 millisec(s)
 Maximum hold time between consecutive SPFs 5000 millisec(s)
 Hold time multiplier is currently 1
 SPF algorithm last executed 4.165s ago
 Last SPF duration 129 usecs
 SPF timer is inactive
 LSA minimum interval 5000 msecs
 LSA minimum arrival 1000 msecs
 Write Multiplier set to 20 
 Refresh timer 10 secs
 This router is an ASBR (injecting external routing information)
 Number of external LSA 8. Checksum Sum 0x000230b6
 Number of opaque AS LSA 0. Checksum Sum 0x00000000
 Number of areas attached to this router: 1
 Area ID: 0.0.0.0 (Backbone)
   Number of interfaces in this area: Total: 4, Active: 4
   Number of fully adjacent neighbors in this area: 1
   Area has no authentication
   SPF algorithm executed 16654 times
   Number of LSA 3
   Number of router LSA 3. Checksum Sum 0x000101db
   Number of network LSA 0. Checksum Sum 0x00000000
   Number of summary LSA 0. Checksum Sum 0x00000000
   Number of ASBR summary LSA 0. Checksum Sum 0x00000000
   Number of NSSA LSA 0. Checksum Sum 0x00000000
   Number of opaque link LSA 0. Checksum Sum 0x00000000
   Number of opaque area LSA 0. Checksum Sum 0x00000000


mpls2# show ip ospf interface brief
No such interface name

mpls2# show ip ospf interface enp1s0 brief
% Unknown command: show ip ospf interface enp1s0 brief
mpls2# show ip ospf interface enp1s0 json 
{
  "interfaces":{
    "enp1s0":{
      "ifUp":true,
      "ifIndex":2,
      "mtuBytes":1500,
      "bandwidthMbit":4294967295,
      "ifFlags":"<UP,BROADCAST,RUNNING,MULTICAST>",
      "ospfEnabled":true,
      "ipAddress":"192.168.123.164",
      "ipAddressPrefixlen":24,
      "ospfIfType":"Broadcast",
      "localIfUsed":"192.168.123.255",
      "area":"0.0.0.0",
      "routerId":"192.168.122.164",
      "networkType":"BROADCAST",
      "cost":1,
      "transmitDelaySecs":1,
      "state":"DR",
      "priority":1,
      "mcastMemberOspfAllRouters":true,
      "mcastMemberOspfDesignatedRouters":true,
      "timerMsecs":10000,
      "timerDeadSecs":40,
      "timerWaitSecs":40,
      "timerRetransmitSecs":5,
      "timerHelloInMsecs":7648,
      "nbrCount":0,
      "nbrAdjacentCount":0
    }
  }
}
mpls2# show ip ospf neighbor

Neighbor ID     Pri State           Dead Time Address         Interface                        RXmtL RqstL DBsmL
192.168.122.198   1 Full/DROther      36.806s 192.168.1.3     enp6s0:192.168.1.4                   3     0     0
192.168.122.35    1 ExStart/DROther   36.238s 192.168.2.5     enp5s0:192.168.2.4                   0     0     0

mpls2# show ip ospf database

       OSPF Router with ID (192.168.122.164)

                Router Link States (Area 0.0.0.0)

Link ID         ADV Router      Age  Seq#       CkSum  Link count
192.168.122.35  192.168.122.35    12 0x800038bf 0x7ac1 2
192.168.122.164 192.168.122.164    6 0x80006449 0xcae1 4
192.168.122.198 192.168.122.198   11 0x80002079 0x7543 3

                AS External Link States

Link ID         ADV Router      Age  Seq#       CkSum  Route
172.19.2.0      192.168.122.35  1532 0x8000002b 0x5f6c E2 172.19.2.0/24 [0x0]
172.19.2.0      192.168.122.198 1057 0x8000002c 0x879f E2 172.19.2.0/24 [0x0]
192.168.1.3     192.168.122.164 1396 0x80000034 0x296c E2 192.168.1.3/32 [0x0]
192.168.1.4     192.168.122.198 1017 0x8000002d 0x6019 E2 192.168.1.4/32 [0x0]
192.168.2.4     192.168.122.35   872 0x8000002d 0x2bf0 E2 192.168.2.4/32 [0x0]
192.168.2.5     192.168.122.164 1516 0x80000034 0x0a88 E2 192.168.2.5/32 [0x0]
192.168.122.0   192.168.122.164 3600 0x80000026 0x2b02 E2 192.168.122.0/24 [0x0]
192.168.122.0   192.168.122.198 3600 0x80000026 0x5eac E2 192.168.122.0/24 [0x0]


mpls2# show ip ospf route
============ OSPF network routing table ============
N    4.4.4.4/32            [10] area: 0.0.0.0
                           directly attached to lo1
N    192.168.123.0/24      [1] area: 0.0.0.0
                           directly attached to enp1s0

============ OSPF router routing table =============

============ OSPF external routing table ===========


mpls2# show ip ospf route