腾讯轻量云服务器ubuntu开通he-ipv6地址

腾讯轻量云服务器ubuntu开通he-ipv6地址

一、到he.net上获取ipv6隧道

https://tunnelbroker.net/

先到开通IPV6地址,Client IPv4 Address处应该是你的公网出口IP

image-20210607101106252

二、在轻量云ubuntu上配置网卡文件

开通隧道后在Example Configurations处选择debian/ubuntu获取网卡配置文件,这个配合在实际使用时要做一个变动

image-20210607101320462

1
2
3
4
5
6
7
8
9
10
11
# 这个是配置文件说明
# /etc/network/interfaces
# 在文件尾部追加
auto he-ipv6
iface he-ipv6 inet6 v4tunnel
address 【客户端IPV6地址】
netmask 【IPV6隧道掩码】
endpoint 【服务器IPV4地址】
local 【局域网IP地址】
ttl 255
gateway 【服务器IPV6地址】

ubuntu安装网卡配配置依赖包,否则就不会生效

1
apt install ifupdown resolvconf

查看文件/etc/network/interfaces,配置文件放在/etc/network/interfaces.d/就会生效

1
2
3
4
5
# This file describes the network interfaces available on your system

# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

新建配置文件/etc/network/interfaces.d/he_ipv6.conf,将官网的配置文件粘贴上,注意local应该是你主网卡的内网ip

image-20210607102058055

local ip获取直接输入命令ip addr就可以获取

image-20210607102356662

配置完后就直接用命令启用网卡

1
2
3
4
# 启用网卡
ifup he-ipv6
# 禁用该网卡
ifdown he-ipv6

三、设置路由转发和配置防火墙规则

切换到root用户并配置路由转发规则

1
2
3
4
# 切换root
sudo -s
# 配置转发规则,注意 x:x:x::/64应替换为代码中address中的地址去除最后一位
ip6tables -t nat -A POSTROUTING -o he-ipv6 -s x:x:x::/64 -j MASQUERADE

启用IPV6转发

1
2
3
4
5
6
# 主网卡
echo 1 > /proc/sys/net/ipv6/conf/eth0/forwarding
# he-ipv6网卡
echo 1 > /proc/sys/net/ipv6/conf/he-ipv6/forwarding
# 所有网卡默认启用
echo 1 > /proc/sys/net/ipv6/conf/all/forwarding

使用下列命令查看防火墙规则

1
2
3
4
# 查看规则
ip6tables -t nat -L -n
# 保存规则
ip6tables-save

四、测试最终实验效果

接下来直接重启主机测试效果

可以ping测试一下,linux是用ping6来测试的

1
2
3
# 阿里dns 2400:3200::1      2400:3200:baba::1
# 谷歌dns 2001:4860:4860::8888 2001:4860:4860::8844
ping6 www.google.com

开启IPV6后,电脑访问ipv6的web网页方式如下

1
2
https://[2001:470:1800:47a::2000]/index.html
https://[2001:470:1800:47a::2000]/