一、拓扑图


二、实验目的

1.使用vpn一对多。让pc2可以连通pc0和pc1


三、设备ip配置

Pc0:ip地址:10.2.2.1 掩码:255.255.255.0 网关:10.2.2.254 Pc1:ip地址:10.3.3.1 掩码:255.255.255.0 网关:10.3.3.254 Pc2:ip地址:10.1.1.1 掩码:255.255.255.0 网关:10.1.1.254 R1:fa0/0:ip地址:10.1.1.254 掩码:255.255.255.0 R1:fa0/1:ip地址:101.0.0.1 掩码:255.255.255.252 R2:gig0/0:ip地址:101.0.0.2 掩码:255.255.255.252 R2:gig0/1:ip地址:103.0.0.2 掩码:255.255.255.252 R2:gig0/2:ip地址:102.0.0.2 掩码:255.255.255.252 R3:fa0/0:ip地址:102.0.0.1 掩码:255.255.255.252 R3:fa0/1:ip地址:10.2.2.254 掩码:255.255.255.0 R4:fa0/0:ip地址:103.0.0.1 掩码:255.255.255.252 R4:fa0/1:ip地址:10.3.3.254 掩码:255.255.255.0


四、配置思路及代码展示

1.R1配置

Router>enable  //进入系统模式
Router#configure terminal  //进入特权模式

Router(config)#hostname R1 //设置路由器名称为R1

R1(config)#int f0/0 //进入f0/0端口
R1(config-if)#no shutdown  //开启端口
R1(config-if)#ip add 10.1.1.254 255.255.255.0 //设置网关
R1(config-if)#exit //退出

R1(config)#int f0/1 //进入f0/1端口
R1(config-if)#no shutdown //开启端口
R1(config-if)#ip add 101.0.0.1 255.255.255.252 //设置网关
R1(config-if)#exit //退出

R1(config)#ip route 0.0.0.0 0.0.0.0 fastEthernet 0/1  //设置静态路由fastEthernet 0/1的直连网段为下一跳地址

R1(config)#crypto isakmp policy 1  //设置加密协议isakmp策略为1
R1(config-isakmp)#encryption 3des //设置加密算法为 3des
R1(config-isakmp)#hash sha //设置哈希算法为sha
R1(config-isakmp)#authentication pre-share //采用预共享密钥方式
R1(config-isakmp)#group 2 //指定DH算法的密钥长度为组2
R1(config-isakmp)#exit //退出

R1(config)#crypto isakmp key mashuo address 102.0.0.1  //设置加密协议 isakmp 密钥为mashuo指定地址为102.0.0.1
R1(config)#access-list 100 permit ip 10.1.1.0 0.0.0.255 10.2.2.0 0.0.0.255 //设置acl 100 允许10.1.1.0网段访问10.2.2.0网段

R1(config)#crypto ipsec transform-set mashuo-set esp-des esp-sha-hmac //设置加密ipsec策略转换集名称为mashuo-set支持esp-sha-hmac

R1(config)#crypto map mashuo-map 1 ipsec-isakmp   //设置映射集 mashuo-map 1 协议为  ipsec-isakmp 
R1(config-crypto-map)#set peer 102.0.0.1 //102.0.0.1端口建立邻居关系
R1(config-crypto-map)#set transform-set mashuo-set //添加ipsec策略转换集 mashuo-set
R1(config-crypto-map)#match address 100 //匹配acl 100
R1(config-crypto-map)#exit //退出

R1(config)#int f0/1 //进入接口f0/1
R1(config-if)#crypto map mashuo-map //设置映射集 mashuo-map
R1(config-if)#exit //退出

R1(config)#crypto isakmp key mashuo-002 address 103.0.0.1  //设置加密协议 isakmp 密钥为mashuo-002指定地址为103.0.0.1

R1(config)#access-list 101 permit ip 10.1.1.0 0.0.0.255 10.3.3.0 0.0.0.255 //设置acl 101 允许10.1.1.0网段访问10.3.3.0网段

R1(config)#crypto map mashuo-map 2 ipsec-isakmp  //设置映射集 mashuo-map 2 协议为  ipsec-isakmp 
R1(config-crypto-map)#set peer 103.0.0.1 //103.0.0.1端口建立邻居关系
R1(config-crypto-map)#set transform-set mashuo-set  //添加ipsec策略转换集 mashuo-set
R1(config-crypto-map)#match address 101  //匹配acl 100
R1(config-crypto-map)#exit //退出

2.R2配置

Router>enable //进入系统模式
Router#configure terminal 

Router(config)#hostname R2 //设置路由器名称为R2

R2(config)#int g0/0 //进入g0/0端口
R2(config-if)#no shutdown //开启端口
R2(config-if)#ip add 101.0.0.2 255.255.255.252 //设置ip地址
R2(config-if)#exit //退出

R2(config)#int g0/1  //进入g0/1端口
R2(config-if)#no shutdown //开启端口
R2(config-if)#ip add 103.0.0.2 255.255.255.252  //设置ip地址
R2(config-if)#exit //退出

