Saturday, March 31, 2012

Install and configure Jail - FreeBSD



  • Once FreeBSD is installed start making the needed directories.


#mkdir /jail/master
#mkdir /jail/master/usr/
#cp -R /bin/ /jail/master/bin
#cp -R /etc/ /jail/master/etc
#cp -R /lib/ /jail/master/lib
#cp -R /libexec/ /jail/master/libexec
#cp -R /sbin/ /jail/master/sbin
#cp -R /usr/share /jail/master/usr/share
#cp -R /usr/bin /jail/master/usr/bin
#cp -R /usr/sbin /jail/master/usr/sbin
#cp -R /usr/lib /jail/master/usr/lib


  • Once you have all the need directories chroot - into /jail/master and run sysinstall


#chroot /jail/master /bin/csh
#/usr/sbin/sysinstall


  • Once you are in choose


->Configure
->Distributions
->base
->(use ftp for media source)
exit sysinstall



  • When you have the whole base distributions exit the chroot


# exit or Ctrl+D
• Sample apps created for jails : ssh and dns
#cp -R /jail/master/ /usr/jail/ssh
#cp -R /jail/master/ /usr/jail/dns


  • After the directories are made edit /etc/rc.conf


#vi /etc/rc.conf


  •  Add the following lines


ifconfig_em0_alias0="192.168.0.30 netmask 255.255.255.0" #Add alias for your network
ifconfig_em0_alias1="192.168.0.31 netmask 255.255.255.0" #Add alias for your network

jail_enable="YES" # Set to NO to disable starting of any jails
jail_list="ssh dns webserver" # Space separated list of names of jails
jail_set_hostname_allow="NO" # Allow root user in a jail to change its hostname
jail_socket_unixiproute_only="YES" # Route only TCP/IP within a jail

 
jail_ssh_rootdir="/jail/ssh"
jail_ssh_hostname="ssh.local"
jail_ssh_ip="192.168.0.30, fd0a:42b1:6521:63b6::4"
jail_ssh_exec_start="/bin/sh /etc/rc"
jail_ssh_devfs_enable="YES"
jail_ssh_devfs_ruleset="devfsrules_jail"

jail_dns_rootdir="/jail/dns"
jail_dns_hostname="dns.local"
jail_dns_ip="192.168.0.31, fd0a:42b1:6521:63b6::5"
jail_dns_exec_start="/bin/sh /etc/rc"
jail_dns_devfs_enable="YES"
jail_dns_devfs_ruleset="devfsrules_jail"


  •  Once the file is saved start the jails and setup the nic


#sh /etc/rc

0 comments:

Post a Comment