1. 首页
  2. 技术
  3. Linux

【GRE协议】CentOS配置GRE隧道

GRE(Generic Routing Encapsulation),通用路由封装协议,是思科开发的隧道协议。

1、加载GRE内核模块

需要加载ip_gre内核模块,并设置开机自动加载

modprobe ip_gre

设置开机自动加载

echo "/sbin/modprobe ip_gre > /dev/null 2>&1" > /etc/sysconfig/modules/ip_gre.modules && chmod 755 /etc/sysconfig/modules/ip_gre.modules

2、创建ifcfg-tun0网络配置

Host A:192.168.0.10

vi /etc/sysconfig/network-scripts/ifcfg-tun0

复制代码

DEVICE=tun0
BOOTPROTO=none
ONBOOT=no
TYPE=GRE
PEER_OUTER_IPADDR=192.168.1.100
PEER_INNER_IPADDR=192.168.168.2
MY_INNER_IPADDR=192.168.168.1

复制代码

Host B:192.168.1.100

vi /etc/sysconfig/network-scripts/ifcfg-tun0

复制代码

DEVICE=tun0
BOOTPROTO=none
ONBOOT=no
TYPE=GRE
PEER_OUTER_IPADDR=192.168.0.10
PEER_INNER_IPADDR=192.168.168.1
MY_INNER_IPADDR=192.168.168.2

复制代码

3、拉起tun0并检查

Host A、Host B:

ifup tun0

4、测试连接

Host A:

ping 192.168.168.2

Host B:

ping 192.168.168.1

抓包结果如下:

15:59:15.444042 IP 192.168.0.10 > 192.168.1.100: GREv0, length 88: IP 192.168.168.1 > 192.168.168.2: ICMP echo request, id 15083, seq 1379, length 64
15:59:15.444111 IP 192.168.1.100 > 192.168.0.10: GREv0, length 88: IP 192.168.168.2 > 192.168.168.1: ICMP echo reply, id 15083, seq 1379, length 64
15:59:16.446077 IP 192.168.0.10 > 192.168.1.100: GREv0, length 88: IP 192.168.168.1 > 192.168.168.2: ICMP echo request, id 15083, seq 1380, length 64
15:59:16.446156 IP 192.168.1.100 > 192.168.0.10: GREv0, length 88: IP 192.168.168.2 > 192.168.168.1: ICMP echo reply, id 15083, seq 1380, length 64

 

参考资料:

1、https://www.centoshowtos.org/network-and-security/gre-tunnel/

2、https://www.linickx.com/gre-example-for-centosrhel

原创文章,作者:admin,如若转载,请注明出处:https://www.huiyingwu.com/3711/

发表评论

电子邮件地址不会被公开。 必填项已用*标注