实验二 使用GRE隧道的IPSEC之上的OSPF

一 实验设备

2CISCO 路由器俩台,IOS版本12.3K9

二实验拓扑图

 实验配置 

1、 R1路由器上连通性配置 

R1(config)#interface e0 

R1(config-if)#ip address 192.168.1.1 255.255.255.0 

R1(config-if)#no shutdown 

R1(config)#interface e1 

R1(config-if)#ip address 10.1.1.1 255.255.255.0 

R1(config-if)#no shutdown 

R1(config)#ip route 0.0.0.0 0.0.0.0 192.168.1.2 

2、 R2路由器上连通性配置 

R2(config)#interface e0 

R2(config-if)#ip address 192.168.1.2 255.255.255.0 

R2(config-if)#no shutdown 

R2(config)#interface e1 

R2(config-if)#ip address 10.2.2.2 255.255.255.0 

R2(config-if)#no shutdown 

R2(config)#ip route 0.0.0.0 0.0.0.0 192.168.1.1 

3、 R1路由器上GRE配置

R1(config)#interface tunnel0 #建立一个隧道口

R1(config-if)#ip address 1.1.1.1 255.255.255.0  #设置IP

R1(config-if)#tunnel source 192.168.1.1 #指定隧道的源端口,这里一定是自己的物理端口

R1(config-if)#tunnel destination 192.168.1.2 #指定隧道的目的端口

R1(config)#ip route 10.2.2.0 255.255.255.0 tunnel0 1.1.1.2 #指定隧道的默认路由的下一跳IP地址为隧道另一端IP

4R2路由器上GRE配置 

R2(config)#interface tunnel0 

R2(config-if)#ip address 1.1.1.2 255.255.255.0 

R2(config-if)#tunnel source 192.168.1.2 

R2(config-if)#tunnel destionation 192.168.1.1 

R2(config)#ip route 10.1.1.0 255.255.255.0 tunnel0 1.1.1.1 

5R1 路由器上 OSPF 配置 

R1(config)#router ospf 1 

R1(config-router)#router-id 1.1.1.1 

R1(config-router)#network 10.1.1.0 0.0.0.255 area 0 

R1(config-router)#network 1.1.1.0 0.0.0.255 area 0 

6、 R1 路由器上 OSPF 配置 

R2(config)#router ospf 1 

R2(config-router)#router-id 1.1.1.2 

R2(config-router)#network 10.1.1.0 0.0.0.255 area 0 

R2(config-router)#network 1.1.1.0 0.0.0.255 area 0 

7、 R1 路由器 IpSec 配置 

R1(config)#crypto isakmp enable (optional)默认启用 

R1 路由器 IpSec isakmp 配置(阶段一的策略) 

R1(config)#crypto isakmp policy 10 创建ISAKMP策略,优先级为10 

R1(config-isakmp)#hash md5 指定ISAKMP策略使用MD5进行HASH运算

R1(config-isakmp)#authentication pre-share 指定ISAKMP策略使用预共享密钥的方式对分公司路由器进行身份验证。

R1(config-isakmp)#encryption 3des 指定ISAKMP策略使用3DES进行加密

R1(config-isakmp)#group 2 指定Diffie-Hellman2(指定ISAKMP策略使用10位密钥算法,分别有1/2/5三种)

R1 路由器 Pre-Share 认证配置 

R1(config)#crypto isakmp key bluefoxlab address 192.168.1.2 指定ISAKMP与分部路由器进行身份认证时使用预共享密钥。

R1 路由器 IpSec 变换集配置(阶段二的策略) 

R1(config)#crypto ipsec transform-set bluefoxlab esp-3des esp-md5-hmac 配置IPSec交换集

R1(cfg-crypto-trans)#mode transport 封装为传输模式(为什么用 transport 模式) 

R1 路由器加密图的配置 

R1(config)#crypto map bluefoxlab 10 ipsec-isakmp 创建加密图

R1(config-crypto-map)#set peer 192.168.1.2 指定加密图用于分支路由器建立×××连接

R1(config-crypto-map)#set transform-set bluefoxlab 指定加密图使用的IPSec交换集

R1(config-crypto-map)#match address 101 指定使用此加密图进行加密的通信,用访问控制列表来定义

R1 路由器定义感兴趣流量 

R1(config)#access-list 101 permit ip host 192.168.1.1 host 192.168.1.2 (感兴趣流量的理解) 

R1 路由器加密图绑定到接口 

R1(config)#interface e0 

R1(config-if)#crypto map bluefoxlab 

8、 R2 路由器 IpSec 配置 

R2(config)#crypto isakmp enable (optional)默认启用 

