tunnel:指保留原始IP数据流的情况下封装成另一种带有新IP报头(注:新IP为tunnel中的source、destination,这两个地址必须是UP状态的接口IP(包括虚接口),且两者能够通讯(包括路由可达、×××等。×××原始IP数据流协议为GRE时,两者ping不通,但也能够通讯的))的数据流,从而以新IP数据流路由转发出去;接收端通过tunnel解封装,得到原始IP的数据流。tunnel封装模式有多种,默认情况下指GRE模式。

GRE(Generic routing encapsulation)通用路由封装是一中隧道协议,能够在IP隧道中封装各种网络层协议的分组,从而创建虚拟点到点链路。GRE隧道并不提供加密服务,默认情况下以明文方式离开,所以通常使用GRE通过IPsec vpn隧道传输动态路由协议数据流。


封装过程:

1、原数据流根据路由表转发进入tunnel中。

2、根据tunnel的配置被封装为GRE数据流,之后GRE数据流与tunnel所指定的source、destination地址组成新的IP报头GRE数据流。

3、新IP报头的GRE数据流再根据路由表转发到适应的出接口。

4、在出接口时,新IP报头的GRE数据流匹配了×××的加密映射表的ACL,所以新IP报头的GRE数据流被封装进了×××隧道中,之后形成的×××数据流转发出接口。


解封装过程:

1、路由器接收到数据流后判断为×××数据流,从而进行vpn解封装,之后得到带有”新IP报头“的GRE数据流。

2、”新IP报头"的GRE数据流被转到tunnel中,去掉”新ip报头”再进行GRE解封装,得到原始数据流。

3、原始数据流根据路由表转到目标出口,期间经过从tunnel中出来。



tunnel(GRE隧道)与IPsec ×××隧道异同:

1、两者都可以保留原始IP数据流情况下进行封装,并异地传输。

2、tunnel在异地的两端建立虚拟隧道接口,相当于异地是直连关系(可以建立邻居关系),从而能传输动态协议等数据流,tunnel数据流以明文方式传输;IPsec ×××隧道没有虚接口,只传输单播而不能传输多播和广播,从而使众多路由协议无法建立邻居关系和传输路由更新,由于×××封装是加密的,所以数据流以密文方式传输。

3、两者可以独立使用不相影响。但通常将两者组合使用,达到支持所有数据传输格式与安全,即tunnel被封装进IPSec ×××中。




实验目录:

1)配置GRE,并观察传输GRE过程。

2)配置IPSec ×××

3)配置将GRE隧道封装到×××里边。


实验拓扑:
防火墙 tunnel(GRE隧道)+×××配置过程分析_防火墙

实验配置:

 

1)各接口IP配置如上图,并在R3R2上配置GRE隧道。

 

R3#sh run

 

interface Tunnel3

 ip address 10.10.10.1 255.255.255.0   \\虚接口地址

 tunnel source 3.3.3.10

 tunnel destination 2.2.2.10   \\作为GRE封装后新的IP报头。

!

interface FastEthernet0/0

 ip address 3.3.3.10 255.255.255.0

 duplex auto

 speed auto

!

interface FastEthernet0/1

 ip address 192.168.1.1 255.255.255.0

 speed auto

 full-duplex

!

router eigrp 100

 network 10.10.10.0 0.0.0.255

 network 192.168.1.0

 no auto-summary

!

ip route 0.0.0.0 0.0.0.0 3.3.3.3

 

R3#

 

 

R2#sh run

 

interface Tunnel2             \\与上面的R3tunnel3对应。

 ip address 10.10.10.2 255.255.255.0

 tunnel source 2.2.2.10

 tunnel destination 3.3.3.10

!

interface FastEthernet0/0

 ip address 2.2.2.10 255.255.255.0

 duplex auto

 speed auto

!

interface FastEthernet0/1

 ip address 172.16.1.1 255.255.255.0

 duplex auto

 speed auto

!

router eigrp 100

 network 10.10.10.0 0.0.0.255

 network 172.16.1.0 0.0.0.255

 no auto-summary

!

ip route 0.0.0.0 0.0.0.0 2.2.2.1

 

R2#

 

1.1)查看路由

 

R3(config)#do sh ip rou

Gateway of last resort is 3.3.3.3 to network 0.0.0.0

     3.0.0.0/24 is subnetted, 1 subnets

C       3.3.3.0 is directly connected, FastEthernet0/0

     172.16.0.0/24 is subnetted, 1 subnets

D       172.16.1.0 [90/297270016] via 10.10.10.2, 03:50:38, Tunnel3         \\目标地址的出口为tunnel3

     10.0.0.0/24 is subnetted, 1 subnets

C       10.10.10.0 is directly connected,Tunnel3     \\目标地址的出口为tunnel3

