各路由器接口IP地址、环回地址按上图配置好
一、r1/4/5为全连的MGRE结构,r1/2/3为星型的拓扑结构,r1为中心站点
[r1]ip route-static 0.0.0.0 0 15.0.0.6
[r1]ip route-static 0.0.0.0 0 25.0.0.6 //设缺省路由,保证公网可通
[r1]interface Tunnel 0/0/0
[r1-Tunnel0/0/0]ip add 192.168.7.1 24
[r1-Tunnel0/0/0]tunnel-protocol gre p2mp //修改接口的封装协议为P2MP
[r1-Tunnel0/0/0]source 15.0.0.1 //规定公网的源IP地址
[r1-Tunnel0/0/0]nhrp network-id 100 //创建NHRP域
[r1-Tunnel0/0/0]nhrp entry 192.168.7.4 65.0.0.5 register
[r1-Tunnel0/0/0]nhrp entry 192.168.7.3 55.0.0.4 register
//1、在本地记录中心节点的隧道地址和物理地址的对应关系;
//2、该命令代表需要向中心节点(15.0.0.1)发送NHRP注册报文(注册报文中包含本地的隧道IP地址和物理IP地址);
//3、第一个IP是隧道IP,第二个IP为公网IP由于r1/4/5为全连的MGRE结构,所以每个路由都为hub节点,也都为分支节点,需要记录其他hub结点的对应关系
[r1-Tunnel0/0/0]nhrp entry multicast dynamic
//中心站点可以收到分支的数据包,但是,分支不能收到中心站点的数据报
--- MGRE环境下不支持广播或者组播行为
---- 在中心站点开启伪广播, 分别给所有节点发送单播以达到广播的效果
[r1]ip route-static 192.168.4.0 24 192.168.7.3
[r1]ip route-static 192.168.5.0 24 192.168.7.4
[r1]int t 0/0/1
[r1-Tunnel0/0/1]ip add 192.168.6.1 24
[r1-Tunnel0/0/1]tunnel-protocol gre p2mp
[r1-Tunnel0/0/1]source 25.0.0.1
[r1-Tunnel0/0/1]nhrp network-id 101
[r1-Tunnel0/0/1]nhrp entry multicast dynamic
//开启伪广播(在OSPF协议中hello包的组播更新必须开启此功能)的同时使得本机收到的下一跳注册信息能以伪广播发送出去,也就是说本机在伪广播的时候会广播到每一个nhrp peer表中字段type为dynamic的条目所对应的路由器上
[r1]ip route-static 192.168.2.0 24 192.168.6.2
[r1]ip route-static 192.168.3.0 24 192.168.6.3
[r2]ip route-static 0.0.0.0 0 35.0.0.6
[r2]int t0/0/1
[r2-Tunnel0/0/1]ip add 192.168.6.2 24
[r2-Tunnel0/0/1]tunnel-protocol gre p2mp
[r2-Tunnel0/0/1]source GigabitEthernet 0/0/0
[r2-Tunnel0/0/1]nhrp network-id 101
[r2-Tunnel0/0/1]nhrp entry 192.168.6.1 25.0.0.1 register
[r2]ip route-static 192.168.1.0 24 192.168.6.1
[r2]ip route-static 192.168.3.0 24 192.168.6.3
[r3]ip route-static 0.0.0.0 0 45.0.0.6
[r3]interface Tunnel0/0/1
[r3-Tunnel0/0/1]ip add 192.168.6.3 24
[r3-Tunnel0/0/1]tunnel-protocol gre p2mp
[r3-Tunnel0/0/1]source GigabitEthernet0/0/0
[r3-Tunnel0/0/1]nhrp network-id 101
[r3-Tunnel0/0/1]nhrp entry 192.168.6.1 25.0.0.1 register
[r3]ip route-static 192.168.1.0 24 192.168.6.1
[r3]ip route-static 192.168.2.0 24 192.168.6.2
[r4]ip route-static 0.0.0.0 0 55.0.0.6
[r4]interface Tunnel0/0/0
[r4-Tunnel0/0/0]ip add 192.168.7.3 24
[r4-Tunnel0/0/0]tunnel-protocol gre p2mp
[r4-Tunnel0/0/0]source 55.0.0.4
[r4-Tunnel0/0/0]nhrp network-id 100
[r4-Tunnel0/0/0]nhrp entry 192.168.7.1 15.0.0.1 register
[r4-Tunnel0/0/0]nhrp entry 192.168.7.4 65.0.0.5 register
[r4-Tunnel0/0/0]nhrp entry multicast dynamic
[r4-Tunnel0/0/0]q
[r4]ip route-static 192.168.1.0 24 192.168.7.1
[r4]ip route-static 192.168.5.0 24 192.168.7.4
[r5]ip route-static 0.0.0.0 0 65.0.0.6
[r5]interface Tunnel0/0/0
[r5-Tunnel0/0/0]ip add 192.168.7.4 24
[r5-Tunnel0/0/0]tunnel-protocol gre p2mp
[r5-Tunnel0/0/0]source 65.0.0.5
[r5-Tunnel0/0/0]nhrp network-id 100
[r5-Tunnel0/0/0]nhrp entry 192.168.7.1 15.0.0.1 register
[r5-Tunnel0/0/0]nhrp entry 192.168.7.3 55.0.0.4 register
[r5-Tunnel0/0/0]nhrp entry multicast dynamic
[r5]ip route-static 192.168.1.0 24 192.168.7.1
[r5]ip route-static 192.168.4.0 24 192.168.7.3
二、私有网段可以互相通讯,私有网段使用OSPF完成
[r1]ospf 1 router-id 1.1.1.1
[r1-ospf-1]area 0
[r1-ospf-1-area-0.0.0.2]network 192.168.7.1 0.0.0.0
[r1-ospf-1-area-0.0.0.2]network 192.168.6.1 0.0.0.0
[r1-ospf-1-area-0.0.0.2]network 192.168.1.1 0.0.0.0
[R1-Tunnel0/0/0]ospf network-type broadcast
//由于MGRE结构形成的隧道接口为p2p类型的接口,所以R1只会与R4或R5其中的一台路由器连通并建立ospf关系,所以我们要将三者隧道接口由p2p类型的接口修改为Broadcast(以太网类型)让中心站点R1与R4及R5都可以连通并建立ospf关系。
[r1-Tunnel0/0/1]ospf network-type p2mp
[r2]ospf 1 router-id 2.2.2.2
[r2-ospf-1]area 0
[r2-ospf-1-area-0.0.0.2]network 192.168.2.2 0.0.0.0
[r2-ospf-1-area-0.0.0.2]network 192.168.6.2 0.0.0.0
[r2-Tunnel0/0/1]ospf network-type p2mp
[r3]ospf 1 router-id 3.3.3.3
[r3-ospf-1]area 0
[r3-ospf-1-area-0.0.0.2]network 192.168.3.3 0.0.0.0
[r3-ospf-1-area-0.0.0.2]network 192.168.6.3 0.0.0.0
[r3-Tunnel0/0/1]ospf network-type p2mp
[r4]ospf 1 router-id 4.4.4.4
[r4-ospf-1]area 0
[r4-ospf-1-area-0.0.0.2]network 192.168.4.4 0.0.0.0
[r4-ospf-1-area-0.0.0.2]network 192.168.7.3 0.0.0.0
[R4-Tunnel0/0/0]ospf network-type broadcast
[r5]ospf 1 router-id 5.5.5.5
[r5-ospf-1]area 0
[r5-ospf-1-area-0.0.0.2]network 192.168.5.5 0.0.0.0
[r5-ospf-1-area-0.0.0.2]network 192.168.7.4 0.0.0.0
[r5-Tunnel0/0/0]ospf network-type broadcast