实验拓扑
图 1-1
注:如无特别说明,描述中的 R1 或 SW1 对应拓扑中设备名称末尾数字为 1 的设备,R2 或 SW2 对应拓扑中设备名称末尾数字为 2 的设备,以此类推;另外,同一网段中,IP 地址的主机位为其设备编号,如 R3 的 g0/0 接口若在192.168.1.0/24网段,则其 IP 地址为192.168.1.3/24,以此类推
实验需求
-
按照图示配置 IP 地址
-
在 R1 和 R3 上配置默认路由连通公网
-
在 R1 和 R3 上配置 IPsec VPN,使两端私网可以互相访问
实验解法
-
配置 IP 地址部分
R1
<H3C>SYS
System View: return to User View with Ctrl+Z.
[H3C]int g0/0
[H3C-GigabitEthernet0/1]ip add 192.168.1.1 24
[H3C-GigabitEthernet0/1]int g0/0
[H3C-GigabitEthernet0/0]ip add 100.1.1.1 24
[H3C-GigabitEthernet0/0]sysn r1
R2
<H3C>sys
System View: return to User View with Ctrl+Z.
[H3C]sysn r2
[r2]int g0/0
[r2-GigabitEthernet0/0]ip add 100.1.1.2 24
[r2-GigabitEthernet0/0]int g0/1
[r2-GigabitEthernet0/1]ip add 100.2.2.2 24
R3
<H3C>sys
System View: return to User View with Ctrl+Z.
[H3C]sysn r3
[r3]int g0/0
[r3-GigabitEthernet0/0]ip add 100.2.2.3 24
[r3-GigabitEthernet0/0]int g0/1
[r3-GigabitEthernet0/1]ip add 192.168.2.3 24
PC4
PC5
A
-
配置默认路由部分
R1
[r1]ip route-static 0.0.0.0 0 100.1.1.2
R3
[r3]ip route-static 0.0.0.0 0 100.2.2.2
-
在 R1 和 R3 上配置 IPsec VPN,使两端私网可以互相访问
步骤 1:在 R1 上创建感兴趣流,匹配两端私网地址网段
[r1]acl ad 3000 [r1-acl-ipv4-adv-3000] rule per ip source 192.168.1.0 0.0.0.255 des 192.168.2.0 0.0.0.255
步骤 2:在 R1 上创建 IKE 提议,配置验证模式为预共享密钥,并配置加密算法
[r1]ike pr 1 [r1-ike-proposal-1]authentication-method pre-share [r1-ike-proposal-1]encryption-algorithm aes-cbc-128
步骤 3:在 R1 上创建预共享密钥
[r1]ike key r3 [r1-ike-keychain-r3]pre add 100.2.2.3 key si 123456
步骤 4:在 R1 上创建 IKE Profile,指定本端和对端公网地址,并调用预共享密钥和 IKE 提议
[r1]ike pr r3 [r1-ike-profile-r3]key r3 [r1-ike-profile-r3]local-identity add 100.1.1.1 [r1-ike-profile-r3]match remote identity add 100.2.2.3 [r1-ike-profile-r3]proposal 1
步骤 5:在 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
步骤 6:在 R1 上创建 IPsec 策略,调用上述配置
<r1>sys System View: return to User View with Ctrl+Z. [r1]ips po r3 1 isa [r1-ipsec-policy-isakmp-r3-1]se acl 3000 [r1-ipsec-policy-isakmp-r3-1]ike-pro r3 [r1-ipsec-policy-isakmp-r3-1]transform-set r3 [r1-ipsec-policy-isakmp-r3-1]re 100.2.2.3
步骤 7:在 R1 的公网接口上下发 IPsec 策略
[r1]int g0/0 [r1-GigabitEthernet0/0]ipsec app po r3
步骤 8:在 R3 上完成 IPsec 相关配置,方法和命令与 R1 一致,本端和对端地址对调即可
<H3C>sys
System View: return to User View with Ctrl+Z.
[H3C]sysn r3
[r3]int g0/0
[r3-GigabitEthernet0/0]ip add 100.2.2.3 24
[r3-GigabitEthernet0/0]int g0/1
[r3-GigabitEthernet0/1]ip add 192.168.2.3 24
[r3-GigabitEthernet0/1]qu
[r3]ip route-static 0.0.0.0 0 100.2.2.2
[r3-GigabitEthernet0/0]acl ad 3000
[r3-acl-ipv4-adv-3000]rule per ip source 192.168.2.0 0.0.0.255 destination 192.1
68.1.0 0.0.0.255
[r3-acl-ipv4-adv-3000]ike proposal 1
[r3-ike-proposal-1]authentication-method pre-share
[r3-ike-proposal-1]encryption-algorithm aes-cbc-128
[r3-ike-proposal-1]ike keychain r1
[r3-ike-keychain-r1]pre-shared-key add 100.1.1.1 key si 123456
[r3-ike-keychain-r1]ike profile r1
[r3-ike-profile-r1]keychain r1
[r3-ike-profile-r1]local-identity add 100.2.2.3
[r3-ike-profile-r1]match remote identity add 100.1.1.1
[r3-ike-profile-r1]proposal 1
[r3-ike-profile-r1]ipsec transform-set r1
[r3-ipsec-transform-set-r1]esp authentication-algorithm sha1
[r3-ipsec-transform-set-r1]esp encryption-algorithm aes-cbc-128
[r3-ipsec-transform-set-r1]ipsec policy r1 1 isakmp
[r3-ipsec-policy-isakmp-r1-1]security acl 3000
[r3-ipsec-policy-isakmp-r1-1]ike-profile r1
[r3-ipsec-policy-isakmp-r1-1]transform-set r1
[r3-ipsec-policy-isakmp-r1-1]remote-address 100.1.1.1
[r3-ipsec-policy-isakmp-r1-1]int g0/0
步骤 9,到这里还没结束我们需要配置nat转换出去公网,nat优先级比IPSec高,我们这里要拒绝下。
R1
[r1]acl ad 3001
[r1-acl-ipv4-adv-3001]rule 4 deny ip source 192.168.1.0 0.0.0.255 destination 19 2.168.2.0 0.0.0.25
[r1-acl-ipv4-adv-3001]rule 5 permit ip source 192.168.1.0 0.0.0.25
[r1-acl-ipv4-adv-3001]int g0/0
[r1-GigabitEthernet0/0]nat out 3001
R3
[r3]acl ad 3001
[r3-acl-ipv4-adv-3001]rule 4 deny ip source 192.168.2.0 0.0.0.255 destination 19
2.168.1.0 0.0.0.25
[r3-acl-ipv4-adv-3001]rule 5 permit ip source 192.168.2.0 0.0.0.25
[r3-acl-ipv4-adv-3001]int g0/0
[r3-GigabitEthernet0/0]nat out 3001
效果测试:在 PC4 上 Ping PC5,可以直接 Ping 通
<PC4>ping 192.168.2.5
小提示完成后可以使用dis ike sa 和dis ipsec sa 来查看建立的vpn线路