VPS需开启TUN/TAP:
wget http://tb-tun.googlecode.com/files/tb-tun_r18.tar.gz
tar xvf tb-tun_r18.tar.gz
yum install gcc
tar xvf tb-tun_r18.tar.gz
gcc tb_userspace.c -l pthread -o tb_userspace
mv tb_userspace /usr/bin/
setsid tb_userspace he-ipv6 <server-ip> <local-ip> sit > /dev/null
ip link set he-ipv6 up
ip addr add 2001:470::2/64 dev he-ipv6
ip route add ::/0 dev he-ipv6
添加多个IP:
for ip in {1..100}; do ip addr add 2001:470:1f07:26a::$ip/64 dev he-ipv6; done
添加随机IP:
#!/bin/sh
MAXCOUNT=100
count=0
network_v6=2001:470:1f07:26a
rnd_ipv6_block () {
#HEX="tr -dc "[:xdigit:]" < /dev/urandom | head -c 16 | sed 's/..../:&/g'"
HEX="openssl rand -hex 8 | sed 's/..../:&/g'"
ipv6=$network_v6$(eval $HEX);
}
echo "$MAXCOUNT 个IPv6:"
echo "-----------------"
while [ $count -lt $MAXCOUNT ]
do
count=`expr $count + 1`
rnd_ipv6_block
echo $ipv6
ip addr add $ipv6/64 dev he-ipv6
done
PHP生成随机IPV6:
<?php
$prefix = '2001:470:1f07:26a';
$str = substr(md5(rand()), 16);
$addr = $prefix . ':' . implode(':', str_split($str, 4));
echo $addr;