一、注意

两端环境需要位于不同的vpc内,但是有相同网段,且两端环境不能有相同的IP。

二、网关侧

1、环境(CentOS7):

eth0: 192.168.1.6/24

eth1: 192.168.204.93/24

gre:  172.16.33.2 (不需要提前配置IP)

2、开启 linux 主机路由转发

# echo 1 > /proc/sys/net/ipv4/ip_forward

3、加载 gre 协议模块

# modprobe ip_gre

4、创建隧道

# ip tunnel add tunnel2 mode gre local 192.168.204.93 remote 192.168.204.94 ttl 255 dev eth1

# ip addr add 172.16.33.2 dev tunnel2 peer 172.16.33.1/32

# ip link set dev tunnel2 up

5、添加路由,192.168.1.4是对端主机的IP

ip route add 192.168.1.4/32 dev tunnel2


本端主机侧

环境:

eth0: 192.168.1.2/24

添加指向目的地路由,192.168.1.4是对端主机的IP,192.168.1.6是上面网关侧的IP

ip route add 192.168.1.4/32 via 192.168.1.6 dev eth0

可以尝试ping 192.168.1.4


三、对端

1、环境:

eth0: 192.168.1.7/24

eth1: 192.168.204.94/24

gre:  172.16.33.1 (不需要提前配置IP)

2、开启 linux 主机路由转发

# echo 1 > /proc/sys/net/ipv4/ip_forward

3、加载 gre 协议模块

# modprobe ip_gre

4、创建隧道

# ip tunnel add tunnel2 mode gre local 192.168.204.94 remote 192.168.204.93 ttl 255 dev eth1

# ip addr add 172.16.33.1 dev tunnel2 peer 172.16.33.2/32

# ip link set dev tunnel2 up

5、添加路由

# ip route add 192.168.1.2/32 dev tunnel2


对端主机侧

环境:

eth0: 192.168.1.4/24

添加指向目的地路由

ip route add 192.168.1.2/32 via 192.168.1.7 dev eth0

可以尝试ping 192.168.1.2