IPsec VPN实验
一、拓扑图
二、组网需求
- 按照图示配置 IP 地址
- 在 R1 和 R3 上配置默认路由连通公网
- 在 R1 和 R3 上配置 IPsec VPN,使两端私网可以互相访问
注:设备IP地址为标志网段+设备号,如R1的G0/0端口的IP地址为1.1.1.1/24
三、配置步骤
1.配置各设备IP地址
G0/0 | G0/1 | |
---|---|---|
R1 | 192.168.1.1/24 | 100.1.1.1/24 |
R2 | 100.1.1.2/24 | 100.2.2.2/24 |
R3 | 192.168.2.3/24 | 100.2.2.3/24 |
R4 | 192.168.1.4/24 | |
R5 | 192.168.2.5/24 |
2.配置默认路由
在R1和R3上,分别配置默认路由模拟公网
[R1]ip route-static 0.0.0.0 0 100.1.1.2
[R3]ip route-static 0.0.0.0 0 200.2.2.2
3.配置 ACL
- 在 R1 上创建感兴趣流,匹配两端私网地址网段
[R1]acl advanced 3000
[R1-acl-ipv4-adv-3000]rule permit ip source 192.168.1.0 0.0.0.255 destination 192.168.2.0 0.0.0.255
- 在 R3 上创建感兴趣流,匹配两端私网地址网段
[R3]acl advanced 3000
[R3-acl-ipv4-adv-3000]rule permit ip source 192.168.2.0 0.0.0.255 destination 192.168.1.0 0.0.0.255
4.创建 IKE 提议
- 在 R1 上创建 IKE 提议,配置验证模式为预共享密钥,并配置加密算法
[R1]ike proposal 1
[R1-ike-proposal-1]authentication-method pre-share //IKE提议使用的密钥处理方式
[R1-ike-proposal-1]encryption-algorithm aes-cbc-128 //IKE提议使用的加密算法
- 在 R3 上创建 IKE 提议,配置验证模式为预共享密钥,并配置加密算法
[R3]ike proposal 1
[R3-ike-proposal-1]authentication-method pre-share
[R3-ike-proposal-1]encryption-algorithm aes-cbc-128
5.创建预共享密钥
- 在 R1 上创建预共享密钥
[R1]ike keychain r3
[R1-ike-keychain-r3]pre-shared-key address 100.2.2.3 key simple 123456
- 在 R3 上创建预共享密钥
[R3]ike keychain r3
[R3-ike-keychain-r3]pre-shared-key address 100.1.1.1 key simple 123456
6.创建 IKE Profile
- 在 R1 上创建 IKE Profile,指定本端和对端公网地址,并调用预共享密钥和 IKE 提议
[R1]ike profile r3
[R1-ike-profile-r3]local-identity address 100.1.1.1
[R1-ike-profile-r3]match remote identity address 100.2.2.3
[R1-ike-profile-r3]keychain r3 //调用预共享密钥
[R1-ike-profile-r3]proposal 1 //调用IKE 提议
- 在 R3 上创建 IKE Profile,指定本端和对端公网地址,并调用预共享密钥和 IKE 提议
[R3]ike profile r3
[R3-ike-profile-r3]
[R3-ike-profile-r3] local-identity address 100.2.2.3
[R3-ike-profile-r3] match remote identity address 100.1.1.1 255.255.255.255
[R3-ike-profile-r3] keychain r3
[R3-ike-profile-r3] proposal 1
6.创建 IPsec 转换集
- 在 R1 上创建IPsec 转换集,配置加密和验证算法。由于工作模式默认是隧道模式,且协议默认使用 ESP,所以无需配置
[R1]ipsec transform-set r3
[R1-ipsec-transform-set-r3]esp authentication-algorithm sha1
[R1-ipsec-transform-set-r3]esp encryption-algorithm aes-cbc-128
- 在 R1 上创建IPsec 转换集,配置加密和验证算法。由于工作模式默认是隧道模式,且协议默认使用 ESP,所以无需配置
[R3]ipsec transform-set r3
[R3-ipsec-transform-set-r3]esp authentication-algorithm sha1
[R3-ipsec-transform-set-r3]esp encryption-algorithm aes-cbc-128
7.创建 IPsec 策略
- 在 R1 上创建 IPsec 策略,调用上述配置
[R1]ipsec policy r3 1 isakmp
[R1-ipsec-policy-isakmp-r3-1]security acl 3000
[R1-ipsec-policy-isakmp-r3-1]ike-profile r3
[R1-ipsec-policy-isakmp-r3-1]transform-set r3
[R1-ipsec-policy-isakmp-r3-1]remote-address 100.2.2.3
- 在 R3 上创建 IPsec 策略,调用上述配置
[R3]ipsec policy r3 1 isakmp
[R3-ipsec-policy-isakmp-r3-1]security acl 3000
[R3-ipsec-policy-isakmp-r3-1]ike-profile r3
[R3-ipsec-policy-isakmp-r3-1]transform-set r3
[R3-ipsec-policy-isakmp-r3-1]remote-address 100.1.1.1
8.下发 IPsec 策略
- 在 R1 的公网接口上下发 IPsec 策略
[R1-GigabitEthernet0/1]ipsec apply policy r3
- 在 R3 的公网接口上下发 IPsec 策略
[R1-GigabitEthernet0/1]ipsec apply policy r3
检查:在 PC4 上 ping PC5 可 通
总结
少配漏配后补全无法 ping 通,用reset ike sa
,reset ipsec sa
清除重新触发sa