R2(config)#int g0/2 //进入g0/2端口
R2(config-if)#no shutdown  //开启端口
R2(config-if)#ip add 102.0.0.2 255.255.255.252 //设置ip地址
R2(config-if)#exit //退出

3.R3配置

Router>enable  //进入系统模式
Router#configure terminal  //进入特权模式

Router(config)#hostname R3  //设置路由器名称为R3

R3(config)#int f0/0  //进入f0/0端口
R3(config-if)#no shutdown //开启端口
R3(config-if)#ip add 102.0.0.1 255.255.255.252 //设置ip地址
R3(config-if)#exit //退出

R3(config)#int f0/1 //进入f0/1端口
R3(config-if)#no shutdown  //开启端口
R3(config-if)#ip add 10.2.2.254 255.255.255.0 //设置ip地址
R3(config-if)#exit //退出

R3(config)#crypto isakmp policy 1 //设置加密协议isakmp策略为1
R3(config-isakmp)#encryption 3des  //设置加密算法为 3des
R3(config-isakmp)#hash sha  //设置哈希算法为sha
R3(config-isakmp)#authentication pre-share  //采用预共享密钥方式
R3(config-isakmp)#group 2 //指定DH算法的密钥长度为组2
R3(config-isakmp)#exit  //退出

R3(config)#crypto ipsec transform-set mashuo-set esp-des esp-sha-hmac  //设置加密ipsec策略转换集名称为mashuo-set支持esp-sha-hmac

R3(config)#ip route 0.0.0.0 0.0.0.0 fastEthernet 0/0 //设置静态路由fastEthernet 0/0的直连网段为下一跳地址

R3(config)#crypto isakmp key mashuo address 101.0.0.1 //设置加密协议 isakmp 密钥为mashuo指定地址为101.0.0.1

R3(config)#access-list 102 permit ip 10.2.2.0 0.0.0.255 10.1.1.0 0.0.0.255   //设置acl 101 允许10.2.2.0网段访问10.1.1.0网段

R3(config)#crypto map mashuo-map 2 ipsec-isakmp  //设置映射集 mashuo-map 2 协议为  ipsec-isakmp
R3(config-crypto-map)#set peer 101.0.0.1 //101.0.0.1端口建立邻居关系
R3(config-crypto-map)#set transform-set mashuo-set //添加ipsec策略转换集 mashuo-set
R3(config-crypto-map)#match address 102 //匹配acl 102
R3(config-crypto-map)#exit //退出

R3(config)#int f0/0 //进入接口f0/0
R3(config-if)#crypto map mashuo-map //设置映射集 mashuo-map
R3(config-if)#exit //退出

4.R4配置

Router>enable  //进入系统模式
Router#configure terminal  //进入特权模式

Router(config)#hostname R4 //设置路由器名称为R4

R4(config)#int f0/0 //进入f0/0端口
R4(config-if)#no shutdown  //开启端口

R4(config-if)#ip add 103.0.0.1 255.255.255.252  //设置ip地址
R4(config-if)#exit//退出

R4(config)#int f0/1 //进入f0/1端口
R4(config-if)#no shutdown  //开启端口
R4(config-if)#ip add 10.3.3.254 255.255.255.0 //设置ip地址
R4(config-if)#exit //退出

R4(config)#ip route 0.0.0.0 0.0.0.0 fastEthernet 0/0 //设置静态路由fastEthernet 0/0的直连网段为下一跳地址

R4(config)#crypto isakmp policy 1 //设置加密协议isakmp策略为1
R4(config-isakmp)#encryption 3des  //设置加密算法为 3des
R4(config-isakmp)#hash sha //设置哈希算法为sha
R4(config-isakmp)#authentication pre-share  //采用预共享密钥方式
R4(config-isakmp)#group 2  //指定DH算法的密钥长度为组2
R4(config-isakmp)#exit //退出

R4(config)#access-list 103 permit ip 10.3.3.0 0.0.0.255 10.1.1.0 0.0.0.255 //设置acl 103 允许10.3.3.0网段访问10.1.1.0网段

R4(config)#crypto ipsec transform-set mashuo-set esp-des esp-sha-hmac //设置加密ipsec策略转换集名称为mashuo-set支持esp-sha-hmac

R4(config)#crypto map mashuo-map 2 ipsec-isakmp //设置映射集 mashuo-map 2 协议为  ipsec-isakmp
R4(config-crypto-map)#set peer 101.0.0.1 //101.0.0.1端口建立邻居关系
R4(config-crypto-map)#set transform-set mashuo-set //添加ipsec策略转换集 mashuo-set
R4(config-crypto-map)#match address 103 //匹配acl 103
R4(config-crypto-map)#exit //退出

R4(config)#int f0/0 //进入接口f0/0
R4(config-if)#crypto map mashuo-map //设置映射集 mashuo-map
R4(config-if)#exit //退出

五、验证:

1.Pc机验证