The ospf cost command sets a cost for an OSPF on an interface.
The undo ospf cost command restores the default cost for OSPF.
By default, OSPF automatically calculates its cost based on its interface bandwidth. The default cost of the loopback interface is 0.
Parameter | Description | Value |
---|---|---|
cost |
Specifies the cost of an OSPF-enabled interface. |
The value is an integer ranging from 1 to 65535. By default, it is 1. |
Usage Scenario
Generally, OSPF automatically calculate the link cost for an interface based on the bandwidth of the interface. You can modify the interface cost using the ospf cost command. For example, when you configure load balancing, you can run this command to modify the interface cost of the routes if conditions are satisfied for load balancing.
If no cost is set for an OSPF interface using the ospf cost command, OSPF automatically calculates its cost based on the interface bandwidth. The calculation formula is as follows: Cost of the interface = Bandwidth reference value/Interface bandwidth. The integer of the calculated result is the cost of the interface. If the calculated result is smaller than 1, the cost is 1. Changing the bandwidth reference value or interface bandwidth change the cost of an interface:
To use the bandwidth reference value to determine the interface cost, run the bandwidth-reference command.
To use the interface bandwidth to determine the interface cost, run the bandwidth command to set configuration bandwidth for an interface, and then run the bandwidth-config enable command to enable the device to calculate the cost for the interface based on the configuration bandwidth of the interface.
To use both the bandwidth reference value and interface bandwidth to determine the interface cost, run the preceding three commands.
Precautions
# Set the cost of VLANIF100 that runs OSPF to 65.
<HUAWEI> system-view
[HUAWEI] interface vlanif 100
[HUAWEI-Vlanif100] ospf cost 65
# Set the cost of GE0/0/1 that runs OSPF to 65.
<HUAWEI> system-view [HUAWEI] interface gigabitethernet 0/0/1 [HUAWEI-GigabitEthernet0/0/1] undo portswitch [HUAWEI-GigabitEthernet0/0/1] ospf cost 65