C    192.168.1.0/24 is directly connected, FastEthernet0/1

S*   0.0.0.0/0 [1/0] via 3.3.3.3

R3(config)#

 

R2#sh ip rou

Gateway of last resort is 2.2.2.1 to network 0.0.0.0

     2.0.0.0/24 is subnetted, 1 subnets

C       2.2.2.0 is directly connected, FastEthernet0/0

     172.16.0.0/24 is subnetted, 1 subnets

C       172.16.1.0 is directly connected, FastEthernet0/1

     10.0.0.0/24 is subnetted, 1 subnets

C       10.10.10.0 is directly connected, Tunnel2

D    192.168.1.0/24 [90/297270016] via 10.10.10.1, 03:54:10, Tunnel2

S*   0.0.0.0/0 [1/0] via 2.2.2.1

R2#    

 

1.2)检测连通性及路由跟踪

 

R3#ping 172.16.1.2 sou 192.168.1.1

Type escape sequence to abort.

Sending 5, 100-byte ICMP Echos to 172.16.1.2, timeout is 2 seconds:

Packet sent with a source address of 192.168.1.1

!!!!!

Success rate is 100 percent (5/5), round-trip min/avg/max = 68/90/100 ms

R3#

 

R3#trace 172.16.1.2 sou 192.168.1.1

Type escape sequence to abort.

Tracing the route to 172.16.1.2

  1 10.10.10.2 84 msec 96 msec 60 msec

  2 172.16.1.2 96 msec 92 msec 76 msec

 

R3#

 

R3#trace 172.16.1.1 sou 192.168.1.1

 

Type escape sequence to abort.

Tracing the route to 172.16.1.1

  1 10.10.10.2 92 msec 56 msec 72 msec

R3#

 

已通表明GRE隧道正常,此时异地之间如同处于一个局域网内且可以进行动态路由的更新。

 

 

3)由于GRE隧道通讯是不安全的,所以将GRE数据流封装进×××隧道,此时×××原封不动的加密新IP报头的GRE数据流,并将其传输到异地。注:加密并保留原始IP数据流是×××的特征,而本次被×××封装的原始IP数据流指的是新IP报头的GRE隧道。

 

IPsec ×××配置,R3R2相对应。

 

R3#sh run

 

crypto isakmp policy 1

 encr aes

 authentication pre-share

crypto isakmp key 6 cisco123 address 2.2.2.10    \\这几步都是配置isakmp

!

!

crypto ipsec transform-set gre_vpn esp-3des esp-sha-hmac      \\配置ipsec

!

crypto map gre_map 10 ipsec-isakmp   \\配置map

 set peer 2.2.2.10

 set transform-set gre_vpn

 match address 100

 

access-list 100 permit gre host 3.3.3.10 host 2.2.2.10    \\将新IP报头的GRE数据流标为×××封装的感兴趣流。

 

interface FastEthernet0/0

 ip address 3.3.3.10 255.255.255.0

 duplex auto

 speed auto

 crypto map gre_map    \\将加密映射表应用于接口

 

R3#

 

查看×××隧道建立情况

 

R3#sh crypto session

Crypto session current status

Interface: FastEthernet0/0

Session status: UP-ACTIVE     \\表明×××隧道建立成功

Peer: 2.2.2.10 port 500

  IKE SA: local 3.3.3.10/500 remote 2.2.2.10/500 Active

  IPSEC FLOW: permit 47 host 3.3.3.10 host 2.2.2.10    \\×××数据流的原始IP(这里指GRE新报头的IP)。红色标注的”47”很重要,它指出了×××的原始IP数据流协议为GRE,如果是IP协议,那么”47“会变为ip,这些协议在定义×××感兴趣流ACL时已经指出来了。

        Active SAs: 2, origin: crypto map

R3#

 

查看路由

 

R3#sh ip rou

Gateway of last resort is 3.3.3.3 to network 0.0.0.0

     3.0.0.0/24 is subnetted, 1 subnets

C       3.3.3.0 is directly connected, FastEthernet0/0

     172.16.0.0/24 is subnetted, 1 subnets

D       172.16.1.0 [90/297270016] via 10.10.10.2, 00:21:08, Tunnel3

     10.0.0.0/24 is subnetted, 1 subnets

C       10.10.10.0 is directly connected, Tunnel3

C    192.168.1.0/24 is directly connected, FastEthernet0/1

S*   0.0.0.0/0 [1/0] via 3.3.3.3

R3#

 

与建立GRE隧道时路由表一样。更加说明×××隧道不会影响路由的转发。

 

检测链路连通

 

R3#ping  172.16.1.2 sou 192.168.1.1

Type escape sequence to abort.

Sending 5, 100-byte ICMP Echos to 172.16.1.2, timeout is 2 seconds:

