GRE over IPSec(基于思科设备)

GRE over IPSec(基于思科设备)

GRE是一种最传统的隧道协议,其根本功能就是要实现隧道功能,通过隧道连接的两个远程网络就如同直连,GRE在两个远程网络之间模拟出直连链路,从而使网络间达到直连的效果,为此,GRE需要完成多次封装,总共有3次,换句话说,就是在GRE隧道中传输的数据包都有3个包头,因为我们只谈IP协议,所以GRE中的IP数据包是一层套一层,总共有3个IP地址。GRE在实现隧道时,需要创建虚拟直连链路,GRE实现的虚拟直连链路可以认为是隧道,隧道是模拟链路,所以隧道两端也有IP地址,但隧道需要在公网中找到起点和终点,所以隧道的源和终点分别都以公网IP地址结尾,该链路是通过GRE协议来完成的,隧道传递数据包的过程分为3步:
1.接收原始IP数据包当作乘客协议,原始IP数据包包头的IP地址为私有IP地址。
2.将原始IP数据包封装进GRE协议,GRE协议称为封装协议(Encapsulation Protocol),封装的包头IP地址为虚拟直连链路两端的IP地址。
3.将整个GRE数据包当作数据,在外层封装公网IP包头,也就是隧道的起源和终点,从而路由到隧道终点。

通过GRE通用路由封装协议来建立一个非安全的隧道去传递私网路由,而且GRE支持组播协议,所以也就支持动态路由协议。但GRE的安全性就需要IPSEC去保证了,而IPSEC可悲的是又不支持组播,除非用到其它诸如VTI的一些技术了。所以自然而然,人们就想到GRE overIPSEC的×××去安全的传递内网数据。

实验步骤

GRE over IPSec(基于思科设备)

1:R1的IP和默认路由器的设置
R1#conf t
R1(config)#int f0/1
R1(config-if)#ip add 192.168.1.254 255.255.255.0
R1(config-if)#no shut
R1(config-if)#int f0/0
R1(config-if)#ip address 200.0.0.1 255.255.255.0
R1(config-if)#no shut
R1(config-if)#exit
R1(config)#ip route 0.0.0.0 0.0.0.0 200.0.0.2

2:ISP路由器的IP设置(运营商设备不设置前往私有网络的路由)
R2#conf t
R2(config)#int f0/0
R2(config-if)#ip add 200.0.0.2 255.255.255.0
R2(config-if)#no shut
R2(config-if)#int f0/1
R2(config-if)#ip add 100.0.0.2 255.255.255.0
R2(config-if)#no shut

3:R3的IP和默认路由的设置
R3#conf t
R3(config)#int f0/1
R3(config-if)#ip add 192.168.2.254 255.255.255.0
R3(config-if)#no shut
R3(config-if)#int f0/0
R3(config-if)#ip add 100.0.0.1 255.255.255.0
R3(config-if)#no shut
R3(config-if)#exit
R3(config)#ip route 0.0.0.0 0.0.0.0 100.0.0.2

4:R4路由器的IP设置(模拟总部内网的路由器)
R4#conf t
R4(config)#int f0/0
R4(config-if)#ip add 192.168.1.1 255.255.255.0
R4(config-if)#no shut
R4(config-if)#int loop0
R4(config-if)#ip add 172.16.0.1 255.255.0.0
R4(config-if)#exit

5:R1隧道接口的设置
R1(config)#int tunnel 0
R1(config-if)#ip add 10.0.0.1 255.0.0.0
R1(config-if)#tunnel source 200.0.0.1
R1(config-if)#tunnel destination 100.0.0.1
R1(config-if)#exit

6:R3隧道接口的设置
R3(config)#int tunnel 0
R3(config-if)#ip add 10.0.0.2 255.0.0.0
R3(config-if)#tunnel source 100.0.0.1
R3(config-if)#tunnel destination 200.0.0.1
R3(config-if)#exit
R3(config)#

7:R1路由器的ospf设置
R1(config)#router ospf 1
R1(config-router)#network 10.0.0.0 0.255.255.255 area 0
R1(config-router)#network 192.168.1.0 0.0.0.255 area 0
R1(config-router)#exit

8:R3路由器的ospf设置
R3(config)#router ospf 1
R3(config-router)#network 10.0.0.0 0.255.255.255 area 0
R3(config-router)#network 192.168.2.0 0.0.0.255 area 0
R3(config-router)#exit
R3(config)#

9:R4路由器的ospf的设置
R4(config)#router ospf 1
R4(config-router)#network 192.168.1.0 0.0.0.255 area 0
R4(config-router)#network 172.16.0.0 0.0.255.255 area 0
R4(config-router)#end

