デュアルスタック サービスの値段がなかなか下がらないので個人では利用しにくい IPv6 ですが、
気軽に自宅のコンピュータにログインできる事はなかなか便利です。
ログイン以外にも普及すればテレビの録画予約や、
飼い犬、飼い猫の留守番を旅行中も見守れたりといろいろ用途は思いつくのですが・・・
この IPv6 ですが、
実は OCN が `OCN IPv6' という名前で、安価な個人向けサービスを実施しております。
http://www.ocn.ne.jp/ipv6/
今回はこの OCN を Debian GNU/Linux 4.0 (etch) で利用する方法をご紹介致します。
まずは必要なフリーソフトをダウンロードします。
と言っても、apt 一発でインストールできない rp-l2tp だけですけどね。
http://jaist.dl.sourceforge.net/sourceforge/rp-l2tp/rp-l2tp-0.3.tar.gz
こちらは通常のフリーソフト同様に configure スクリプトを実行してから make します。
----------------------------------------------------
mtaneda@whitemax~% tar xzvf rp-l2tp-0.3.tar.gz
mtaneda@whitemax~% cd rp-l2tp-0.3
mtaneda@whitemax~/rp-l2tp-0.3% ./configure
creating cache ./config.cache
中略
creating handlers/Makefile
mtaneda@whitemax~/rp-l2tp-0.3% make
gcc -M -g -I.. -Ilibevent -Wall -Wstrict-prototypes -ansi -pedantic -D_GNU_SOURCE -DVERSION=\"0.3\" -DPREFIX=\"/usr/local\" auth.c debug.c dgram.c main.c md5.c network.c options.c peer.c session.c tunnel.c utils.c > .depend
中略
make[1]: ディレクトリ `/home/mtaneda/rp-l2tp-0.3/handlers' から出ます
mtaneda@whitemax~/rp-l2tp-0.3% su
Password:
root@whitemax/home/mtaneda/rp-l2tp-0.3# make install
----------------------------------------------------
rp-l2tp のインストールが終ったら apt を使って ppp と wide-dhcpv6-client をインストールします。
方法はお馴染の root になって、apt-get install ppp wide-dhcpv6-client を叩くだけですね。
以上ができたら、接続するためのスクリプトを用意しましょう。
スクリプトは下記サイト様を参考にしました。
http://sky.geocities.jp/ocnipv6/ocnipv6-linux.html
--- /etc/l2tp/l2tp.conf ---
global
load-handler "sync-pppd.so"
load-handler "cmd.so"
listen-port 1701
section sync-pppd
lac-pppd-opts " call l2tp"
section peer
peer 60.37.55.232 # <-- OCN IPv6 を申し込んだときに通知されたサーバの IP アドレス
port 1701
lac-handler sync-pppd
lns-handler sync-pppd
hide-avps no
section cmd
---------------------------
--- /etc/ppp/options ---
lock
dump
------------------------
--- /etc/ppp/peers/l2tp ---
user dareka@one.ocn.ne.jp # <-- OCN IPv6 を申し込んだときに通知されたアカウント
ipv6 ,
noip
ipparam "l2tp"
lcp-echo-interval 30
lcp-echo-failure 4
debug
kdebug 1
---------------------------
--- /etc/ppp/chap-secrets ---
dareka@one.ocn.ne.jp * "password" *
-----------------------------
--- /usr/sbin/L2TP-start ---
#!/bin/sh
#
SED=/bin/sed
CONF_PATH="/etc/l2tp"
echo 0 > /tmp/l2tpd.tmp
peer=`$SED -n "/^peer [0-9]*\.[0-9]*\.[0-9]*\.[0-9]*/p" $CONF_PATH/l2tp.conf`
peer_lgth=`expr length "$peer"`
peer=`expr substr "$peer" 6 "$peer_lgth"`
if [ `$SED -n "/./p" /tmp/l2tpd.tmp` = "0" ]; then
l2tpd > /dev/null 2> /dev/null
echo 1 > /tmp/l2tpd.tmp
fi
l2tp-control "start-session $peer" > /dev/null 2> /dev/null
sleep 5
/sbin/route -A inet6 add ::/0 dev ppp0
----------------------------
--- /usr/sbin/L2TP-stop ---
#!/bin/sh
#
/sbin/route -A inet6 del ::/0 dev ppp0
if [ $# = 0 ]; then
l2tp-control exit > /dev/null 2> /dev/null
echo 0 > /tmp/l2tpd.tmp
exit 0
fi
l2tp-control dump-sessions > /tmp/l2tp-tunnel.tmp
TUNNEL=`sed -n "s/Tunnel MyID \([0-9]*\) .*/\1/p" /tmp/l2tp-tunnel.tmp`
echo tunnel: $TUNNEL
sed -n "s/Session LAC MyID \([0-9][0-9]*\) .*/\1/w /tmp/l2tp-sessions.tmp" /tmp/l2tp-tunne
l.tmp
SESSION=`head -n $1 /tmp/l2tp-sessions.tmp | tail -1`
echo session: $SESSION
l2tp-control "stop-session $TUNNEL $SESSION"
rm /tmp/l2tp-tunnel.tmp
rm /tmp/l2tp-sessions.tmp
---------------------------
--- /etc/init.d/ipv6 (/etc/init.d/skeleton がベース) ---
#! /bin/sh
### BEGIN INIT INFO
# Provides: skeleton
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Example initscript
# Description: This file should be used to construct scripts to be
# placed in /etc/init.d.
### END INIT INFO
# Author: Foo Bar
#
# Please remove the "Author" lines above and replace them
# with your own name if you copy and modify this script.
# Do NOT "set -e"
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin
DESC="IPv6"
NAME=ipv6
DAEMON=/usr/sbin/L2TP-start
DAEMON_ARGS=""
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions
#
# Function that starts the daemon/service
#
do_start()
{
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
|| return 1
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
$DAEMON_ARGS \
|| return 2
# Add code here, if necessary, that waits for the process to be ready
# to handle requests from services started subsequently which depend
# on this one. As a last resort, sleep for some time.
}
#
# Function that stops the daemon/service
#
do_stop()
{
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
#start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
#RETVAL="$?"
#[ "$RETVAL" = 2 ] && return 2
# Wait for children to finish too if this is a daemon that forks
# and if the daemon is only ever run from this initscript.
# If the above conditions are not satisfied then add some other code
# that waits for the process to drop all resources that could be
# needed by services started subsequently. A last resort is to
# sleep for some time.
#start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
[ "$?" = 2 ] && return 2
# Many daemons don't delete their pidfiles when they exit.
/usr/sbin/L2TP-stop
rm -f $PIDFILE
return 0
}
#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
#
# If the daemon can reload its configuration without
# restarting (for example, when it is sent a SIGHUP),
# then implement that here.
#
/usr/sbin/L2TP-stop
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
return 0
}
case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
#reload|force-reload)
#
# If do_reload() is not implemented then leave this commented out
# and leave 'force-reload' as an alias for 'restart'.
#
#log_daemon_msg "Reloading $DESC" "$NAME"
#do_reload
#log_end_msg $?
#;;
restart|force-reload)
#
# If the "reload" option is implemented then remove the
# 'force-reload' alias
#
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
*)
#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 3
;;
esac
------------------------
上記までが用意できたら、/etc/wide-dhcpv6/dhcp6c.conf に下記を追記します。
------------------------
interface ppp0 {
send ia-pd 0;
};
id-assoc pd 0{
prefix-interface eth0 {
sla-id 1;
sla-len 0;
};
};
------------------------
ppp0 と eth0 は適当に読みかえてください。
ここでの準備が完了したら、
root で /etc/init.d/ipv6 start を叩くと自動的に OCN IPv6 でトンネルが張られ、
IPv6 による通信が可能になります。
ping6 www.kame.net 等で確認ができたら、
cd /etc/rc2.d
ln -s /etc/init.d/ipv6 S12ipv6
と、起動時にスクリプトを呼ぶ様にすると幸せかもしれませんね。
また、もしこのホストから ra を出したい場合は apt で radvd をインストールして、
/etc/init.d/radvd の OPTIONS から test -x の間に下記を挟むと良いかもしれません。
--------------------------------
my_network=`ifconfig eth0 | sed -e "s/ inet6 addr: //" | awk 'BEGIN {FS=":"} /2001/ {printf(" prefix %s:%s:%s:%s
::/64\n", $1, $2, $3, $4) ;}'`
echo "interface eth0
{
AdvSendAdvert on;
MinRtrAdvInterval 3;
MaxRtrAdvInterval 10;
" > /etc/radvd.conf
echo "$my_network
{
AdvOnLink on;
AdvAutonomous on;
};
};" >> /etc/radvd.conf
--------------------------------
固定プレフィックスでなくても、他のコンピュータに正しい ra を配ってくれるようになります。
コメントする