54 GRE-VPN 点到点

一 理论

1  GRE 概念

GRE(Generic Routing Encapsulation,通用路由封装)协议用来对某种协议(如IP、以太网)的数据报文进行封装,使这些被封装的数据报文能够在另一个网络(如IP)中传输。封装前后数据报文的网络层协议可以相同,也可以不同。封装后的数据报文在网络中传输的路径,称为GRE隧道。GRE隧道是一个虚拟的点到点的连接,其两端的设备分别对数据报文进行封装及解封装。

2 GRE 协议

图1-1所示,GRE封装后的报文包括如下几个部分:

· 净荷数据(Payload packet):需要封装和传输的数据报文。净荷数据的协议类型,称为乘客协议(Passenger Protocol)。乘客协议可以是任意的网络层协议。

· GRE头(GRE header):采用GRE协议对净荷数据进行封装所添加的报文头,包括封装层数、版本、乘客协议类型、校验和信息、Key信息等内容。添加GRE头后的报文称为GRE报文。对净荷数据进行封装的GRE协议,称为封装协议(Encapsulation Protocol)。

· 传输协议的报文头(Delivery header):在GRE报文上添加的报文头,以便传输协议对GRE报文进行转发处理。传输协议(Delivery Protocol或者Transport Protocol)是指负责转发GRE报文的网络层协议。设备支持IPv4和IPv6两种传输协议:当传输协议为IPv4时,GRE隧道称为GRE over IPv4隧道;当传输协议为IPv6时,GRE隧道称为GRE over IPv6隧道。

3 GRE 原理

(1)      Device A从连接IPv6 network 1的接口收到IPv6报文后,查找路由表判定此报文需要通过GRE隧道模式的Tunnel接口(本例中为Tunnel0)转发,并将报文发给相应的Tunnel接口。

(2)      GRE隧道模式的Tunnel接口收到此IPv6报文后,先在报文前封装上GRE头,再封装上IPv4头。IPv4头中的源地址为隧道的源端地址(本例中为Device A的Interface A接口的IP地址),目的地址为隧道的目的端地址(本例中为Device B的Interface B接口的IP地址)。

(3)      Device A根据封装的IPv4头中的目的地址查找路由表,将封装后的IPv4报文通过GRE隧道的实际物理接口(Interface A)转发出去。

(4)      封装后的IPv4报文通过GRE隧道到达隧道的目的端设备Device B后,由于报文的目的地是本设备,且IPv4头中的协议号为47(表示封装的报文为GRE报文),Device B将此报文交给GRE协议进行解封装处理。

(5)      GRE协议先剥离掉此报文的IPv4头,再对报文进行GRE Key验证、校验和验证、报文序列号检查等处理,处理通过后再剥离掉报文的GRE头,将报文交给IPv6协议进行后续的转发处理。

4  GRE 配置思路

(1)      进入系统视图。

system-view

(2)      创建模式为GRE over IPv4隧道的Tunnel接口,并进入该Tunnel接口视图。

interface tunnel number mode gre

[FW-Tunn1-1060]interface  Tunnel  1 mode  ?
  ds-lite-aftr  DS-Lite AFTR tunnel mode
  gre           Generic Routing Encapsulation (GRE)
  ipv4-ipv4     IPv4 over IPv4 tunnel mode
  ipv6          IPv6 tunnel mode
  ipv6-ipv4     IPv6 over IPv4 tunnel mode
  mpls-te       MPLS TE tunnel mode

[FW-Tunn1-1060]interface  Tunnel  1 mode  gr
[FW-Tunn1-1060]interface  Tunnel  1 mode  gre  ?
  ipv6  GRE over IPv6 tunnel mode
  <cr>  

[FW-Tunn1-1060]interface  Tunnel  1 mode  gre  ip
[FW-Tunn1-1060]interface  Tunnel  1 mode  gre  ipv6  ?
  <cr>  

