2 .\" Copyright (c) 2000 Robert N. M. Watson
3 .\" All rights reserved.
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
14 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 .\" ----------------------------------------------------------------------------
28 .\" "THE BEER-WARE LICENSE" (Revision 42):
29 .\" <phk@FreeBSD.ORG> wrote this file. As long as you retain this notice you
30 .\" can do whatever you want with this stuff. If we meet some day, and you think
31 .\" this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
32 .\" ----------------------------------------------------------------------------
34 .\" $FreeBSD: src/usr.sbin/jail/jail.8,v 1.13.2.15 2003/05/08 13:04:24 maxim Exp $
35 .\" $DragonFly: src/usr.sbin/jail/jail.8,v 1.11 2008/05/02 02:05:07 swildner Exp $
42 .Nd "imprison process and its descendants"
46 .Op Fl l u Ar username | Fl U Ar username
47 .Ar path hostname ip-list command ...
51 command imprisons a process and all future descendants.
53 The options are as follows:
54 .Bl -tag -width ".Fl u Ar username"
56 Output the jail identifier of the newly created jail.
58 Run program in the clean environment.
59 The environment is discarded except for
60 .Ev HOME , SHELL , TERM
66 are set to the target login's default values.
68 is set to the target login.
70 is imported from the current environment.
71 The environment variables from the login class capability database for the
72 target login are also set.
74 The user name as whom the
78 The user name from jailed environment as whom the
82 Directory which is to be the root of the prison.
84 Hostname of the prison.
86 Comma separated IP list assigned to the prison.
88 Pathname of the program which is to be executed.
93 man page for further details.
95 .Ss "Setting up a Jail Directory Tree"
96 This example shows how to setup a jail directory tree
99 distribution, provided that you built world before already:
104 make installworld DESTDIR=$D
106 make distribution DESTDIR=$D
108 ln -sf dev/null boot/kernel
111 In many cases this example would put far more stuff in the jail than is needed.
112 In the other extreme case a jail might contain only one single file:
113 the executable to be run in the jail.
115 We recommend experimentation and caution that it is a lot easier to
118 jail and remove things until it stops working,
119 than it is to start with a
121 jail and add things until it works.
122 .Ss "Setting Up a Jail"
123 Do what was described in
124 .Sx "Setting Up a Jail Directory Tree"
125 to build the jail directory tree.
126 For the sake of this example, we will
127 assume you built it in
128 .Pa /data/jail/192.168.11.100 ,
129 named for the external jail IP address.
130 Substitute below as needed with your
131 own directory, IP addresses, and hostname.
133 First, you will want to set up your real system's environment to be
135 For consistency, we will refer to the parent box as the
136 .Dq "host environment" ,
137 and to the jailed virtual machine as the
138 .Dq "jail environment" .
139 Because jail is implemented using IP aliases, one of the first things to do
140 is to disable IP services on the host system that listen on all local
141 IP addresses for a service.
144 to only listen on the
145 appropriate IP address, and so forth.
148 in the host environment:
149 .Bd -literal -offset indent
151 inetd_flags="-wW -a 192.168.11.23"
156 is the native IP address for the host system, in this example.
157 Daemons that run out of
159 can be easily set to use only the specified host IP address.
161 will need to be manually configured\(emfor some this is possible through
164 flags entries, for others it is not possible without munging
165 the per-application configuration files, or even recompiling.
167 applications that cannot specify the IP they run on, it is better to disable
170 A number of daemons ship with the base system that may have problems when
171 run from outside of a jail in a jail-centric environment.
181 can be configured to listen only on a specific
182 IP using their configuration files, in most cases it is easier to simply
183 run the daemons in jails only, and not in the host environment.
185 NFS from the host environment may also cause confusion, and cannot be
186 easily reconfigured to use only specific IPs, as some NFS services are
187 hosted directly from the kernel.
188 Any third party network software running
189 in the host environment should also be checked and configured so that it
190 does not bind all IP addresses, which would result in those services also
191 appearing to be offered by the jail environments.
194 these daemons have been disabled or fixed in the host environment, it is
195 best to reboot so that all daemons are in a known state, to reduce the
196 potential for confusion later (such as finding that when you send mail
197 to a jail, and its sendmail is down, the mail is delivered to the host,
200 Start any jails for the first time without configuring the network
201 interface so that you can clean it up a little and set up accounts.
203 with any machine (virtual or not) you will need to set a root password, time
208 .Dl "jail /data/jail/192.168.11.100 testhostname 127.0.0.1,192.168.11.100 /bin/sh"
210 You will end up with a shell prompt, assuming no errors, within the jail.
211 You can now do the post-install configuration to set various configuration
216 .Bl -bullet -offset indent -compact
218 Disable the port mapper
220 .Li rpcbind_enable="NO" )
228 Disable interface configuration to quell startup warnings about
230 .Pq Li network_interfaces=""
234 so that name resolution within the jail will work correctly
236 Set a root password, probably different from the real host system
238 Set the timezone with
241 Add accounts for users in the jail environment
243 Install any packages that you think the environment requires
246 You may also want to perform any package-specific configuration (web servers,
247 SSH servers, etc), patch up
249 so it logs as you would like, etc.
251 Exit from the shell, and the jail will be shut down.
252 .Ss "Starting the Jail"
253 You are now ready to restart the jail and bring up the environment with
254 all of its daemons and other programs.
255 To do this, first bring up the
256 virtual host interface, and then start the jail's
258 script from within the jail.
260 NOTE: If you plan to allow untrusted users to have root access inside the
261 jail, you may wish to consider setting the
262 .Va jail.set_hostname_allowed
264 Please see the management reasons why this is a good idea.
265 If you do decide to set this variable,
266 it must be set before starting any jails, and once each boot.
267 .Bd -literal -offset indent
268 ifconfig ed0 inet alias 192.168.11.100/32
269 mount -t procfs proc /data/jail/192.168.11.100/proc
270 jail /data/jail/192.168.11.100 testhostname 127.0.0.1,192.168.11.100 \\
274 A few warnings will be produced, because most
276 configuration variables cannot be set from within the jail, as they are
277 global across all jails and the host environment.
278 However, it should all
280 You should be able to see
283 and other processes running within the jail using
287 flag appearing beside jailed processes.
288 You should also be able to
290 to the hostname or IP address of the jailed environment, and log
291 in using the accounts you created previously.
292 .Ss "Managing the Jail"
293 Normal machine shutdown commands, such as
298 cannot be used successfully within the jail.
299 To kill all processes in a
300 jail, you may log into the jail and, as root, use one of the following
301 commands, depending on what you want to accomplish:
302 .Bd -literal -offset indent
311 signals to all processes in the jail from within the jail.
313 the intended use of the jail, you may also want to run
315 from within the jail.
316 Currently there is no way to insert new processes
317 into a jail, so you must first log into the jail before performing these
320 To kill processes from outside the jail, you must individually identify the
321 PID of each process to be killed.
323 .Pa /proc/ Ns Ar pid Ns Pa /status
324 file contains, as its last field, the hostname of the jail in which the
327 to indicate that the process is not running within a jail.
332 flag for processes in a jail.
333 However, the hostname for a jail may be, by
334 default, modified from within the jail, so the
336 status entry is unreliable by default.
337 To disable the setting of the hostname
338 from within a jail, set the
339 .Va jail.set_hostname_allowed
340 sysctl variable in the host environment to 0, which will affect all jails.
341 You can have this sysctl set on each boot using
343 Just add the following line to
344 .Pa /etc/sysctl.conf :
346 .Dl jail.set_hostname_allowed=0
348 In a future version of
350 the mechanisms for managing jails may be
352 .Ss "Sysctl MIB Entries"
353 Certain aspects of the jail containments environment may be modified from
354 the host environment using
357 Currently, these variables affect all jails on the system, although in
358 the future this functionality may be finer grained.
360 .It Va jail.set_hostname_allowed
361 This MIB entry determines whether or not processes within a jail are
362 allowed to change their hostname via
366 In the current jail implementation, the ability to set the hostname from
367 within the jail can impact management tools relying on the accuracy of jail
370 As such, this should be disabled in environments where privileged access to
371 jails is given out to untrusted parties.
372 .It Va jail.socket_unixiproute_only
373 The jail functionality binds IPv4 and IPv6 addresses to each jail, and limits
374 access to other network addresses in the IPv4 and IPv6 space that may be available
375 in the host environment.
376 However, jail is not currently able to limit access to other network
377 protocol stacks that have not had jail functionality added to them.
378 As such, by default, processes within jails may only access protocols
379 in the following domains:
380 .Dv PF_LOCAL , PF_INET , PF_INET6 ,
383 permitting them access to
386 IPv4 and IPv6 addresses, and routing sockets.
387 To enable access to other domains, this MIB variable may be set to
389 .It Va jail.sysvipc_allowed
390 This MIB entry determines whether or not processes within a jail have access
391 to System V IPC primitives.
392 In the current jail implementation, System V primitives share a single
393 namespace across the host and jail environments, meaning that processes
394 within a jail would be able to communicate with (and potentially interfere
395 with) processes outside of the jail, and in other jails.
396 As such, this functionality is disabled by default, but can be enabled
397 by setting this MIB entry to 1.
424 Support for multiple IPs and IPv6 appeared in
429 The jail feature was written by
430 .An Poul-Henning Kamp
432 .Pa http://www.rndassociates.com/
433 who contributed it to
437 wrote the extended documentation, found a few bugs, added
438 a few new features, and cleaned up the userland jail environment.
440 .An Victor Balada Diaz
441 wrote the support for multiple IPs and IPv6. Multiple IPs support
442 is based on work done by
443 .An Pawel Jakub Dawidek .
445 Jail currently lacks strong management functionality, such as the ability
446 to deliver signals to all processes in a jail, and to allow access to
447 specific jail information via
451 Similarly, it might be a good idea to add an
452 address alias flag such that daemons listening on all IPs
454 will not bind on that address, which would facilitate building a safe
455 host environment such that host daemons do not impose on services offered
457 Currently, the simplist answer is to minimize services
458 offered on the host, possibly limiting it to services offered from
460 which is easily configurable.