10:R1的路由表
R1#show ip route

C 200.0.0.0/24 is directly connected, FastEthernet0/0
172.16.0.0/32 is subnetted, 1 subnets
O 172.16.0.1 [110/2] via 192.168.1.1, 00:08:52, FastEthernet0/1
C 10.0.0.0/8 is directly connected, Tunnel0
C 192.168.1.0/24 is directly connected, FastEthernet0/1
O 192.168.2.0/24 [110/11112] via 10.0.0.2, 00:08:52, Tunnel0
S* 0.0.0.0/0 [1/0] via 200.0.0.2

11:R3的路由表
R3#show ip route

 100.0.0.0/24 is subnetted, 1 subnets

C 100.0.0.0 is directly connected, FastEthernet0/0
172.16.0.0/32 is subnetted, 1 subnets
O 172.16.0.1 [110/11113] via 10.0.0.1, 00:10:00, Tunnel0
C 10.0.0.0/8 is directly connected, Tunnel0
O 192.168.1.0/24 [110/11112] via 10.0.0.1, 00:10:00, Tunnel0
C 192.168.2.0/24 is directly connected, FastEthernet0/1
S* 0.0.0.0/0 [1/0] via 100.0.0.2

12:R4的路由表
R4#show ip route

C 172.16.0.0/16 is directly connected, Loopback0
O 10.0.0.0/8 [110/11112] via 192.168.1.254, 00:00:14, FastEthernet0/0
C 192.168.1.0/24 is directly connected, FastEthernet0/0
O 192.168.2.0/24 [110/11113] via 192.168.1.254, 00:00:14, FastEthernet0/0

此处要注意虽然两个路由器都有前往对方私有网络的路由,但是两个局域网现在是不通的,因为GRE隧道只保护ospf的流量,不保护用户业务流量,在没有配置×××时,是不对业务流量进行保护的,所以两个局域网此时虽然有路由,但是不能通信

13:R1的×××的设置
R1(config)#crypto isakmp policy 10
R1(config-isakmp)#encryption aes 128
R1(config-isakmp)#hash sha
R1(config-isakmp)#authentication pre-share
R1(config-isakmp)#group 2
R1(config-isakmp)#exit
R1(config)#

R1(config)#crypto isakmp key 0 cisco123 address 100.0.0.1 no-xauth
R1(config)#access-list 101 permit gre host 200.0.0.1 host 100.0.0.1
R1(config)#crypto ipsec transform-set myset esp-aes esp-sha-hmac
R1(cfg-crypto-trans)#mode transport
R1(cfg-crypto-trans)#exit
R1(config)#crypto map cisco-map 10 ipsec-isakmp
R1(config-crypto-map)#set peer 100.0.0.1
R1(config-crypto-map)#set transform-set myset
R1(config-crypto-map)#match address 101
R1(config-crypto-map)#exit
R1(config)#int f0/0
R1(config-if)#crypto map cisco-map
R1(config-if)#

14:R3的×××设置
R3(config)#crypto isakmp policy 10
R3(config-isakmp)#encryption aes 128
R3(config-isakmp)#hash sha
R3(config-isakmp)#authentication pre-share
R3(config-isakmp)#group 2
R3(config-isakmp)#exit
R3(config)#crypto isakmp key 0 cisco123 address 200.0.0.1 no-xauth
R3(config)#access-list 101 permit gre host 100.0.0.1 host 200.0.0.1
R3(config)#crypto ipsec transform-set myset esp-aes esp-sha-hmac
R3(cfg-crypto-trans)#mode transport
R3(cfg-crypto-trans)#exit
R3(config)#crypto map cisco-map 10 ipsec-isakmp
R3(config-crypto-map)#set peer 200.0.0.1
R3(config-crypto-map)#set transform-set myset
R3(config-crypto-map)#match address 101
R3(config-crypto-map)#int f0/0
R3(config-if)#crypto map cisco-map
R3(config-if)#

15:测试
两个局域网之间的网络可以互通,但是,局域网不能ping通ISP的网络,要想和运营商互通,需要对上网的流量做nat转换,本案例不讨论此过程
可以将R1上的GRE隧道删除掉
R1(config)#no int tunnel 0
R1(config)#end
R1#show ip route

C 200.0.0.0/24 is directly connected, FastEthernet0/0
172.16.0.0/32 is subnetted, 1 subnets
O 172.16.0.1 [110/2] via 192.168.1.1, 00:00:01, FastEthernet0/1
C 192.168.1.0/24 is directly connected, FastEthernet0/1
S* 0.0.0.0/0 [1/0] via 200.0.0.2
再用pc2 ping172.16.0.1发现不通了

猜你喜欢

转载自blog.51cto.com/72756/2368037