防火牆 tunnel(GRE隧道)+×××配置過程分析

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 ***隧道傳輸動態路由協議數據流。


封裝過程:

1、原數據流根據路由錶轉發進入tunnel中。

2、根據tunnel的配置被封裝爲GRE數據流,之後GRE數據流與tunnel所指定的source、destination地址組成新的IP報頭GRE數據流。

3、新IP報頭的GRE數據流再根據路由錶轉發到適應的出接口。

4、在出接口時,新IP報頭的GRE數據流匹配了×××的加密映射表的ACL,所以新IP報頭的GRE數據流被封裝進了×××隧道中,之後形成的×××數據流轉發出接口。


解封裝過程:

1、路由器接收到數據流後判斷爲×××數據流,從而進行***解封裝,之後得到帶有”新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隧道封裝到×××裏邊。


實驗拓撲:
20150902120918984.png

實驗配置:

 

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_*** esp-3des esp-sha-hmac      \\配置ipsec

!

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

 set peer 2.2.2.10

 set transform-set gre_***

 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#

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





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章