Packet sent with a source address of 192.168.1.1

!!!!!

Success rate is 100 percent (5/5), round-trip min/avg/max = 104/120/140 ms

R3#trace 172.16.1.2 sou 192.168.1.1

Type escape sequence to abort.

Tracing the route to 172.16.1.2

  1 10.10.10.2 96 msec 124 msec 68 msec

  2 172.16.1.2 128 msec 108 msec 88 msec

R3#

 

 

到此GRE隧道+×××隧道组合建立成功。

 

 

 

识扩知展:在虚接口上建立tunnel隧道,实际中比较稳定,在IPV6过渡中应用很多。

 

1、在R3上将tunnelsourcedestination分别30.3.3.1020.2.2.10

 

interface Tunnel3

 ip address 10.10.10.1 255.255.255.0

 tunnel source 30.3.3.10

 tunnel destination 20.2.2.10

 

 

×××的感兴趣流设置为

 

access-list 100 permit gre host 30.3.3.10 host 20.2.2.10

 

R2做相应配置,查看结果

 

R3(config)#do sh  cry se 

Crypto session current status

Interface: FastEthernet0/0

Session status: UP-ACTIVE     \\表明×××已建立成功

Peer: 2.2.2.10 port 500

  IKE SA: local 3.3.3.10/500 remote 2.2.2.10/500 Active

  IPSEC FLOW: permit 47 host 30.3.3.10 host 20.2.2.10

        Active SAs: 2, origin: crypto map

R3(config)#

 

R3(config)#do ping 10.10.10.2

Type escape sequence to abort.

Sending 5, 100-byte ICMP Echos to 10.10.10.2, timeout is 2 seconds:

.....

Success rate is 0 percent (0/5)

R3(config)#

 

tunnel隧道没有建立成功。这由于tunnel是在30.3.3.1020.2.2.10连接的基础上建立的,而这两个IP压根都没在各自的路由器上,所以这两个IP之间是无法通讯的,更别说tunnel建立了。

 

所以在各自路由器上建立虚接口

 

R3#

 

interface Loopback20

 ip address 30.3.3.10 255.255.255.255

 

R2#

 

interface Loopback20

 ip address 20.2.2.10 255.255.255.255

 

结果

 

R3(config-if)#do ping 10.10.10.2

Type escape sequence to abort.

Sending 5, 100-byte ICMP Echos to 10.10.10.2, timeout is 2 seconds:

!!!!!

Success rate is 100 percent (5/5), round-trip min/avg/max = 104/122/152 ms

R3(config-if)#

 

R3(config-if)#do sh ip rou

     3.0.0.0/24 is subnetted, 1 subnets

C       3.3.3.0 is directly connected, FastEthernet0/0

     172.16.0.0/24 is subnetted, 1 subnets

D       172.16.1.0 [90/297270016] via 10.10.10.2, 00:11:07, Tunnel3    \\表明动态路由EIGRP与异地路由器建立成功。也说明tunnel建立成功。

     10.0.0.0/24 is subnetted, 1 subnets

C       10.10.10.0 is directly connected, Tunnel3

C    192.168.1.0/24 is directly connected, FastEthernet0/1

     30.0.0.0/32 is subnetted, 1 subnets

C       30.3.3.10 is directly connected, Loopback30

S*   0.0.0.0/0 [1/0] via 3.3.3.3

R3(config-if)#

 

 

这就是文章前面提到过tunnel建立的条件:tunnel中的sourcedestination,这两个地址必须是UP状态的接口IP(包括虚接口),且两者保证能够通讯(包括路由可达、×××等。×××原始IP数据流协议为GRE时,两者ping不通,但也能够通讯的)。

 

现在tunnel已建立成功了,表明sourcedestination之间肯定能够通讯了,但两者之间却Ping通,这是为什么???

 

R3#ping 20.2.2.10 sou 30.3.3.10

Type escape sequence to abort.

Sending 5, 100-byte ICMP Echos to 20.2.2.10, timeout is 2 seconds:

Packet sent with a source address of 30.3.3.10

.....

Success rate is 0 percent (0/5)

R3#

 

因为使用ping针对的是数据流协议为ip才行,而本例中对于×××来说所封装的原始IP数据流协议为GRE,所以不能用ping来测试这两个IP

 

R3#sh crypto session

Crypto session current status

Interface: FastEthernet0/0

Session status: UP-ACTIVE    

Peer: 2.2.2.10 port 500

  IKE SA: local 3.3.3.10/500 remote 2.2.2.10/500 Active

  IPSEC FLOW: permit 47 host 30.3.3.10 host 20.2.2.10   \\47”表明为GRE协议,如果为“IP”则是IP协议,那么才可以ping通。

        Active SAs: 2, origin: crypto map

R3#

---------------------