As we all know that, the default administrative distance of the OSPF is 110. However, in some cases, we will need to change this value to something else to manipulate the routing table to avoid routing loop or else. We use this following command to accomplish it.
distance <AD> <source address> <Mask> <ACL>
In OSPF, the source address is the router-id of the router advertising the network matched in ACL. Therefore, it is not necessarily the attached routers. See the configuration example below.
We have 4 routers R1,R2,R3,R4. R1 tries to change the administrative distance of the network advertised from R3 from 110 to 50. R3 has the router-id of 3.3.3.3. Therefore in R1, we can configure as followings.
Here is the routing table of R1
R1
Gateway of last resort is not set
20.0.0.0/24 is subnetted, 1 subnets
O E2 20.20.20.0 [110/20] via 192.168.1.2, 00:00:01, FastEthernet0/0
O IA 172.16.0.0/16 [110/21] via 192.168.4.1, 00:00:01, FastEthernet0/1
[110/21] via 192.168.1.2, 00:00:01, FastEthernet0/0
C 192.168.4.0/24 is directly connected, FastEthernet0/1
10.0.0.0/32 is subnetted, 1 subnets
C 10.10.10.10 is directly connected, Loopback0
C 192.168.1.0/24 is directly connected, FastEthernet0/0
O 192.168.2.0/24 [110/20] via 192.168.1.2, 00:00:01, FastEthernet0/0
O 192.168.3.0/24 [110/20] via 192.168.4.1, 00:00:01, FastEthernet0/1
30.0.0.0/32 is subnetted, 1 subnets
O 30.30.30.30 [110/21] via 192.168.4.1, 00:00:01, FastEthernet0/1
[110/21] via 192.168.1.2, 00:00:01, FastEthernet0/0
Check the ospf database seen by R1
Routing Bit Set on this LSA
LS age: 137
Options: (No TOS-capability, DC)
LS Type: Router Links
Link State ID: 3.3.3.3
Advertising Router:
3.3.3.3
LS Seq Number: 80000004
Checksum: 0x8D28
Length: 60
Area Border Router
Number of Links: 3
Link connected to: a
Stub Network
(Link ID) Network/subnet number:
30.30.30.30
(Link Data) Network Mask: 255.255.255.255
Number of TOS metrics: 0
TOS 0 Metrics: 1
Link connected to: a Transit Network
(Link ID) Designated Router address: 192.168.3.2
(Link Data) Router Interface address: 192.168.3.1
Number of TOS metrics: 0
TOS 0 Metrics: 10
Link connected to: a Transit Network
(Link ID) Designated Router address: 192.168.2.1
(Link Data) Router Interface address: 192.168.2.2
Number of TOS metrics: 0
TOS 0 Metrics: 10
We can see that R1 receive the LSA database from R3 ( area 0 - same area ). We apply the distance command to change the AD of ospf network from R3 as followings.
R1
router ospf 1
router-id 1.1.1.1
log-adjacency-changes
network 0.0.0.0 255.255.255.255 area 0
distance 50 3.3.3.3 0.0.0.0 1
access-list 1 permit any
This will change the AD for the network 30.30.30.30/32 to 50.
R1#sh ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route
Gateway of last resort is not set
20.0.0.0/24 is subnetted, 1 subnets
O E2 20.20.20.0 [110/20] via 192.168.1.2, 00:05:10, FastEthernet0/0
O IA 172.16.0.0/16 [50/21] via 192.168.4.1, 00:05:10, FastEthernet0/1
[50/21] via 192.168.1.2, 00:05:10, FastEthernet0/0
C 192.168.4.0/24 is directly connected, FastEthernet0/1
10.0.0.0/32 is subnetted, 1 subnets
C 10.10.10.10 is directly connected, Loopback0
C 192.168.1.0/24 is directly connected, FastEthernet0/0
O 192.168.2.0/24 [110/20] via 192.168.1.2, 00:05:10, FastEthernet0/0
O 192.168.3.0/24 [110/20] via 192.168.4.1, 00:05:10, FastEthernet0/1
30.0.0.0/32 is subnetted, 1 subnets
O 30.30.30.30 [50/21] via 192.168.4.1, 00:05:10, FastEthernet0/1
[50/21] via 192.168.1.2, 00:05:10, FastEthernet0/0