
Router>en
Router#conf t
Router(config)#hostname R1
R1(config)#interface f0/0
R1(config-if)#ip address 192.168.1.254 255.255.255.0
R1(config-if)#no sh
R1(config-if)#int f0/1
R1(config-if)#ip address 12.1.1.1 255.255.255.0
R1(config-if)#no sh
R1(config-if)#exit
R1(config)#router ospf 1 --进入OSPF配置模式,进程号为1
R1(config-router)#router-id 1.1.1.1 --路由器ID为1.1.1.1
R1(config-router)#network 192.168.1.0 0.0.0.255 area 0 --发布直连网络,反掩码,区域号(注:OSPF必需有骨干区域,为区域0)
R1(config-router)#network 12.1.1.0 0.0.0.255 area 0 --发布直连网络,反掩码,区域号
R1(config-router)#end
R1#
查看OSPF邻居表:
R1#show ip ospf neighbor
2.2.2.2 1 FULL/DR 00:00:38 12.1.1.2 FastEthernet0/1
R1#
查看路由表:
R1#show ip route
Codes: C - connected, S - static, I - IGRP, 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, E - EGP
i - IS-IS, 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
C 12.1.1.0 is directly connected, FastEthernet0/1
C 192.168.1.0/24 is directly connected, FastEthernet0/0
O 192.168.2.0/24 [110/2] via 12.1.1.2, 00:00:20, FastEthernet0/1
R1#
验证在PC0拼PC1:
PC>ping 192.168.2.1
Reply from 192.168.2.1: bytes=32 time=33ms TTL=126
Reply from 192.168.2.1: bytes=32 time=32ms TTL=126
Reply from 192.168.2.1: bytes=32 time=38ms TTL=126
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 32ms, Maximum = 48ms, Average = 37ms
Router>en
Router#conf t
Router(config)#hostname R2
R1(config)#interface f0/0
R1(config-if)#ip address 192.168.2.254 255.255.255.0
R1(config-if)#no sh
R1(config-if)#int f0/1
R1(config-if)#ip address 12.1.1.2 255.255.255.0
R1(config-if)#no sh
R1(config-if)#exit
R1(config)#router ospf 1
R1(config-router)#router-id 2.2.2.2
R1(config-router)#network 192.168.2.0 0.0.0.255 area 0
R1(config-router)#network 12.1.1.0 0.0.0.255 area 0
R1(config-router)#end
R1#
查看邻居表:
R2#show ip ospf neighbor
1.1.1.1 1 FULL/BDR 00:00:38 12.1.1.1 FastEthernet0/1
R2#
R2#show ip route
Codes: C - connected, S - static, I - IGRP, 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, E - EGP
i - IS-IS, 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
C 12.1.1.0 is directly connected, FastEthernet0/1
O 192.168.1.0/24 [110/2] via 12.1.1.1, 00:03:08, FastEthernet0/1
C 192.168.2.0/24 is directly connected, FastEthernet0/0
R2#
验证在PC1拼PC0:
PC>ping 192.168.1.1
Reply from 192.168.1.1: bytes=32 time=30ms TTL=126
Reply from 192.168.1.1: bytes=32 time=37ms TTL=126
Reply from 192.168.1.1: bytes=32 time=40ms TTL=126
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 30ms, Maximum = 48ms, Average = 38ms
















