二、详细排查与解决方案
解决方案1:在防火墙上配置GRE相关策略(首选)
步骤1:确认GRE协议细节
GRE协议号:47
Keepalive报文:ICMP Echo Request(协议号1)封装在GRE内
典型端口:无固定端口(三层协议)
步骤2:防火墙配置示例
华为/华三防火墙:
# 创建高级ACL允许GRE协议
acl number 3000
rule permit gre source 1.1.1.1 0 dest 2.2.2.2 0
rule permit gre source 2.2.2.2 0 dest 1.1.1.1 0
# 创建安全策略
security-policy
rule name GRE_Tunnel
source-zone trust
destination-zone untrust
source-address 1.1.1.1 32
dest-address 2.2.2.2 32
service gre
action permit
rule name GRE_Tunnel_Return
source-zone untrust
destination-zone trust
source-address 2.2.2.2 32
dest-address 1.1.1.1 32
service gre
action permit
# 调整会话老化时间
session aging-time gre 3600 # 设置GRE会话老化时间为3600秒
思科ASA防火墙:
access-list OUTSIDE extended permit gre host 1.1.1.1 host 2.2.2.2
access-list OUTSIDE extended permit gre host 2.2.2.2 host 1.1.1.1
# 调整连接超时时间
timeout conn 1:00:00
timeout gre 1:00:00
CheckPoint防火墙:
# 在SmartDashboard中
1. 创建新服务:Protocol=GRE (47)
2. 创建规则:允许源/目的IP的GRE协议
3. 调整Global Properties:
- Stateful Inspection: 启用GRE协议检查
- 设置连接保持时间
解决方案2:调整MSR3640路由器配置
步骤1:优化GRE隧道配置
# 创建Tunnel接口
interface Tunnel0
ip address 192.168.100.1 255.255.255.252
source 1.1.1.1
destination 2.2.2.2
tunnel-protocol gre
# 调整Keepalive参数(重要!)
gre keepalive interval 10 retry-times 3
# interval: 发送间隔(秒),默认10
# retry-times: 重试次数,默认3
# 调整MTU和分片
tunnel dfbit set
tunnel mtu 1400
# 配置静态路由
ip route-static 10.0.0.0 255.255.255.0 Tunnel0
步骤2:优化Keepalive参数
# 方案A:延长Keepalive间隔和重试
interface Tunnel0
gre keepalive interval 30 retry-times 5
# 将间隔从10秒延长到30秒,重试次数增加到5次
# 方案B:启用BFD for GRE(如果支持)
interface Tunnel0
gre bfd enable
bfd min-transmit-interval 1000
bfd min-receive-interval 1000
bfd detect-multiplier 3
步骤3:配置NAT穿越(如果存在NAT)
# 在隧道接口启用NAT穿越
interface Tunnel0
gre key cipher 123456
nat traversal enable
# 在出接口配置NAT
interface GigabitEthernet0/0
ip address 1.1.1.1 255.255.255.0
nat outbound
解决方案3:完全禁用Keepalive的替代方案
方案A:使用静态路由+Track
# 创建NQA检测
nqa entry admin test
type icmp-echo
destination ip 2.2.2.2
frequency 5000
reaction 1 checked-element probe-fail threshold-type consecutive 3
# 创建Track关联NQA
track 1 nqa entry admin test
# 配置浮动路由
ip route-static 10.0.0.0 255.255.255.0 Tunnel0 preference 60 track 1
ip route-static 10.0.0.0 255.255.255.0 1.1.1.254 preference 100
方案B:使用IPsec over GRE
# 创建IPsec profile
ipsec profile gre-profile
transform-set trans1
sa duration time-based 3600
# 在GRE隧道应用IPsec
interface Tunnel0
tunnel protection ipsec profile gre-profile
三、详细诊断命令
1. 路由器端诊断
# 查看隧道状态
display interface Tunnel brief
display interface Tunnel0
display tunnel-info all
# 查看Keepalive统计
display gre keepalive statistics interface Tunnel0
# 调试GRE Keepalive报文
debugging gre keepalive packet
terminal debugging
# 查看是否有Keepalive发送/接收
# 查看路由表
display ip routing-table
display ip routing-table 10.0.0.0
# 查看ARP表
display arp all
2. 抓包分析
在路由器两端分别抓包:
路由器A侧:
# 在公网接口抓包
display capture interface GigabitEthernet0/0
# 或在隧道接口抓包
display capture interface Tunnel0
关键观察点:
Keepalive报文是否正常发出
对端是否回应Keepalive
防火墙是否丢弃了某些报文
四、防火墙端配置检查清单
必须放行的协议和端口:
协议
端口/类型
方向
说明
GRE
IP协议47
双向
必须放行
ICMP
协议1
双向
用于Keepalive检测
ESP
IP协议50
双向
如使用IPsec
UDP 500
端口500
双向
IKE协商
UDP 4500
端口4500
双向
NAT-T
防火墙策略优化建议:
创建专门的GRE策略
禁用GRE深度检测(如ASPF/ALG)
延长会话超时时间(建议1-2小时)
允许ICMP协议双向通过
五、分步骤故障排查流程
第1步:基础连通性测试
# 从路由器A测试到路由器B公网IP
ping 2.2.2.2
# 查看是否能通
# 测试到防火墙的连通性
tracert 2.2.2.2
# 查看路径是否经过防火墙
第2步:隧道状态检查
# 检查隧道接口状态
display interface Tunnel0
# 重点关注:
# Line protocol state: Up/Down
# Input/Output packets: 是否有计数增加
第3步:防火墙会话检查
# 在防火墙上查看GRE会话
# 华为/华三防火墙
display firewall session table protocol gre
display firewall session table source-ip 1.1.1.1
# 检查会话状态和超时时间
display firewall statistic system
第4步:报文跟踪
# 在防火墙上启用调试
# 华为/华三防火墙
debugging firewall packet
debugging firewall packet filter acl 3000
六、配置示例(完整配置)
路由器A配置示例:
sysname RouterA
interface GigabitEthernet0/0
ip address 1.1.1.1 255.255.255.0
nat outbound
#
interface Tunnel0
ip address 192.168.100.1 255.255.255.252
tunnel-protocol gre
source 1.1.1.1
destination 2.2.2.2
gre key cipher 123456
gre keepalive interval 30 retry-times 5
#
ip route-static 10.2.0.0 255.255.255.0 Tunnel0
ip route-static 0.0.0.0 0.0.0.0 1.1.1.254
防火墙配置示例(华为/华三):
# 创建地址对象
ip address-set GRE_LOCAL type object
address 1.1.1.1 32
address 2.2.2.2 32
#
# 创建服务对象
ip service-set GRE type object
service protocol gre
#
# 创建安全策略
security-policy
rule name Permit_GRE
source-zone any
destination-zone any
source-address address-set GRE_LOCAL
destination-address address-set GRE_LOCAL
service gre
action permit
#
# 调整会话参数
session aging-time gre 7200
session aging-time icmp 60
七、常见问题与解决方法
问题现象
可能原因
解决方法
隧道时通时断
防火墙会话超时
延长防火墙GRE会话老化时间
Keepalive无响应
防火墙过滤ICMP
允许ICMP协议双向通过
隧道建立失败
防火墙过滤GRE协议
允许IP协议47
白天正常晚上断
空闲超时机制
调整路由器Keepalive间隔
仅单向通
非对称路由
检查防火墙双向策略
八、最佳实践建议
保持Keepalive启用:不要长期禁用Keepalive,否则无法检测隧道故障
调整合理参数:
gre keepalive interval 30 retry-times 5
防火墙专用策略:为GRE创建独立的安全策略
定期监控:监控隧道状态和流量
备份方案:配置Track+NQA实现自动切换
九、紧急恢复脚本
如果问题频繁发生,可以创建自动恢复脚本:
#!/usr/bin/env python3
"""
GRE隧道自动检测与恢复脚本
在路由器上通过Python或计划任务执行
"""
import paramiko
import time
import re
def check_gre_tunnel(host, username, password, tunnel_if='Tunnel0'):
"""检查GRE隧道状态"""
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
ssh.connect(host, username=username, password=password, timeout=10)
stdin, stdout, stderr = ssh.exec_command(f'display interface {tunnel_if}')
output = stdout.read().decode()
# 检查隧道状态
if 'Line protocol state: DOWN' in output:
return False
return True
finally:
ssh.close()
def restart_gre_tunnel(host, username, password, tunnel_if='Tunnel0'):
"""重启GRE隧道"""
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
ssh.connect(host, username=username, password=password, timeout=10)
# 进入系统视图
stdin, stdout, stderr = ssh.exec_command('system-view')
time.sleep(1)
# 重启隧道接口
stdin.write(f'interface {tunnel_if}\n')
stdin.write('shutdown\n')
time.sleep(2)
stdin.write('undo shutdown\n')
stdin.flush()
time.sleep(5)
return True
finally:
ssh.close()
# 主程序
if __name__ == '__main__':
router_ip = '1.1.1.1'
username = 'admin'
password = 'password'
if not check_gre_tunnel(router_ip, username, password):
print(f"隧道异常,尝试恢复...")
restart_gre_tunnel(router_ip, username, password)
time.sleep(10)
if check_gre_tunnel(router_ip, username, password):
print("隧道恢复成功")
else:
print("隧道恢复失败,请手动检查")
十、总结
根本解决方案:在防火墙上正确配置GRE协议(IP协议47)和ICMP协议的双向放行策略,并调整会话超时时间。
临时解决方案:调整路由器上的Keepalive参数,延长检测间隔和增加重试次数。
推荐配置:
防火墙:放行GRE协议,会话超时设置为7200秒
路由器:gre keepalive interval 30 retry-times 5
启用日志监控,及时发现隧道故障
如果问题依旧,建议在防火墙和路由器上同时抓包,分析GRE Keepalive报文的实际传输情况。
暂无评论
亲~登录后才可以操作哦!
确定你的邮箱还未认证,请认证邮箱或绑定手机后进行当前操作
举报
×
侵犯我的权益
×
侵犯了我企业的权益
×
抄袭了我的内容
×
原文链接或出处
诽谤我
×
对根叔社区有害的内容
×
不规范转载
×
举报说明
暂无评论