这是IPsec×××的另一种配置,作用在防火墙上面。虽然一个是作用的路由器上的一个是作用在防火墙上的但是原理机制都是差不多,唯一的区别就是默认配置的区别。路由器默认就开启了IKE的协商,而防火墙是默认关闭的所以要输入crypto isakmp enable outside这条命令开启防火墙上面的IKE的协商,outside就是指在防火墙的外网口开启这个功能,也就是图中所示的e0/0这个端口。但是由于防火墙存在一种限制,如果流量从一个接口进入,就不能从相同安全级别的端口流出。也就是流量不能在同一安全级别的端口之间传输。这个问题我会在最后面做重点的补充出来。

esp防火墙 epc防火墙_运维

 

先为路由器配置地址

R1



R1>en R1#conf t Enter configuration commands, one per line.  End with CNTL/Z. R1(config)#int fa0/1 R1(config-if)#ip add 192.168.1.1 255.255.255.0 R1(config-if)#no shut R1(config-if)#ex R1(config)#int fa0/0 R1(config-if)#ip add 192.168.10.1 255.255.255.0 R1(config-if)#no shut R1(config-if)#ex R1(config)#ip route 0.0.0.0 0.0.0.0 192.168.10.2




R3



R3>en R3#conf t R3(config)#int fa0/0 R3(config-if)#ip add 192.168.20.1 255.255.255.0 R3(config-if)#no shut R3(config-if)#ex R3(config)#int fa0/1 R3(config-if)#ip add 192.168.2.1 255.255.255.0 R3(config-if)#no shut R3(config-if)#ex R3(config)#ip route 0.0.0.0 0.0.0.0 192.168.20.2




ISP



ISP>en ISP#conf t ISP(config)#int fa0/0 ISP(config-if)#ip add 10.0.0.2 255.255.255.0 ISP(config-if)#no shut ISP(config-if)#ex ISP(config)#int fa0/1 ISP(config-if)#ip add 11.0.0.2 255.255.255.0 ISP(config-if)#no shut




ASA1配置等同于ASA2配置(除地址外)

1、首先配置的是如何保存


esp防火墙 epc防火墙_3d_02

esp防火墙 epc防火墙_R3_03

 

#重启防火墙后在查看磁盘,你就会发现有所区别了,因为没重启前的磁盘还不能写入数据。



ciscoasa> show disk0 --#--  --length--  -----date/time------  path     5  4096        Jul 12 2015 11:59:59  .private     6  0           Jul 12 2015 11:59:57  .private/mode.dat     7  0           Jul 12 2015 11:59:59  .private/DATAFILE   268136448 bytes total (242642944 bytes free)  ciscoasa> en                                                 Password: #这里不需要密码直接回车 ciscoasa# conf t ciscoasa(config)# copy running-config disk0:/.private/startup-config#复制文件   Source filename [running-config]? 敲回车   Destination filename [/.private/startup-config]? 敲回车 Cryptochecksum: 6e33e06b 255d8b92 90c27d70 9f5b4de4    1471 bytes copied in 2.580 secs (735 bytes/sec)open(ffsdev/2/write/41) failed open(ffsdev/2/write/40) failed   ciscoasa(config)# boot config disk0:/.private/startup-config#重启文件 ciscoasa(config)# wr#保存文件 Building configuration... Cryptochecksum: a0ce05e6 e361a34f d8bc3b81 55185b42    1514 bytes copied in 2.410 secs (757 bytes/sec)open(ffsdev/2/write/41) failed open(ffsdev/2/write/40) failed  [OK]#这里已经说明成功了 ciscoasa(config)# show disk0#然后在查看磁盘 --#--  --length--  -----date/time------  path     5  4096        Jul 12 2015 12:09:40  .private     6  0           Jul 12 2015 11:59:57  .private/mode.dat     7  0           Jul 12 2015 12:10:58  .private/DATAFILE     8  1514        Jul 12 2015 12:10:58  .private/startup-config     9  4096        Jul 12 2015 12:10:58  boot    10  0           Jul 12 2015 12:10:58  boot/grub.conf 268136448 bytes total (242634752 bytes free) ciscoasa(config)# hostname ASA1 #修改名称 ASA1(config)#  ASA1(config)# int e0/0#进入端口 ASA1(config-if)# nameif outside#指定端口所在区域(这里可以加一个端口的优先级配置security-level number INFO: Security level for "outside" set to 0 by default. ASA1(config-if)# ip add 10.0.0.1 255.255.255.0#配置地址 ASA1(config-if)# no shut#激活端口 ASA1(config-if)# ex ASA1(config)# int e0/1 ASA1(config-if)# nameif inside  INFO: Security level for "inside" set to 100 by default. ASA1(config-if)# ip add 192.168.10.2 255.255.255.0 ASA1(config-if)# no shut  ASA1(config-if)# ex ASA1(config)# route outside 0 0 10.0.0.2#默认路由配置 ASA1(config)# route inside 192.168.1.0 255.255.255.0 192.168.10.1#指向内网段 ASA1(config)# ex ASA1# ping 11.0.0.1 Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 11.0.0.1, timeout is 2 seconds: ?!!!!#可以通过网卡说明防火墙配置成功了 Success rate is 80 percent (4/5), round-trip min/avg/max = 20/37/50 ms




