拓扑图&IP划分如下:
以R1为例,R2~R4同理
interface GigabitEthernet 0/0/0
ip address 12.1.1.1 24
interface GigabitEthernet 0/0/1
ip address 13.1.1.1 24
interface LoopBack 0
ip address 1.1.1.1 32
以R2为例,R1&R3&R4同理,注意R1只配置RIP、R4只配置OSPF
rip 1 //开启RIP
version 2 //选择版本
network 12.0.0.0
network 2.0.0.0 //宣告网段
quit
ospf 1 router-id 2.2.2.2 //开启OSPF,并输入id号
area 0 //选择区域
network 24.1.1.1 0.0.0.0 //精准宣告
以R2为例,R3同理
import-route rip 1 //在OSPF里重发布RIP
quit
rip 1
import-route ospf 1 //在RIP里重发布OSPF
R1
ip ip-prefix xx deny 3.3.3.3 32 //禁止3.3.3.3访问R1
ip ip-prefix xx deny 34.1.1.0 24 //禁止34.1.1.0网段访问R1
ip ip-prefix xx permit 0.0.0.0 0 less-equal 32 //允许所有IP访问R1
rip 1
filter-policy ip-prefix xx import GigabitEthernet0/0/0
R3
ip ip-prefix xx permit 24.1.1.0 24
route-policy yy permit node 10
if-match ip-prefix xx
apply cost 3
quit
route-policy yy permit node 20
quit
rip 1
import-route ospf 1 route-policy yy
R3
ip ip-prefix nn permit 2.2.2.2 32
ip ip-prefix nn permit 12.1.1.0 24
route-policy mm permit node 10
if-match ip-prefix nn
apply tag 5
quit
route-policy mm permit node 20
quit
ospf 1
import-route rip 1 route-policy mm
R4
route-policy vv deny node 10
if-match tag 5
quit
route-policy vv deny node 20
quit
ospf 1
filter-policy route-policy vv import
R2
ip ip-prefix cc permit 13.1.1.0 24
route-policy kk deny node 10
Info: New Sequence of this List.
quit
route-policy kk deny node 20
quit
ospf 1
import-route rip 1 route-policy kk