首页 > 技术文章 > CentOS7中GreVPN的配置

smallcoderhujin 2015-05-07 15:52 原文

目前只实现了三层的GRE隧道,但其实二层也可以实现的,但是没有找到很好的方法,待研究

 

环境如下:

host A :  121.207.22.123

host B: 111.2.33.28

1. 在host A上面:

# ip tunnel add gre1 mode gre remote 111.2.33.28 local 121.207.22.123 ttl 255 key 123456
# ip link set gre1 up
# ip addr add 10.10.10.1 peer 10.10.10.2 dev gre1

创建一个GRE类型隧道设备gre0, 并设置对端IP为111.2.33.28。

隧道数据包将被从121.207.22.123也就是本地IP地址发起,其TTL字段被设置为255。

隧道设备分配的IP地址为10.10.10.1,掩码为255.255.255.0。

 

2. 在host B上面:

# ip tunnel add gre1 mode gre remote  121.207.22.123 local 111.2.33.28 ttl 255 key 123456
# ip link set gre1 up
# ip addr add 10.10.10.2 peer 10.10.10.1 dev gre1

 

此时,host A 和 host B 建立起GRE隧道了。

 

3. 添加路由

如果一个路由(例如 B)的后面有很多个子网,那么就需要添加多个路由来实现A对B后面子网的访问

# ip route add 192.168.1.0/24 dev gre1

 

4. 检测连通性

# ping 10.10.10.2

 

5. 撤销GRE隧道

# ip link set gre1 down
# ip tunnel del gre1

 

推荐阅读