2、ISAKMP/IKE阶段一管理连接部分及解释


ASA1(config)# crypto isakmp enable outside#在防火墙上启用IKE的协商
ASA1(config)# crypto isakmp policy 1#建立管理链接策略(policy的值1~10000)
ASA1(config-isakmp-policy)# encryption 3des#用于管理最后两个数据报文(用于身份验证)采用何种加密算法( des | 3des | aes  这三种对称加密算法aes支持256位秘钥长度最安全其次是3des168位,des支持56位)
ASA1(config-isakmp-policy)# hash sha#指定验证过程采用HMAC功能( sha | md5 其中SHA安全散列算法 MD5信息-摘要算法)
ASA1(config-isakmp-policy)# authentication pre-share#指定设备身份验证方式( pre-share | rsa-encr | rsa-sig )
ASA1(config-isakmp-policy)# group 2#指定DH秘钥组,默认DH2组( 1 | 2 | 5 组号越大算法越安全)
ASA1(config-isakmp-policy)# lifetime 120#指定管理链接的生存周期,默认24小时,这里以秒为单位。最小120s。
ASA1(config-isakmp-policy)# ex     
ASA1(config)# crypto isakmp key 123 address 11.0.0.1#预共享秘钥
ASA1(config)# crypto ipsec transform-set benet esp-3des esp-sha-hmac #定义传输集,ipsec-set是名称,该设定的名称具有唯一性。esp-3des是ESP六个加密中的一种,esp-sha-hmac是ESP验证还有一种是esp-md5-hmac。(传输集有AH和ESP两种其中AH不支持加密)


3、ISAKMP/IKE阶段二数据连接部分及解释


ASA1(config)# access-list 111 permit ip 192.168.1.0 255.255.255.0 192.168.2.0 255.255.255.0#防火墙上配置ACL不使用反掩码
ASA1(config)# crypto map li 1 match address 111#指定ACL
ASA1(config)# crypto map li 1 set peer 11.0.0.1#指定对端地址
ASA1(config)# crypto map li 1 set transform-set benet#指定对等体设备与谁建立连接(名称要与定义传输集的名称相同)
ASA1(config)# crypto map li interface outside#端口指定
ASA1(config)# show crypto isakmp sa#防火墙上在全局模式查看不需要再show前加do,而且全局模式也无法ping,只能在特权模式ping测试
   Active SA: 1
    Rekey SA: 0 (A tunnel will report 1 Active and 1 Rekey SA during rekey)
Total IKE SA: 1
 
1   IKE Peer: 11.0.0.1
    Type    : L2L             Role    : initiator 
    Rekey   : no              State   : MM_ACTIVE 
ASA1(config)# show crypto ipsec sa    
interface: outside
Crypto map tag: li, seq num: 1, local addr: 10.0.0.1
 
      access-list 111 permit ip 192.168.1.0 255.255.255.0 192.168.2.0 255.255.255.0 
      local ident (addr/mask/prot/port): (192.168.1.0/255.255.255.0/0/0)
      remote ident (addr/mask/prot/port): (192.168.2.0/255.255.255.0/0/0)
      current_peer: 11.0.0.1指定远程对等体设备地址
#local ident和remote ident指定了基于感兴趣流量的ACL需要被保护的流量
      #pkts encaps: 4, #pkts encrypt: 4, #pkts digest: 4
      #pkts decaps: 4, #pkts decrypt: 4, #pkts verify: 4
      #pkts compressed: 0, #pkts decompressed: 0
      #pkts not compressed: 4, #pkts comp failed: 0, #pkts decomp failed: 0
      #pre-frag successes: 0, #pre-frag failures: 0, #fragments created: 0
      #PMTUs sent: 0, #PMTUs rcvd: 0, #decapsulated frgs needing reassembly: 0
      #send errors: 0, #recv errors: 0
 
      local crypto endpt.: 10.0.0.1, remote crypto endpt.: 11.0.0.1
 
      path mtu 1500, ipsec overhead 58, media mtu 1500
      current outbound spi: DE983656
