搭建自配置可用的IPv6网络

为了能有IPv6链接,在重新配置了系统之后又把以前做过的 Radvd 和 使用 HE 提供的 Tunnel Broker 的服务又配置了一遍:

首先要有一个 Hurrican Electric 的 Tunnel Broker 帐号,注册很方便,过程略。

内核要开启Tunnel支持,可见链接中的Wiki。

自用的配置脚本:

由于我用的ADSL拨号网络IP总是变化,所以不能用固定的文件去配置,需要一枚脚本:

https://github.com/ryncsn/he-ipv6-init-script/raw/master/hev6.sh

放到/usr/local/sbin/

wget https://raw.githubusercontent.com/ryncsn/he-ipv6-init-script/master/hev6.sh -O /usr/local/sbin/hev6-init

vim /usr/local/sbin/hev6-init

按照 Tunnel Broker 帐号和申请的 Tunnel 信息配置开头的各种变量,INTERFACE是 Tunnel 经过的的 Interface,需要能接受服务器发来的 6in4 (Protocal 41) 包,且有独立公网地址。ROUTE_INTERFACE是本地需要提供IPv6网络的接口,对我来说就是内网。

 

配置服务:

要让服务自启动。之后写一个服务资源文件:

Gentoo中:

vim /etc/init.d/hev6-init
#!/sbin/runscript
# Copyright 1999-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id$

description="Hurrican Electric Tunnel Broker"

command="/usr/local/sbin/hev6-init"

log_file="/var/log/hev6"
depend() {
        need net
        use logger dns
}

start() {
        ebegin "Starting DDNS on ${IFACE}"
        start-stop-daemon --start --background \
        --stdout $log_file --stderr $log_file \
        --exec $command
}

stop() {
        ebegin "Stopping HE v6 tunnel"
        $command clear
        eend $?
}

启用,启动服务。

rc-update add hev6-init default

service hev6-init start

Systemd版:

vim /etc/systemd/system/hev6.service
[Unit]
Description=Hurrican Electric IPv6 Tunnel Broker
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
TimeoutSec=0
PIDFile=/run/hev6.pid
ExecStart=/usr/local/sbin/hev6-init
ExecStop=/usr/local/sbin/hev6-init clear
Restart=on-failure


[Install]
WantedBy=multi-user.target
systemctl enable hev6

systemctl start hev6

服务启动之后通过ping6 ipv6.google.com测试,无问题。

 

配置Radvd:

配置radvd,在要提供IPv6服务的接口上开启路由通知:

emerge radvd

vim /etc/radvd.conf

参考配置,酌情修改网段信息等:

interface eth0
{       
        AdvSendAdvert on;
        
        MinRtrAdvInterval 3;
        MaxRtrAdvInterval 10;
        
        AdvDefaultPreference low;               
        AdvHomeAgentFlag off;
        
        prefix 2001:470:ffff:ffff::/64
        {       
                AdvOnLink on;
                AdvAutonomous on;                                                                               
                AdvRouterAddr on;                                                                                       
        };
};

之后配置服务开机自起:

service radvd start

rc-update add radvd default

Gentoo中启动radvd 服务会自动开启ipv6 forwarding。

我的另一机器是 Centos 7,配置时需要手动在/etc/sysctl.con中加入:

net.ipv6.conf.default.forwarding=1
net.ipv6.conf.all.forwarding=1

 

配置ip6tables:

增加TUNNEL Chain,配置类似如下:

-A FORWARD -j TUNNEL

:TUNNEL - [0:0]
-A TUNNEL -s 2001:470:ffff:ffff::/64 -j ACCEPT
-A TUNNEL -d 2001:470:ffff:ffff::/64 -j ACCEPT
-A TUNNEL -s fe80::/10 -j ACCEPT
-A TUNNEL -d fe80::/10 -j ACCEPT
-A TUNNEL -j RETURN

之后在网络上接入其他设备,ping6 ipv6.google.com,测试无问题即可用。

 

相关链接:

Tunnel broker:

http://tunnelbroker.net/

Gentoo Wiki:

https://wiki.gentoo.org/wiki/IPv6_router_guide#Using_radvd

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.