配置拓扑
这里使用ens33接口地址来建立隧道,使用ens37接口地址做隧道接口标识,使用ens38接口地址来模拟私网业务地址。实际场景中,用于建立隧道的地址是公网地址,而业务地址是私网地址,GRE隧道使得私网地址空间不会暴露于公网。
具体配置
1. node02
开启路由转发,加载GRE协议模块。
# 开启ipv4路由转发
echo 1 > /proc/sys/net/ipv4/ip_forward
# 查看GRE内核模块信息
modinfo ip_gre
# 查看GRE内核模块是否安装
lsmod | grep ip_gre
# 加载GRE内核模块
modprobe ip_gre
modprobe --first-time ip_gre
创建隧道虚接口tunnel2并配置隧道接口ip(隧道标识)。
# 配置GRE隧道的source和destination ip(外部,公网地址)
ip tunnel add tunnel2 mode gre local 192.168.91.129 remote 192.168.91.130 ttl 255 dev ens33
# 配置GRE tunnel接口的隧道标识(在数通设备上可以通过ip unnumber借用其他接口的primary ip)
ip addr add 172.16.18.10 dev tunnel2 peer