R2 路由器 IpSec isakmp 配置(阶段一的策略) 

R2(config)#crypto isakmp policy 10 

R2(config-isakmp)#hash md5 

R2(config-isakmp)#authentication pre-share 

R2(config-isakmp)#encryption 3des 

R2(config-isakmp)#group 2 指定Diffie-Hellman2(指定ISAKMP策略使用10位密钥算法,分别有1/2/5三种)

R2 路由器 Pre-Share 认证配置 

R2(config)#crypto isakmp key bluefoxlab address 192.168.1.1 

R2 路由器 IpSec 变换集配置(阶段二的策略) 

R2(config)#crypto ipsec transform-set bluefoxlab esp-des esp-md5-hmac R2(cfg-crypto-trans)#mode transport (为什么用 transport 模式) 

R2 路由器加密图的配置 

R2(config)#crypto map bluefoxlab 10 ipsec-isakmp 

R2(config-crypto-map)#set peer 192.168.1.1 

R2(config-crypto-map)#set transform-set bluefoxlab 

R2(config-crypto-map)#match address 101 

R2 路由器定义感兴趣流量 

R2(config)#access-list 101 permit ip host 192.168.1.2 host 192.168.1.1 (感兴趣流量的理解) 

R2 路由器加密图绑定到接口 

R2(config)#interface e0 

R2(config-if)#crypto map bluefoxlab 

 实验总结 

如R2:

1、show int tunnel 0 

Tunnel0 is up, line protocol is up 

  Hardware is Tunnel

  Internet address is 1.1.1.2/24

  MTU 1514 bytes, BW 9 Kbit, DLY 500000 usec, 

     reliability 255/255, txload 1/255, rxload 1/255

  Encapsulation TUNNEL, loopback not set

  Keepalive not set

  Tunnel source 192.168.1.2, destination 192.168.1.1

  Tunnel protocol/transport GRE/IP

    Key disabled, sequencing disabled

    Checksumming of packets disabled

  Tunnel TTL 255

  Fast tunneling enabled

  Tunnel transmit bandwidth 8000 (kbps)

  Tunnel receive bandwidth 8000 (kbps)

  Last input 00:08:55, output 00:00:36, output hang never

  Last clearing of "show interface" counters never

  Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 3

  Queueing strategy: fifo

  Output queue: 0/0 (size/max)

  5 minute input rate 0 bits/sec, 0 packets/sec

  5 minute output rate 0 bits/sec, 0 packets/sec

     60 packets input, 6208 bytes, 0 no buffer

     Received 0 broadcasts, 0 runts, 0 giants, 0 throttles

     0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored, 0 abort

     106 packets output, 10796 bytes, 0 underruns

     0 output errors, 0 collisions, 0 interface resets

     0 output buffer failures, 0 output buffers swapped out

2、show crypto ipsec sa 

interface: Ethernet0/0

    Crypto map tag: bluefoxlab, local addr 192.168.1.2

   protected vrf: (none)

   local  ident (addr/mask/prot/port): (192.168.1.2/255.255.255.255/0/0)

   remote ident (addr/mask/prot/port): (192.168.1.1/255.255.255.255/0/0)

   current_peer 192.168.1.1 port 500

     PERMIT, flags={origin_is_acl,ipsec_sa_request_sent}

    #pkts encaps: 0, #pkts encrypt: 0, #pkts digest: 0

    #pkts decaps: 0, #pkts decrypt: 0, #pkts verify: 0

    #pkts compressed: 0, #pkts decompressed: 0

    #pkts not compressed: 0, #pkts compr. failed: 0

    #pkts not decompressed: 0, #pkts decompress failed: 0

    #send errors 12, #recv errors 0

     local crypto endpt.: 192.168.1.2, remote crypto endpt.: 192.168.1.1

     path mtu 1500, ip mtu 1500, ip mtu idb Ethernet0/0

     current outbound spi: 0x0(0)

     inbound esp sas:

     inbound ah sas:

          

     inbound pcp sas:

     outbound esp sas:

     outbound ah sas:

     outbound pcp sas:

3、show crypto engine connections active 

  ID Interface            IP-Address      State  Algorithm           Encrypt  Decrypt

   4 Ethernet0/0          192.168.1.2     set    HMAC_MD5+3DES_56_C        0        0

   5 Ethernet0/0          192.168.1.2     set    HMAC_MD5+3DES_56_C        0        0

   6 Ethernet0/0          192.168.1.2     set    HMAC_MD5+3DES_56_C        0        0

4debug crypto isakmp 

5debug crypto ipsec 

6show ip ospf neighbor 

7debug ip ospf adj 

8show ip route