通过隧道为老版阿里云共享型ECS提供IPv6服务

本文发布于 ,内容可能和实际情况存在出入。如果文章存在错误欢迎指正,我会根据情况对文章进行修改或做隐藏处理

因为我阿里云的学生机到目前为止还没能开通IPv6功能,所以决定新购一台最便宜的t6实例
在两台实例之间通过VPC内网建立GRE隧道并配置NAT6为其提供IPv6

1、在新机器上配置IPv6

这个阿里云已经有相关教程 [https://help.aliyun.com/document_detail/108465.html][1]

2、在新机器上建立GRE隧道(并不局限于GRE,其他隧道也可以)

ip tunnel add gre-tunnel mode gre remote 老机器内网IP ttl 1
ip link set gre-tunnel up
ip addr add fc00::1/64 dev gre-tunnel

3、在老机器上建立GRE隧道

ip tunnel add gre-tunnel mode gre remote 新机器内网IP ttl 1
ip link set gre-tunnel up
ip addr add fc00::2/64 dev gre-tunnel

4、在新机器配置NAT6,转发80和443端口
因为ECS有提供安全组功能所以不在iptables中做过多限制

vi /etc/sysctl.conf
net.ipv6.conf.all.forwarding=1
退出vi
sysctl -p
service ip6tables start
ip6tables -P INPUT ACCEPT
ip6tables -P OUTPUT ACCEPT
ip6tables -P FORWARD ACCEPT
ip6tables -F
ip6tables -t nat -F
ip6tables -t nat -I POSTROUTING -s fc00::2/128 -j MASQUERADE
ip6tables -t nat -I PREROUTING -p tcp -d 新机器公网IPv6 --dport 80 -j DNAT --to-destination fc00::2
ip6tables -t nat -I PREROUTING -p tcp -d 新机器公网IPv6 --dport 443 -j DNAT --to-destination fc00::2

5、老机器上配置默认路由

ip -6 route add default via fc00::1

6、修改安全组
在两端机器上对对方内网IP开放完全访问
在新机器上对需要映射的端口开放所有人访问(授权对象为::/0)
(可选)开放新机器的ICMPv6以便本地PING检测

7、测试效果

8、保存设置
老机器

vi /etc/rc.local
ip tunnel add gre-tunnel mode gre remote 新机器内网IP ttl 1
ip link set gre-tunnel up
ip addr add fc00::2/64 dev gre-tunnel
ip -6 route add default via fc00::1
退出vi
chmod +x /etc/rc.d/rc.local

新机器

service ip6tables save
chkconfig ip6tables on
vi /etc/rc.local
ip tunnel add gre-tunnel mode gre remote 老机器内网IP ttl 1
ip link set gre-tunnel up
ip addr add fc00::1/64 dev gre-tunnel
退出vi
chmod +x /etc/rc.d/rc.local

标签: gre, 阿里云, ipv6, tunnel, ip6tables

已有 2 条评论

  1. 催更,催更。

添加新评论