5

使用自己的子网进行6to4 Tunnel规划

 2 years ago
source link: https://www.taterli.com/8051/
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.

使用自己的子网进行6to4 Tunnel规划

  • TaterLi
  • 2021年7月6日2021年7月6日

买了自己一段IPv6 /48之后,总想给自己全部机都配上,实名上网嘛,但是呢,IP要好好规划.

首先有一台广播机,最好流量多一些,把自己IP通过BGP播出去,还要一段属于自己的IP,我的资源如下:

  • 我自己的IPv6:2a0f:9400:770a::/48
  • BGP Router:107.189.6.1

由于IPv4是32位长,如果想不冲突,最佳方法就是把V4带入到自己的IPv6段内,比如我的IPv4是23.94.26.137,拆成16进制是175E1A89,那么我拼到的IP段是2a0f:9400:770a:175e:1a89::/80,虽然小于64,ND是失效了,但是实测主要在BGP Router服务器上做点小动作,问题就解决了,这里不展开说.

PS:如果有一个方法能只占16B并且一定不冲突就更好了.

我写了两个小脚本,用于我自己的IPv6配置.

客户端(InstallClient.sh):

#!/bin/sh

ipv4=$(curl -4 -s ip.sb)
ipv4_prefix=$(printf '%02x' ${ipv4//./ })
ip_prefix=2a0f:9400:770a:${ipv4_prefix:0:4}:${ipv4_prefix:4:8}
if [ $(grep -c "interfaces.d" /etc/network/interfaces) -ne '0' ]; then
    cat >/etc/network/interfaces.d/tun0 <<EOF
auto tun0
 iface tun0 inet6 v4tunnel
  address $ip_prefix:$(openssl rand -hex 2):$(openssl rand -hex 2):$(openssl rand -hex 2)
  netmask 80
  endpoint 107.189.6.1
  local $ipv4
  ttl 255
  gateway $ip_prefix::1
  mtu 1472
EOF
else
    echo "其他方式的系统暂时不考虑支持."
fi
ifdown tun0 > /dev/null 2>&1
ifup tun0 > /dev/null 2>&1
echo '请在服务器上执行:bash InstallTunServer.sh' $ipv4 $ip_prefix

BGP Router(InstallTunServer.sh):

#!/bin/bash
# descr:TaterLi自创,用于配置自己的隧道的快捷工具,服务器部分,根据客户端参数来写.

for i in $(seq 0 10000); do
  if [ ! -f /etc/network/interfaces.d/tun$i ]; then
    cat >/etc/network/interfaces.d/tun$i <<EOF
auto tun$i
 iface tun$i inet6 v4tunnel
  address $2::1
  netmask 80
  endpoint $1
  local 107.189.6.1
  ttl 255
  mtu 1472
EOF
    ifup tun$i
    echo '服务器上连接已创建.'
    exit
  fi
done

当然,服务器上记得开IPv6转发,测试结果.

最后我只需要用curl或者wget套娃一下,这样就每个服务器都有自动V6了,但是这样明显不够智能,如果可以客户端执行,服务器自动添加配置就更好了.


为了做到这一点,我开发一个Python脚本,获取请求过来的机器IP,当然添加一些简单的鉴权或者服务器上坐好端口封堵,以免违规.

自助配IPv6脚本(NAT机不能用,IPv6封禁明文邮件和种子,包括私有协议,接投诉后拉黑/80.):

curl -Lso-  http://x.thekoziolfoundation.com/files/script/GetIPv6.sh | bash

获得的整段/80除了网关,都是你的,可用地址有281万亿4749亿7671万655个,给VPS的每个晶体管编个地址吧.

发表评论 取消回复

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

评论

显示名称 *

电子邮箱地址 *

网站地址


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK