FreeBSD6.2Rでjail環境構築中 - hostの環境を整える

やっぱり途中ミスったりするんで、メモ書き。
参考サイトのデッドコピーになるけど、気づいた所を。
参考サイト:http://free-vv.dyndns.org/d/?q=node/406
FreeBSD6.2Rで構築。

Portsからインストールするお

# cd /usr/ports/sysutils/ezjail
# make install clean
# rehash

以上でインストール完了。
ezjailは単なるスクリプトなので、速攻でインストール完了。

cp -p /usr/local/etc/ezjail.conf.sample /usr/local/etc/ezjail.conf 

とりあえず、サンプルのコンフィグファイルをコピーしておきます。
ところで、「サンプルのコンフィグファイルや、デフォルトの設定を/root/default-configとかに取って置くのが行儀いいかなぁ、一緒にインストールログと一緒に。」と思いつつ、いつもやってないm-birdで御座います。

ezjail.confは以下の通り。
参考にさせて貰っているサイトさんとほぼ同じです。はい。

# ezjail.conf - Example file, see ezjail.conf(5)
#
# Note: If you alter some of those variables AFTER creating your first
# jail, you may have to adapt /etc/fstab.* and EZJAIL_PREFIX/etc/ezjail/* by
# hand

# Location of jail root directories
#
# Note: If you have spread your jails to multiple locations, use softlinks 
# to collect them in this directory
ezjail_jaildir=/usr/local/jails

# Location of the tiny skeleton jail template
# ezjail_jailtemplate=${ezjail_jaildir}/newjail

# Location of the huge base jail
ezjail_jailbase=${ezjail_jaildir}/basejail

# Location of your copy of FreeBSD's source tree
# ezjail_sourcetree=/usr/src

# In case you want to provide a copy of ports tree in base jail, set this to
# a cvsroot near you
# ezjail_portscvsroot=:pserver:anoncvs@anoncvs.at.FreeBSD.org:/home/ncvs

# This is where the install sub command defaults to fetch its packages from
# ezjail_ftphost=ftp.freebsd.org

# base jail will provide a soft link from /usr/bin/perl to /usr/local/bin/perl
# to accomodate all scripts using '#!/usr/bin/perl'...
# ezjail_uglyperlhack="YES"

# Default options for newly created jails
#
# Note: Be VERY careful about disabling ezjail_mount_enable. Mounting 
# basejail via nullfs depends on this. You will have to find other
# ways to provide your jail with essential system files
ezjail_mount_enable="YES"
ezjail_devfs_enable="YES"
ezjail_devfs_ruleset="devfsrules_jail"
ezjail_procfs_enable="YES"
ezjail_fdescfs_enable="YES"
ベースシステムを構築する。
# ezjail-admin update -i

-iを付ける事によって、buildworldされずにinstallworldされます。
最近worldを再構築したばかりなら、-iオプションを付けてくだしあ。
そうじゃないんなら、-iを付けずに。

HOST側の環境の設定をするお

次に、ホスト側の設定を。

/etc/rc.confの設定
# vim /etc/rc.conf
inetd_flags="-wW -C 60 -a 192.168.hoge.hoge"
ezjail_enable="YES"
ifconfig_xxx_alias0="inet 192.168.fuga.fuga netmask 255.255.255.255"

192.168.hoge.hogeな部分を、host側のIPアドレスに。
192.168.fuga.fugaな部分を、jail側のIPアドレスに。
ifconfig_xxx_alias0のxxxの部分については、自分のNICの名前を入れてください。
ifconfigできちんと名前を確認した上で、入れてくださいな。

/etc/sysctl.conf
# vim /etc/sysctl.conf
security.jail.allow_raw_sockets=1

raw socketsを使わないんだったら、これ要らない。。。っぽい?

/etc/ssh/sshd_config
# vim /etc/ssh/sshd_config
ListenAddress 192.168.hoge.hoge

ListenAddressの部分を、host環境のIPアドレスを設定して下さい。
デフォルトの設定だとJail側に送られるパケットまで拾ってしまうので、HOST側のIPでListenするように>します。
(今回のjailの設定でも、jailの数だけNICがアドレスを持ちます)

とりあえず、ここまで。
続きはhttp://d.hatena.ne.jp/m-bird/20080118/1202583191