[FW-Tunn1-1060]interface  Tunnel  1 mode  gre  ipv6  

在隧道的两端应配置相同的隧道模式,否则可能造成报文传输失败。

(3)      根据乘客协议,设置Tunnel接口的IP地址。

(IPv4网络)

IPv4地址的配置方法,请参见“三层技术-IP业务配置指导”中的“IP地址”。

(IPv6网络)

IPv6地址的配置方法,请参见“三层技术-IP业务配置指导”中的“IPv6基础”。

缺省情况下,Tunnel接口上未设置IP地址。

 ip address 30.30.30.1 255.255.255.0

(4)      设置隧道的源端地址或源接口。

source { ip-address | interface-type interface-number }

缺省情况下,未设置隧道的源端地址和源接口。

如果设置的是隧道的源端地址,则该地址将作为封装后隧道报文的源IPv4地址;如果设置的是隧道的源接口,则该接口的主IP地址将作为封装后隧道报文的源IPv4地址。

(5)      设置隧道的目的端地址。

destination ip-address

缺省情况下,未设置隧道的目的端地址。

隧道的目的端地址是对端从GRE隧道上接收报文的实际物理接口的地址,该地址将作为封装后隧道报文的目的IPv4地址。该地址不能与Tunnel接口的地址在同一网段。

(6)      (可选)开启GRE的keepalive功能,并配置keepalive报文发送周期及最大发送次数。

keepalive [ interval [ times ] ]

缺省情况下,GRE的keepalive功能处于关闭状态。

(7)      (可选)配置GRE安全功能。

?  开启GRE报文校验和功能。

gre checksum

缺省情况下,GRE报文校验和功能处于关闭状态。

?  设置GRE类型Tunnel接口的GRE Key。

gre key key

缺省情况下,未设置GRE类型Tunnel接口的GRE Key。

隧道两端必须设置相同的GRE Key,或者都不设置GRE Key。

(8)      (可选)设置封装后隧道报文的DF(Don’t Fragment,不分片)标志。

tunnel dfbit enable

缺省情况下(默认情况下),未设置隧道报文的不分片标志,即转发隧道报文时允许分片。

二 实操

FW1  脚本


vlan 1
#
object-group ip address untrust
#
interface NULL0
#
interface GigabitEthernet1/0/0
 port link-mode route
 combo enable copper
#
interface GigabitEthernet1/0/1
 port link-mode route
 combo enable copper
 ip address 192.168.0.1 255.255.255.0
#
interface GigabitEthernet1/0/2
 port link-mode route
 combo enable copper
#
interface GigabitEthernet1/0/3
 port link-mode route
 combo enable copper
#
interface GigabitEthernet1/0/4
 port link-mode route
 combo enable copper
 ip address 192.168.23.2 255.255.255.0
 manage http inbound
 manage http outbound
 manage https inbound
 manage https outbound
 manage ping inbound
 manage ping outbound
 manage ssh inbound
 manage ssh outbound
#
interface GigabitEthernet1/0/5
 port link-mode route
 combo enable copper
#
interface GigabitEthernet1/0/6
 port link-mode route
 combo enable copper
 ip address 10.10.10.10 255.255.255.0
 manage http inbound
 manage http outbound
 manage https inbound
 manage https outbound
 manage ping inbound
 manage ping outbound
 manage ssh inbound
 manage ssh outbound
 manage telnet inbound
 manage telnet outbound
#
interface GigabitEthernet1/0/7
 port link-mode route
 combo enable copper

interface Tunnel0 mode gre
 ip address 30.30.30.1 255.255.255.0
 source 10.10.10.10
 destination 20.20.20.1
#
security-zone name Local
#
security-zone name Trust
 import interface GigabitEthernet1/0/4
#
security-zone name DMZ
#
security-zone name Untrust
 import interface GigabitEthernet1/0/6
#
security-zone name Management
 import interface GigabitEthernet1/0/1

