💗心爱的💗-小沨

  • 首页
  • 网盘
  • 图床
  • 赞助
  • 关于本站
私人小天地
谈天说地,学习笔记
  1. 首页
  2. Linux系统
  3. 正文

linux架设gre tunnel/隧道

2019年3月14日 5864点热度 0人点赞 0条评论

GRE隧道是IP-over-IP隧道,可以封装IPv4/IPv6和单播/多播流量。要在Linux上创建GRE隧道,需要ip_gre内核模块。

先查看系统p_gre模块

sudo modprobe ip_gre
lsmod | grep gre

在2个不同VPS或者服务器直接架设GRE隧道链接,例如VPS1,VPS2
VPS1: 172.168.1.2
VPS2: 172.168.1.3

在VPS1上是操作,gre1看你自己喜欢用什么都可以,但是有的机器gre0默认已经使用了

sudo ip tunnel add gre1 mode gre remote 172.168.1.3 local 172.168.1.2 ttl 255
sudo ip link set gre1 up
sudo ip addr add 10.10.10.1/24 peer 10.10.10.2/24 dev gre1
sudo ip addr add 200a::1/64 peer 200a::2/64 dev gre1

这个是在VPS1创建一个名为gre1的GRE类型隧道,并将其远程地址设置为172.168.1.3。隧道数据包将来自192.168.1.2(本地IP地址),其TTL字段将设置为255.隧道设备的IP地址为10.10.10.1,网络掩码为255.255.255.0。

现在验证GRE隧道的路由是否已正确设置:

ip route show

然后在VPS2重复上面的操作

VPS2操作

sudo ip tunnel add gre1 mode gre remote 172.168.1.2 local 172.168.1.3 ttl 255
sudo ip link set gre1 up
sudo ip addr add 10.10.10.2/24 peer 10.10.10.1/24 dev gre1
sudo ip addr add 200a::2/64 peer 200a::1/64 dev gre1

然后VPS1和VPS2建立GRE隧道了,现在在VPS1可以测试一下:

root@VPS1 ~ # ping 10.10.10.2
PING 10.10.10.2 (10.10.10.2) 56(84) bytes of data.
64 bytes from 10.10.10.2: icmp_seq=1 ttl=64 time=120 ms
64 bytes from 10.10.10.2: icmp_seq=2 ttl=64 time=120 ms
64 bytes from 10.10.10.2: icmp_seq=3 ttl=64 time=119 ms

如果要关掉卸载GRE

sudo ip link set gre0 down
sudo ip tunnel del gre0

建静态路由,在VPS1上操作,1.1.1.0/24通过GRE隧道路由。请注意,网关地址10.10.10.2是分配给GRE隧道远程端点的IP地址(VPS2)。

sudo ip route add 1.1.1.0/24 via 10.10.10.2/24 dev gre1

link:http://ask.xmodulo.com/create-gre-tunnel-linux.html

标签: gre linux tunnel 隧道
最后更新:2019年8月17日

mikj

这个人很懒,什么都没留下

打赏 点赞
< 上一篇
下一篇 >

文章评论

您需要 登录 之后才可以评论
站内搜索
联系我
分类
  • AI智能
  • Android
  • Linux系统
  • VPS服务器
  • windows系统
  • wordpress
  • 域名相关
  • 建站分享
  • 教程学习
  • 数据库类
  • 旅行点滴
  • 未分类
  • 网络服务
  • 资源分享
  • 跨境出海
  • 金融投资
友情链接
  • QQPCC
  • 李子博客
  • 麦麦同学
  • 寥寥后花园
  • 夜狐
  • 小沨记事本
  • 天下无鱼
  • 撸羊毛
  • semnew
  • 爱购啦
  • 我的图库
  • vzone
  • 怪鸟博客
  • 光的魔术师
  • 死老鬼
  • 陈否否
  • LINUX DO
  • 轨迹博客
  • 豆博
  • QQTM论坛
  • 朱志瑞
  • 傻子-跸西的blog
  • Shucheng Li
  • 我喔喔喔
  • 娃娃博客

COPYRIGHT © 2025 Xinai.De. ALL RIGHTS RESERVED.@ 网站运行:@ 服务器运行状态

Theme Kratos Made By Seaton Jiang