R1
enable
config terminal
host r1
no ip domain-lookup
int g0/0
ip address 192.168.1.1 255.255.255.0
no shut
exit
router ospf 100
!进程号,1-65535中任意数,且这个是路由器本地进程号,即其它路由器也可以设置一样的进程号
!OSPF路由协议的进程号为100,一个路由器上可启用多个OSPF进程,以进程号作为区别标志
network 192.168.1.0 0.0.0.255 area 1
router-id 192.168.1.1
!这个路由器有多个接口,谁代表本区域跟别的交换链路状态数据报呢?就是路由id是谁呢?指定路由id,不指定也会进行选举(优先级一样时,谁的ip地址大,就做)
exit
R2
enable
config terminal
host r2
no ip domain-lookup
int g0/0
ip address 192.168.1.2 255.255.255.0
no shut
exit
int g0/1
ip address 192.168.2.1 255.255.255.0
no shut
exit
router ospf 100
log-adjacency-changes
!当一个OSPF域的邻接关系改变时,用日志记录
network 192.168.1.0 0.0.0.255 area 1
network 192.168.2.0 0.0.0.255 area 0
router-id 192.168.2.1
!强制指定router-id为192.168.2.1。router-id(RID)的作用是在一个OSPF域(area)的路由器群中作为选举DR(指定路由器)及BDR(备份指定路由器)的重要指标,当各个路由器的优先级(priority)相同时,RID最高者为DR。注:在一个OSPF域内的路由器交换OSPF路由信息时,不是两两交互的,而是由DR收集并发布
exit
R3
enable
config terminal
host r3
no ip domain-lookup
!下面设置接口的IP参数
int g0/0
ip address 192.168.2.2 255.255.255.0
no shut
exit
int g0/1
ip address 192.168.3.1 255.255.255.0
no shut
exit
int loopback 0
!环回口,一般常用环回口来做router-id
ip address 3.3.3.3 255.255.255.255
no shut
exit
router ospf 100
network 192.168.2.0 0.0.0.255 area 0
network 192.168.3.0 0.0.0.255 area 2
router-id 3.3.3.3
!一般常用环回口来做router-id
!area 2 virtual-link 4.4.4.4
exit
R4
enable
config terminal
host r4
no ip domain-lookup
int g0/0
ip address 192.168.3.2 255.255.255.0
no shut
exit
int g0/1
ip address 192.168.4.1 255.255.255.0
no shut
exit
int loopback 0
ip address 4.4.4.4 255.255.255.255
no shut
exit
router ospf 100
network 192.168.3.0 0.0.0.255 area 2
network 192.168.4.0 0.0.0.255 area 3
router-id 4.4.4.4
!area 2 virtual-link 3.3.3.3
exit
R5
enable
config terminal
host r5
no ip domain-lookup
int g0/0
ip address 192.168.4.2 255.255.255.0
no shut
exit
int loopback 0
ip address 5.5.5.5 255.255.255.255
no shut
exit
router ospf 100
network 192.168.4.0 0.0.0.255 area 3
router-id 5.5.5.5
Exit
R1:
R2:
R3:
R4:
R5:
作者:aiworenyanzhousuanfa