global private
BOX1 a.b.c.d 192.168.0.1/24
BOX2 e.f.g.h 192.168.1.1/24
このBOX1とBOX2の間に gif interfaceでトンネルを設置します。
IPSecを利用するにはBOX1とBOX2の kernel の config で
options IPSEC #IP security options IPSEC_ESP #IP security (crypto; define w/ IPSEC) options IPSEC_DEBUG #debug for IP securityと
pseudo-device gifを設定し、recompileします。
kernel内の Security Policy Database (SPD) として知られるテーブルを作成する
setkey(8) コマンドの動作を設定します。
最初はracoonを使用せず、鍵を手動で設定します。
########################################################
# ESP tunnel from a.b.c.d to e.f.g.h
# 192.168.0.1 192.168.1.1
#
flush;
spdflush;
add a.b.c.d e.f.g.h esp 9991 -E simple "258mojiInainoMojiretsu1"
add e.f.g.h a.b.c.d esp 9992 -E simple "258mojiInainoMojiretsu2"
# src dst protocol spi algorithm
# 暗号化 256以上の -E 暗号化のアルゴリズム "key"
# するので 数字 des-cbc 64bit = 8byte
# esp 3des-cbc 192 = 24
# simple 0-2048 = 0-256
# blowfish-cbc 40-448 = 5-56
# cast128-cbc 40-128 = 5-16
# des-deriv 64 = 8
# 3des-deriv 192 = 24
# rijndael-cbc 128/192/256=16/24/32
#
spdadd 192.168.0.0/24 192.168.1.0/24 any
-P out ipsec esp/tunnel/a.b.c.d-e.f.g.h/require;
spdadd 192.168.1.0/24 192.168.0.0/24 any
-P in ipsec esp/tunnel/e.f.g.h-a.b.c.d/require;
########################################################
|
########################################################
# ESP tunnel from e.f.g.h to a.b.c.d
# 192.168.1.1 192.168.0.1
#
flush;
spdflush;
add a.b.c.d e.f.g.h esp 9991 -E simple "258mojiInainoMojiretsu1"
add e.f.g.h a.b.c.d esp 9992 -E simple "258mojiInainoMojiretsu2"
# src dst protocol spi algorithm
spdadd 192.168.1.0/24 192.168.0.0/24 any
-P out ipsec esp/tunnel/e.f.g.h-a.b.c.d/require;
spdadd 192.168.0.0/24 192.168.1.0/24 any
-P in ipsec esp/tunnel/a.b.c.d-e.f.g.h/require;
########################################################
|
# setkey -DP
192.168.0.0/24[any] 192.168.1.0/24[any] any
in ipsec
esp/tunnel/a.b.c.d-e.f.g.h/require
spid=10 seq=1 pid=6583
refcnt=1
192.168.1.0/24[any] 192.168.0.0/24[any] any
out ipsec
esp/tunnel/e.f.g.h-a.b.c.d/require
spid=9 seq=0 pid=6583
refcnt=1
# setkey -D
e.f.g.h a.b.c.d
esp mode=any spi=9992(0x00002708) reqid=0(0x00000000)
E: null 7473746f 6d616b69 6f6b61
replay=0 flags=0x00000040 state=mature seq=1 pid=6584
created: Feb 2 08:49:09 2002 current: Feb 2 08:55:34 2002
diff: 385(s) hard: 0(s) soft: 0(s)
last: Feb 2 08:49:24 2002 hard: 0(s) soft: 0(s)
current: 348(bytes) hard: 0(bytes) soft: 0(bytes)
allocated: 3 hard: 0 soft: 0
refcnt=2
a.b.c.d e.f.g.h
esp mode=any spi=9991(0x00002707) reqid=0(0x00000000)
E: null 6d616b69 6f6b6174 6f7473
replay=0 flags=0x00000040 state=mature seq=0 pid=6584
created: Feb 2 08:49:09 2002 current: Feb 2 08:55:34 2002
diff: 385(s) hard: 0(s) soft: 0(s)
last: Feb 2 08:49:24 2002 hard: 0(s) soft: 0(s)
current: 252(bytes) hard: 0(bytes) soft: 0(bytes)
allocated: 3 hard: 0 soft: 0
refcnt=1
|
まず ifconfig で tunnel を作成。その中に経路を設定します。
# ifconfig gif0 create tunnel a.b.c.d e.f.g.h # ifconfig gif0 192.168.0.1 192.168.1.1 netmask 255.255.255.255 # route add 192.168.1.0/24 192.168.1.1 |
# ifconfig gif0 gif0: flags=8051 |
/etc/rc.conf に以下を追加します。
ipsec_enable="YES" ipsec_file="/etc/ipsec.conf" gif_interfaces="gif0" gifconfig_gif0="a.b.c.d e.f.g.h" network_interfaces="lo0 vr0 dc0 gif0" # gif0 を追加 ifconfig_gif0="192.168.0.1 192.168.1.1 netmask 255.255.255.255" static_routes="vpn" route_vpn="-net 192.168.1.0/24 192.168.1.1" |
# # cd /usr/ports/security/racoon # make install |
PORTVERSION= 20011215a MASTER_SITES= ftp://ftp.kame.net/pub/kame/misc/でした。
racoonを使用する場合、/etc/ipsec.confから
add a.b.c.d e.f.g.h esp 9991 -E simple "258mojiInainoMojiretsu1" add e.f.g.h a.b.c.d esp 9992 -E simple "258mojiInainoMojiretsu2"を取り除きます。
racoonの設定は /usr/local/etc/racoon/racoon.conf で行ないます。
今回は事前共有鍵を用います。
racoon.confはBOX1,BOX2で共通です。
# cd /usr/local/etc/racoon # vi racoon.conf
path include "/usr/local/etc/racoon" ;
path pre_shared_key "/usr/local/etc/racoon/psk.txt" ;
path certificate "/usr/local/etc/cert" ;
#log debug;
log notify;
remote anonymous
{
exchange_mode main, aggressive;
doi ipsec_doi;
situation identity_only;
nonce_size 16;
lifetime time 1 hour; # sec,min,hour
initial_contact on;
support_mip6 on;
proposal_check obey; # obey, strict or claim
proposal {
encryption_algorithm 3des;
hash_algorithm sha1;
authentication_method pre_shared_key ;
dh_group 2 ;
}
}
sainfo anonymous
{
pfs_group 2;
lifetime time 1 hour;
encryption_algorithm 3des ;
authentication_algorithm hmac_sha1;
compression_algorithm deflate ;
}
|
共有する鍵を /usr/local/etc/racoon/psk.txt に置きます。
# vi /usr/local/etc/racoon/psk.txt
# BOX1では e.f.g.h hogehoge # # BOX2では a.b.c.d hogehoge |
# chmod 400 /usr/local/etc/racoon/psk.txt