目录
IKE(密钥管理)方式建立IPsec vpn与使用IPSec vpn模板方式。
IPSec简介
IPSec(Internet Protocol Security)是一套用于互联网协议(IP)层的安全协议组合,旨在保护IP通信的安全性。它通过认证、加密和数据完整性验证来确保数据在传输过程中的机密性和完整性。IPSec可以在IPv4和IPv6网络中使用,广泛应用于虚拟专用网络(VPN)和安全站点间通信。
加密与验证
加密
- 目的是保护数据的机密性,防止未授权的用户窃取或查看数据。
- 工作原理:通过算法将原始数据(明文)转换为不可读的形式(密文),只有拥有正确密钥的接收方才能解密为明文。
- 加密方式(对称方式):DES<3DES<AES
验证
- 目的是确保数据的完整性和来源可信性,防止数据在传输过程中被篡改或伪造。
- 工作原理:通过散列函数和签名算法生成消息摘要和身份验证信息,发送者和接收者都可以验证数据是否未被篡改,以及数据确实来自声称的发送者。
- 验证算法:MD5<SHA1<SHA2
工作方式:AH(验证报文的完整性),ESP(既可以验证报文的完整性又具有加密功能)
安全封装
隧道模式:用于生成新的报文头放在AH和ESP前,用于两个网关之间的IPsec隧道,可以保护内部网络。
传输模式:隧道的源目的地址就是最终通信的源目的地址,应用于两台主机之间的通信。
安全联盟
在IPSec双方建立的连接为SA(安全联盟),建立的双方必须使用相同的封装模式,加密算法,加密算法,验证算法,验证密钥。
为了区分不同的安全联盟,IPSec为每个联盟打上唯一的标识(SPI)。适用于手工建立IPSec的方式。
手工建立IPSec
在上面实验中:总部和分布流量可以实现互访,要求互访的流量被加密。
配置缺省包过滤路由
security-policy
default action permit
FW10
#
acl number 3000
rule 5 permit ip source 192.168.1.0 0.0.0.255 destination 172.16.1.0 0.0.0.255
#
ipsec proposal 10
transform esp ##加密与验证方式
encapsulation-mode tunnel ##封装模式为隧道模式
esp authentication-algorithm sha2-256 ##验证方法
esp encryption-algorithm aes-256 ##加密方法
#
ipsec policy policy1 1 manual ## manual手工方式建立IPSec策略
security acl 3000
proposal 10
tunnel local 10.0.12.1 ##需要建立IPSec本端地址
tunnel remote 10.0.12.2 ##需要建立IPSec对端地址
sa spi inbound esp 12345 ##创建IPSec唯一标识符
sa string-key inbound esp Text123456
sa spi outbound esp 12345
sa string-key outbound esp Text123456
#
#
interface GigabitEthernet0/0/0
undo shutdown
ip address 192.168.1.254 255.255.255.0
alias GE0/METH
#
interface GigabitEthernet1/0/0
undo shutdown
ip address 10.0.12.1 255.255.255.0
ipsec policy policy1 ##在接口下调用IPSec安全策略
#
ip route-static 0.0.0.0 0.0.0.0 10.0.12.2
FW13
#
acl number 3000
rule 5 permit ip source 172.16.1.0 0.0.0.255 destination 192.168.1.0 0.0.0.255
#
ipsec proposal 10
esp authentication-algorithm sha2-256
esp encryption-algorithm aes-256
#
ipsec policy policy1 1 manual
security acl 3000
proposal 10
tunnel local 10.0.12.2
tunnel remote 10.0.12.1
sa spi inbound esp 12345
sa string-key inbound esp Text123456
sa spi outbound esp 12345
sa string-key outbound esp Text123456
#
interface GigabitEthernet0/0/0
undo shutdown
ip address 172.16.1.254 255.255.255.0
alias GE0/METH
#
interface GigabitEthernet1/0/0
undo shutdown
ip address 10.0.12.2 255.255.255.0
ipsec policy policy1
#
ip route-static 0.0.0.0 0.0.0.0 10.0.12.1
最终效果
使用总部PING分部发现数据被进行了加密,由于我们配置的是隧道模式,所以用于两个网关之间的IPsec隧道。
IKE(密钥管理)方式建立IPsec vpn与使用IPSec vpn模板方式。
由于手工配置IPSec方式比较繁琐,容易出错,且在需要调整时,重新配置可能比较麻烦。为保证IPSec长期使用,IKE的出现用于协商和管理IPSec参数。通过IKE,两个端点可以动态地协商加密算法、密钥和其他安全参数。
IKE三大协议
ISAKMP:定义ike对等体关系,ike sa相似与IPSec sa
Oakley 与 SKEME的核心是DH算法,用于分发密钥,验证身份议保证数据传输的安全性。
IKE版本
ike v1:支持主模式与野蛮模式
配置ike v1(默认是主模式)
FW10
#
acl number 3000
rule 5 permit ip source 192.168.1.0 0.0.0.255 destination 172.16.1.0 0.0.0.255
#
ipsec proposal 10
authentication-method pre-share ##默认为预共享密钥
esp authentication-algorithm sha2-256
esp encryption-algorithm aes-256
#
ike proposal 10
encryption-algorithm aes-256
dh group14
authentication-algorithm sha2-256
authentication-method pre-share
integrity-algorithm hmac-sha2-256
prf hmac-sha2-256
#
ike peer b
undo version 2 ##开启ike v1 版本
exchange-mode main ##缺省为主模式
pre-shared-key Text123456
ike-proposal 10
#
ipsec policy-template tem1 1 ##创建IPSec模板
security acl 3000
ike-peer b
proposal 10
#
ipsec policy policy1 1 isakmp template tem1 ##创建IPSec安全策略与IPSec模板所关联
#
#
interface GigabitEthernet1/0/0
undo shutdown
ip address 10.0.12.1 255.255.255.0
ipsec policy policy1
#
ip route-static 0.0.0.0 0.0.0.0 10.0.12.2
#
FW13
#
acl number 3000
rule 5 permit ip source 172.16.1.0 0.0.0.255 destination 192.168.1.0 0.0.0.255
#
ipsec proposal 10
esp authentication-algorithm sha2-256
esp encryption-algorithm aes-256
#
ike proposal 10
encryption-algorithm aes-256
dh group14
authentication-algorithm sha2-256
authentication-method pre-share
integrity-algorithm hmac-sha2-256
prf hmac-sha2-256
#
ike peer a
undo version 2
pre-shared-key Text123456
ike-proposal 10
remote-address 10.0.12.1
#
ipsec policy policy1 1 isakmp
security acl 3000
ike-peer a
proposal 10
#
interface GigabitEthernet1/0/0
undo shutdown
ip address 10.0.12.2 255.255.255.0
ipsec policy policy1
#
ip route-static 0.0.0.0 0.0.0.0 10.0.12.1
#
配置完成后使用分部计算机和总部计算机互访,激活IPSec vpn隧道。
(主模式)
使用6条ISAKMP建立IKE SA
使用两条ISAKMP建立IPSec SA
野蛮模式
ike peer
exchange-mode aggressive ##配置为野蛮模式
野蛮模式中只用了3条ISAKMP就建立成功了,相比主模式要快很多。但是野蛮模式是明文传输,没有加密和完整性验证,所以它是不安全的。现在已经很少使用了。
配置ike v2
由于ike v1的版本协商时间太长,而且也不支持远程用户接入。这时ike v2就很好的解决了不能认证的办法。(以总部防火墙为列,分部也是同样操作)
ike peer b
[zong-ike-peer-b]version 2
使用ike v2版本是需要4条ISAKMP就完成了IPSec SA 和IKE SA的建立。
NAT 穿越
在上面实验中分部访问总部,其中FWA与FWC建立IPSec VPN。FWB做NAT地址转换负责把10.1.23.0/24的流量通过公网地址12.1.1.2转换。
放行所有策略
#
security-policy
default action permit
#
FWA
#
acl number 3000
rule 5 permit ip source 10.1.10.0 0.0.0.255 destination 10.1.20.0 0.0.0.255
#
ipsec proposal 10
esp authentication-algorithm sha2-256
esp encryption-algorithm aes-256
#
ike proposal 10
encryption-algorithm aes-256
dh group14
authentication-algorithm sha2-256
authentication-method pre-share
integrity-algorithm hmac-sha2-256
prf hmac-sha2-256
#
ike peer c
pre-shared-key Text123456
ike-proposal 10
#
ipsec policy-template tem1 1
security acl 3000
ike-peer c
proposal 10
#
ipsec policy policy1 1 isakmp template tem1
#
interface GigabitEthernet1/0/6
undo shutdown
ip address 11.1.1.1 255.255.255.0
ipsec policy policy1
#
ip route-static 0.0.0.0 0.0.0.0 11.1.1.254
#
AR1-1
#
interface GigabitEthernet0/0/0
ip address 11.1.1.254 255.255.255.0
#
interface GigabitEthernet0/0/1
ip address 12.1.1.254 255.255.255.0
#
ip route-static 10.1.10.0 255.255.255.0 11.1.1.1
ip route-static 10.1.23.0 255.255.255.0 12.1.1.2
FWB
#
interface GigabitEthernet1/0/6
undo shutdown
ip address 12.1.1.2 255.255.255.0
#
interface GigabitEthernet1/0/0
undo shutdown
ip address 10.1.23.2 255.255.255.0
#
ip route-static 10.1.20.0 255.255.255.0 10.1.23.3
ip route-static 11.1.1.0 255.255.255.0 12.1.1.254
#
FWC
#
acl number 3000
rule 5 permit ip source 10.1.20.0 0.0.0.255 destination 10.1.10.0 0.0.0.255
#
ipsec proposal 10
esp authentication-algorithm sha2-256
esp encryption-algorithm aes-256
#
ike proposal 10
encryption-algorithm aes-256
dh group14
authentication-algorithm sha2-256
authentication-method pre-share
integrity-algorithm hmac-sha2-256
prf hmac-sha2-256
#
ike peer a
pre-shared-key Text123456
ike-proposal 10
remote-address 11.1.1.1
#
ipsec policy policy1 1 isakmp
security acl 3000
ike-peer a
proposal 10
#
interface GigabitEthernet1/0/0
undo shutdown
ip address 10.1.20.254 255.255.255.0
#
interface GigabitEthernet1/0/6
undo shutdown
ip address 10.1.23.3 255.255.255.0
ipsec policy policy1
#
ip route-static 0.0.0.0 0.0.0.0 10.1.23.2
#
开启NAT穿越功能
[FWC-ike-peer-a]nat traversal ##默认是开启的
根据出接口进行地址转换
FW1
#
nat-policy
rule name 1
source-address 10.1.23.0 mask 255.255.255.0
destination-address 11.1.1.0 mask 255.255.255.0
action source-nat easy-ip
#
根据NAT服务器进行地址转换
#
nat server 0 protocol udp global 12.1.1.2 500 inside 10.1.23.3 500 nat-disable
nat server 1 protocol udp global 12.1.1.2 4500 inside 10.1.23.3 4500 nat-disable
#
IKE v2的NAT穿越协商(使用分部ping总部激活隧道)
IKE v2使用UDP:4500封装ESP。报文当封装后的报文通过NAT 设备时,NAT 设备对该报文的外层P头和增加的UDP头进行地址和端口号转换。
IKE v1的NAT穿越协商(使用分部ping总部激活隧道)
查看会话记录
因为中间NAT 设备上配置了源NAT转换,所以分部FW上只有分部到总部方向的会话,没有总部到分部方向的会话。