#inbound和outbound指定每条SA的具体参数
    inbound esp sas:
      spi: 0xE35937F1 (3814275057)
         transform: esp-3des esp-sha-hmac none 
         in use settings ={L2L, Tunnel, }
         slot: 0, conn_id: 4096, crypto-map: li
         sa timing: remaining key lifetime (kB/sec): (3824999/28747)
         IV size: 8 bytes
         replay detection support: Y
    outbound esp sas:
      spi: 0xDE983656 (3734517334)
         transform: esp-3des esp-sha-hmac none 
         in use settings ={L2L, Tunnel, }
         slot: 0, conn_id: 4096, crypto-map: li
         sa timing: remaining key lifetime (kB/sec): (3824999/28747)
         IV size: 8 bytes
         replay detection support: Y



ASA2防火墙配置


ASA2(config)# int e0/0
ASA2(config-if)# nameif outside
INFO: Security level for "outside" set to 0 by default.
ASA2(config-if)# ip add 11.0.0.1 255.255.255.0
ASA2(config-if)# ex
ASA2(config)# int e0/0
ASA2(config-if)# no shut
ASA2(config-if)# ex
ASA2(config)# int e0/1
ASA2(config-if)# nameif inside 
INFO: Security level for "inside" set to 100 by default.
ASA2(config-if)# ip add 192.168.20.2 255.255.255.0
ASA2(config-if)# no shut
ASA2(config-if)# ex
ASA2(config)# route outside 0 0 11.0.0.2
ASA2(config)# route inside 192.168.2.0 255.255.255.0 192.168.20.1


ISAKMP/IKE阶段一管理连接配置
ASA2(config)# crypto isakmp enable outside 
ASA2(config)# crypto isakmp policy 1
ASA2(config-isakmp-policy)# encryption 3des
ASA2(config-isakmp-policy)# hash sha
ASA2(config-isakmp-policy)# authentication pre-share
ASA2(config-isakmp-policy)# group 2
ASA2(config-isakmp-policy)# lifetime 120
ASA2(config-isakmp-policy)# ex
ASA2(config)# crypto isakmp key 123 address 10.0.0.1     
ASA2(config)# crypto ipsec transform-set benet esp-3des esp-sha-hmac 


ISAKMP/IKE阶段二数据连接配置
ASA2(config)# access-list 111 permit ip 192.168.2.0 255.255.255.0 192.168.1.0 255.255.255.0
ASA2(config)# crypto map li 1 match address 111
ASA2(config)# crypto map li 1 set peer 10.0.0.1
ASA2(config)# crypto map li 1 set transform-set benet
ASA2(config)# crypto map li interface outside


VPCS虚拟网卡地址配置部分

esp防火墙 epc防火墙_R3_04

结果测试成功


esp防火墙 epc防火墙_3d_05

补充:

介绍几个主模式方便排查错误

MM_NO_STATE:ISAKMP建立初始状态,管理连接建立失败也是该模式。

MM_SA_SETUP:对等体之间ISAKMP策略协商成功。

MM_KEY_EXCH:对等体通过DH算法成功建立共享秘钥,还没进行设备验证。

MM_KEY_AUTH:对等体成功进行设备验证

QM_IDLE:管理连接建立成功

 

故障一:管理连接中加密算法不匹配通过debug  crypto isakmp 命令查看

ISAKMP:(0:0:N/A:0):Encryption algorithm offered does not match policy!加密算法不匹配

ISAKMP:(0:0:N/A:0):atts are not acceptable Next payload is 0策略不被接受

故障二:两端的key秘钥不匹配通过debug crypto isakmp命令查看

ISAKMP:(0:0:N/A:0):atts are acceptable. Next payload is 0 算法匹配,开始进行秘钥交换及身份验证

%CRYPTO-4-IKMP_BAD_MESSAGE:IKE message form 10.0.0.1 failed its sanity check or is malformed验证失败

 

防火墙的端口安全机制的解决方法就是配置下面这条命令,该命令的意思是允许进出同一端口,这样就可以建多个站点了。



ASA(config)#same-security-traffic permit intra-interface



.