【GRE协议】CentOS配置GRE隧道

北慕城南 提交于 2020-03-07 06:42:17

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

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!