#
 ip route-static 20.20.20.0 24 10.10.10.2
#
 info-center loghost 127.0.0.1 port 3301 format default
 info-center source CFGLOG loghost level informational
#
 ssh server enable
#
domain system
#
 aaa session-limit ftp 16
 aaa session-limit telnet 16
 aaa session-limit ssh 16
 domain default enable system

local-user admin class manage
 password hash $h$6$0zYuhgGtsVVU4g33$2+AJbQUeSw+GVu3OhSAMGl8sQ3+wYqm2drHrRZ+pygF6uiDxa5tendwi8nti3c04WRvq7dxELJKWDlZRrgpu6A==
 service-type ssh telnet terminal http https
 authorization-attribute user-role level-3
 authorization-attribute user-role network-admin
 authorization-attribute user-role network-operator
#
local-user root class manage
 authorization-attribute user-role network-operator
#
 ip http enable
 ip https enable
#
security-policy ip
 rule 0 name grelocalout
  action pass
  source-zone local
  destination-zone untrust
  source-ip-host 10.10.10.10 
  source-ip-host 30.30.30.1 
  source-ip-host 192.168.23.2 
  destination-ip-host 20.20.20.1 
  destination-ip-host 30.30.30.2 
  destination-ip-host 192.168.24.2 
 rule 1 name grelocalin
  action pass
  source-zone untrust
  destination-zone local
  source-ip-host 20.20.20.1 
  source-ip-host 30.30.30.2 
  source-ip-host 192.168.24.2 
  destination-ip-host 10.10.10.10 
  destination-ip-host 30.30.30.1 
  destination-ip-host 192.168.23.2 
#
return

FW2 脚本


interface GigabitEthernet1/0/1
 port link-mode route
 combo enable copper
 ip address 192.168.0.2 255.255.255.0
#
interface GigabitEthernet1/0/6
 port link-mode route
 combo enable copper
 ip address 20.20.20.1 255.255.255.0
 manage http inbound
 manage http outbound
 manage https inbound
 manage https outbound
 manage ping inbound
 manage ping outbound
 manage ssh inbound
 manage ssh outbound
 manage telnet inbound
 manage telnet outbound
#
interface GigabitEthernet1/0/8
 port link-mode route
 combo enable copper
 ip address 192.168.24.2 255.255.255.0
 manage http inbound
 manage http outbound
 manage https inbound
 manage https outbound
 manage ping inbound
 manage ping outbound
 manage ssh inbound
 manage ssh outbound

interface Tunnel0 mode gre
 ip address 30.30.30.2 255.255.255.0
 source 20.20.20.1
 destination 10.10.10.10
#
security-zone name Local
#
security-zone name Trust
 import interface GigabitEthernet1/0/8
#
security-zone name DMZ
#
security-zone name Untrust
 import interface GigabitEthernet1/0/6
#
security-zone name Management
 import interface GigabitEthernet1/0/1
#
 ip route-static 10.10.10.0 24 20.20.20.2
#
 info-center loghost 127.0.0.1 port 3301 format default
 info-center source CFGLOG loghost level informational
#
 ssh server enable

local-user admin class manage
 password hash $h$6$UbIhNnPevyKUwfpm$LqR3+yg1IjNct39MkOR0H0iQXLkYB3jMqM4vbAeoXOhbabIIFnjJPEGR00YiYA1Sz4LiY3FmEdru2fOLMb1shQ==
 service-type telnet terminal http
 authorization-attribute user-role level-3
 authorization-attribute user-role network-admin
 authorization-attribute user-role network-operator
#
local-user root class manage
 password hash $h$6$GZ6Hlw+QN9floEjl$zAAAoM8tPLMDtyLMDjudNXm4adPyVQsgEK1Rcta9Rz+L342wGHx9+Ff32n+HtVh51vMOxi3c/6FDNQ4uxoEKWQ==
 service-type ssh telnet terminal http https
 authorization-attribute user-role level-15
 authorization-attribute user-role network-root
 authorization-attribute user-role network-operator
