0

自制 Tunnel Broker 服务

 2 years ago
source link: https://www.taterli.com/8012/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

自制 Tunnel Broker 服务

  • TaterLi
  • 2021年7月2日2021年7月2日

很多人都会用HE的隧道服务,但是其实除了HE还有很多其他免费服务,但是更厉害的是自己可以制作一个,这需要你有Routed Prefix,部分VPS会提供,大部分杜甫也提供,如果你是通过BGP宣告自己的IP,那一段就肯定是Routed了.

假定配置如下:

我拥有的地址段 => 2406:840:e030::/48
隧道使用的/64地址块 => 2406:840:e030:ffff::/64
服务器 A(隧道服务器)公网 IPv4 地址:10.0.0.1 隧道内地址 => 2406:840:e030:ffff::1/64
服务器 B(客户端)公网 IPv4 地址:10.0.0.2 隧道内地址 => 2406:840:e030:ffff::2/64
额外的/64地址块(Routed /64):2406:840:e030:fffe::/64

在A服务器执行如下命令打开转发:


#打开 Linux 内核的 IPv6 转发功能
echo "net.ipv6.conf.all.forwarding = 1" >> /etc/sysctl.conf
sysctl -p

然后在A服务器执行以下命令创建网络.

#设置隧道
ip tunnel add tun0 mode sit remote 10.0.0.2 local 10.0.0.1 ttl 255
ip link set tun0 up
#隧道端地址
ip addr add 2406:840:e030:ffff::1/64 dev tun0
#更大的地址块
ip route add 2406:840:e030:fe00::/56 dev tun0

当然也可以写在配置文件里.

auto tun0
 iface tun0 inet6 v4tunnel
  address 2406:840:e030:ffff::1
  netmask 64
  endpoint 10.0.0.2
  local 10.0.0.1
  ttl 255
  mtu 1472

然后在B服务器执行以下命令.

#设置隧道
ip tunnel add tun0 mode sit remote 10.0.0.1 local 10.0.0.2 ttl 255
ip link set tun0 up
#隧道端地址
ip addr add 2406:840:e030:ffff::2/64 dev tun0
ip route add ::/0 dev tun0
ip -f inet6 addr

到现在,服务器B已经可以随便给网卡添加2406:840:e030:ffff::/64这段内地址,但这个是Link Prefix,需要Route Prefix的话用另一段地址.

当然,服务器B也可以做一个配置文件,和服务器端就只多了一个网关配置.

auto tun0
 iface tun0 inet6 v4tunnel
  address 2406:840:e030:ffff::2
  netmask 64
  endpoint 10.0.0.1
  local 10.0.0.2
  ttl 255
  gateway 2406:840:e030:ffff::1
  mtu 1472

写在后面,/48是BGP的最小单位,如果小于/48就无办法通过公网BGP,一段/48可以分割出65536个/64网络,如果分配/56的Routed Prefix是可以支持SLAAC等各种特性的,比如我考虑的就是如下分配方案:

  • 2406:840:e030::/48 => 我自己做宣告和网关用途.
  • 2406:840:e030:100::/56 – 2406:840:e030:fe00::/56 => Route Prefix (共254个)
  • 2406:840:e030:ff00::/64 – 2406:840:e030:ffff::/64 => Link Prefix (共256个,但是其中有2个必然浪费.)

这样我的一段/48就可以给开254条隧道了,而每条隧道的用户又可以挂256个设备.

发表评论 取消回复

您的电子邮箱地址不会被公开。 必填项已用*标注

评论

显示名称 *

电子邮箱地址 *

网站地址


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK