搭建 GRE 隧道

出口端

text
1
2
3
4
5
6
7
ip tunnel add gre-tunnel mode gre remote $client_ipv4 ttl 128
ip link set gre-tunnel up
ip addr add 2402:9e80:2b:b::1/64 dev gre-tunnel

sysctl net.ipv6.conf.all.forwarding=1
sysctl net.ipv6.conf.all.proxy_ndp=1

$client_ipv4为入口端IP地址

入口端

text
1
2
3
4
5
ip tunnel add gre-tunnel mode gre remote $server_ipv4 ttl 128
ip link set gre-tunnel up
ip addr add 2402:9e80:2b:b::2/64 dev gre-tunnel
ip -6 route add default dev gre-tunnel # 会转发所有IPv6流量

$server_ipv4为出口端IP地址

测试

可以通过互ping来测试隧道搭建情况

维护

text
1
2
3
4
5
6
7
# 删除
ip link set gre-tunnel down
ip tunnel del gre-tunnel

# 修改IP
ip tunnel change gre-tunnel remote $new_client_ipv4