#
 ip http enable
 ip https enable
#
security-policy ip
 rule 0 name grelocalout
  source-zone local
  destination-zone untrust
  source-ip-host 20.20.20.1 
  source-ip-host 30.30.30.2 
  source-ip-host 192.168.24.1 
  destination-ip-host 10.10.10.10 
  destination-ip-host 30.30.30.1 
  destination-ip-host 192.168.23.2 
 rule 1 name grelocalin
  source-zone untrust
  destination-zone local
  source-ip-host 10.10.10.10 
  source-ip-host 30.30.30.1 
  source-ip-host 192.168.23.2 
  destination-ip-host 20.20.20.1 
  destination-ip-host 30.30.30.2 
  destination-ip-host 192.168.24.1 
#
return

R1 脚本

#
interface GigabitEthernet0/1
 port link-mode route
 combo enable copper
 ip address 10.10.10.2 255.255.255.0
#
interface GigabitEthernet0/2
 port link-mode route
 combo enable copper
 ip address 20.20.20.2 255.255.255.0
#

GRE 测试

[FW-Tunn1-1060]display  interface  Tunnel 0
Tunnel0
Current state: UP
Line protocol state: DOWN
Description: Tunnel0 Interface
Bandwidth: 64 kbps
Maximum transmission unit: 1468
Internet address: 30.30.30.1/24 (Primary)
Tunnel source 10.10.10.10, destination 20.20.20.1
Tunnel keepalive enabled, Period(34 s), Retries(3)
Tunnel TTL 255
Tunnel protocol/transport GRE/IP
    GRE key value is 5
    Checksumming of GRE packets enabled
Last clearing of counters: Never
Last 300 seconds input rate: 0 bytes/sec, 0 bits/sec, 0 packets/sec
Last 300 seconds output rate: 0 bytes/sec, 0 bits/sec, 0 packets/sec
Input: 0 packets, 0 bytes, 0 drops
Output: 4 packets, 128 bytes, 0 drops
[FW-Tunn1-1060]display  interface  Tunnel brief 
Brief information on interfaces in route mode:
Link: ADM - administratively down; Stby - standby
Protocol: (s) - spoofing
Interface            Link Protocol Primary IP      Description                
Tun0                 UP   DOWN     30.30.30.1      

三 脚本技术解析

  1. IRF(Intelligent Resilient Framework):IRF是华三交换机的高可用性技术,可以将多台交换机虚拟化为单个逻辑设备,提供冗余和容错功能。

  2. VLAN:虚拟局域网(VLAN)是将局域网划分为多个逻辑网段的技术,可以增强网络的安全性和性能。

  3. 接口配置:配置了各个物理接口(GigabitEthernet1/0/0到GigabitEthernet1/0/23)的链路模式、协议类型和IP地址。

  4. 安全区域(Security Zone):安全区域将不同的接口划分到不同的安全域中,可以实现流量隔离和安全策略。

  5. 用户角色(User Role):配置了用户角色,用于授权不同用户访问交换机的权限。

  6. SSH、Telnet和HTTP/HTTPS管理:配置了通过SSH、Telnet、HTTP和HTTPS协议对交换机进行远程管理。

  7. IP路由:配置了静态路由,用于指定数据包的转发路径。

  8. 安全策略(Security Policy):配置了IP层面的安全策略,包括允许或禁止特定源和目的IP地址之间的通信。

  9. GRE(Generic Routing Encapsulation)是一种隧道协议,可用于在不同的网络中传输IP数据包。GRE VPN(GRE Virtual Private Network)是通过GRE协议在公共网络上创建一个私密的虚拟网络。它可以通过将IP数据包封装在GRE封装中来实现数据的安全传输和隐私保护。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

人生的方向随自己而走

世界上没有免费的午餐

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值