xref: /freebsd/usr.sbin/jail/jail.8 (revision 8ced50767933f3e2949456367d4d9a64797daec3)
1.\"
2.\" SPDX-License-Identifier: BSD-2-Clause
3.\"
4.\" Copyright (c) 2000, 2003 Robert N. M. Watson
5.\" Copyright (c) 2008-2012 James Gritton
6.\" All rights reserved.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\"    notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\"    notice, this list of conditions and the following disclaimer in the
15.\"    documentation and/or other materials provided with the distribution.
16.\"
17.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27.\" SUCH DAMAGE.
28.\"
29.Dd November 6, 2025
30.Dt JAIL 8
31.Os
32.Sh NAME
33.Nm jail
34.Nd "manage system jails"
35.Sh SYNOPSIS
36.Ss From Configuration File
37.Nm
38.Op Fl cm
39.Op Fl Cdqv
40.Op Fl f Ar conf_file
41.Op Fl p Ar limit
42.Op Ar jail
43.Nm
44.Op Fl r
45.Op Fl Cqv
46.Op Fl f Ar conf_file
47.Op Fl p Ar limit
48.Op Cm * | Ar jail ...
49.Ss Without Configuration File
50.Nm
51.Op Fl cm
52.Op Fl dhilqv
53.Op Fl J Ar jid_file
54.Op Fl u Ar username
55.Op Fl U Ar username
56.Ar param Ns = Ns Ar value ...
57.Op Cm command Ns = Ns Ar command ...
58.Nm
59.Op Fl rR
60.Op Fl qv
61.Op Cm * | Ar jail ...
62.Ss Show Parameters
63.Nm
64.Op Fl f Ar conf_file
65.Fl e
66.Ar separator
67.Ss Backward Compatibility
68.Nm
69.Op Fl dhilqv
70.Op Fl J Ar jid_file
71.Op Fl u Ar username
72.Op Fl U Ar username
73.Op Fl n Ar jailname
74.Op Fl s Ar securelevel
75.Ar path hostname ip Ns Op Cm \&, Ns Ar ...
76.Ar command ...
77.Sh DESCRIPTION
78The
79.Nm
80utility creates new jails, or modifies or removes existing jails.
81It can also print a list of configured jails and their parameters.
82A jail
83.Pq or Dq prison
84is specified via parameters on the command line, or in the
85.Xr jail.conf 5
86file.
87.Pp
88At least one of the options
89.Fl c ,
90.Fl e ,
91.Fl m
92or
93.Fl r
94must be specified.
95These options are used alone or in combination to describe the operation to
96perform:
97.Bl -tag -width indent
98.It Fl c
99Create a new jail.
100The jail
101.Va jid
102and
103.Va name
104parameters (if specified on the command line)
105must not refer to an existing jail.
106.It Fl e Ar separator
107Exhibit a list of all configured non-wildcard jails and their parameters.
108No jail creation, modification or removal performed if this option is used.
109The
110.Ar separator
111string is used to separate parameters.
112Use
113.Xr jls 8
114utility to list running jails.
115.It Fl m
116Modify an existing jail.
117One of the
118.Va jid
119or
120.Va name
121parameters must exist and refer to an existing jail.
122Some parameters may not be changed on a running jail.
123.It Fl r
124Remove the
125.Ar jail
126specified by jid or name.
127All jailed processes are killed, and all jails that are
128children of this jail are also
129removed.
130.It Fl rc
131Restart an existing jail.
132The jail is first removed and then re-created, as if
133.Dq Nm Fl r
134and
135.Dq Nm Fl c
136were run in succession.
137.It Fl cm
138Create a jail if it does not exist, or modify the jail if it does exist.
139.It Fl mr
140Modify an existing jail.
141The jail may be restarted if necessary to modify parameters than could
142not otherwise be changed.
143.It Fl cmr
144Create a jail if it doesn't exist, or modify (and possibly restart) the
145jail if it does exist.
146.El
147.Pp
148Other available options are:
149.Bl -tag -width indent
150.It Fl C
151Clean up after an already-removed jail, running commands and operations
152that are typically run following jail removal.
153.It Fl f Ar conf_file
154Use configuration file
155.Ar conf_file
156instead of the default
157.Pa /etc/jail.conf .
158.It Fl h
159Resolve the
160.Va host.hostname
161parameter (or
162.Va hostname )
163and add all IP addresses returned by the resolver
164to the list of addresses for this jail.
165This is equivalent to the
166.Va ip_hostname
167parameter.
168.It Fl i
169Output (only) the jail identifier of the newly created jail(s).
170This implies the
171.Fl q
172option.
173.It Fl J Ar jid_file
174Write a
175.Ar jid_file
176file, containing the parameters used to start the jail.
177.It Fl l
178Run commands in a clean environment.
179This is deprecated and is equivalent to the exec.clean parameter.
180.It Fl n Ar jailname
181Set the jail's name.
182This is deprecated and is equivalent to the
183.Va name
184parameter.
185.It Fl p Ar limit
186Limit the number of commands from
187.Va  exec.*
188that can run simultaneously.
189.It Fl q
190Suppress the message printed whenever a jail is created, modified or removed.
191Only error messages will be printed.
192.It Fl R
193A variation of the
194.Fl r
195option that removes an existing jail without using the configuration file.
196No removal-related parameters for this jail will be used \(em the jail will
197simply be removed.
198.It Fl s Ar securelevel
199Set the
200.Va kern.securelevel
201MIB entry to the specified value inside the newly created jail.
202This is deprecated and is equivalent to the
203.Va securelevel
204parameter.
205.It Fl u Ar username
206The user name from host environment as whom jailed commands should run.
207This is deprecated and is equivalent to the
208.Va exec.jail_user
209and
210.Va exec.system_jail_user
211parameters.
212.It Fl U Ar username
213The user name from the jailed environment as whom jailed commands should run.
214This is deprecated and is equivalent to the
215.Va exec.jail_user
216parameter.
217.It Fl v
218Print a message on every operation, such as running commands and
219mounting filesystems.
220.It Fl d
221This is deprecated and is equivalent to the
222.Va allow.dying
223parameter, which is also deprecated.
224It used to allow making changes to a
225.Va dying
226jail.
227Now such jails are always replaced when a new jail is created with the same
228.Va jid
229or
230.Va name .
231.El
232.Pp
233If no arguments are given after the options, the operation (except
234remove) will be performed on all jails specified in the
235.Xr jail.conf 5
236file.
237A single argument of a jail name will operate only on the specified jail.
238The
239.Fl r
240and
241.Fl R
242options can also remove running jails that aren't in the
243.Xr jail.conf 5
244file, specified by name or jid.
245.Pp
246An argument of
247.Dq *
248is a wildcard that will operate on all jails, regardless of whether
249they appear in
250.Xr jail.conf 5 ;
251this is the surest way for
252.Fl r
253to remove all jails.
254If hierarchical jails exist, a partial-matching wildcard definition may
255be specified.
256For example, an argument of
257.Dq foo.*
258would apply to jails with names like
259.Dq foo.bar
260and
261.Dq foo.bar.baz .
262.Pp
263A jail may also be specified via parameters directly on the command line in
264.Dq name=value
265form, ignoring the contents of
266.Xr jail.conf 5 .
267For backward compatibility, the command line may also have four fixed
268parameters, without names:
269.Ar path ,
270.Ar hostname ,
271.Ar ip ,
272and
273.Ar command .
274.Ss Jail Parameters
275Parameters in the
276.Xr jail.conf 5
277file, or on the command line, are generally of the form
278.Dq name=value .
279Some parameters are boolean, and do not have a value but are set by the
280name alone with or without a
281.Dq no
282prefix, e.g.
283.Va persist
284or
285.Va nopersist .
286They can also be given the values
287.Dq true
288and
289.Dq false .
290Other parameters may have more than one value, specified as a
291comma-separated list, or with
292.Dq +=
293in the configuration file (see
294.Xr jail.conf 5
295for details).
296List-based parameters may also be specified multiple times on the command
297line, i.e.,
298.Dq name=value1,value2
299and
300.Dq name=value1 name=value2
301are equivalent for such parameters.
302.Pp
303The
304.Nm
305utility recognizes two classes of parameters.
306There are the true jail
307parameters that are passed to the kernel when the jail is created,
308which can be seen with
309.Xr jls 8 ,
310and can (usually) be changed with
311.Dq Nm Fl m .
312Then there are pseudo-parameters that are only used by
313.Nm
314itself.
315.Pp
316Jails have a set of core parameters, and kernel modules can add their own
317jail parameters.
318The current set of available parameters can be retrieved via
319.Dq Nm sysctl Fl d Va security.jail.param .
320Any parameters not set will be given default values, often based on the
321current environment.
322The core parameters are:
323.Bl -tag -width indent
324.It Va jid
325The jail identifier.
326This will be assigned automatically to a new jail (or can be explicitly
327set), and can be used to identify the jail for later modification, or
328for such commands as
329.Xr jls 8
330or
331.Xr jexec 8 .
332.It Va name
333The jail name.
334This is an arbitrary string that identifies a jail (except it may not
335contain a
336.Sq \&. ) .
337Like the
338.Va jid ,
339it can be passed to later
340.Nm
341commands, or to
342.Xr jls 8
343or
344.Xr jexec 8 .
345If no
346.Va name
347is supplied, a default is assumed that is the same as the
348.Va jid .
349The
350.Va name
351parameter is implied by the
352.Xr jail.conf 5
353file format, and need not be explicitly set when using the configuration
354file.
355.It Va path
356The directory which is to be the root of the jail.
357Any commands run inside the jail, either by
358.Nm
359or from
360.Xr jexec 8 ,
361are run from this directory.
362.It Va ip4.addr
363A list of IPv4 addresses assigned to the jail.
364If this is set, the jail is restricted to using only these addresses.
365Any attempts to use other addresses fail, and attempts to use wildcard
366addresses silently use the jailed address instead.
367For IPv4 the first address given will be used as the source address
368when source address selection on unbound sockets cannot find a better
369match.
370It is only possible to start multiple jails with the same IP address
371if none of the jails has more than this single overlapping IP address
372assigned to itself.
373.It Va ip4.saddrsel
374A boolean option to change the formerly mentioned behaviour and disable
375IPv4 source address selection for the jail in favour of the primary
376IPv4 address of the jail.
377Source address selection is enabled by default for all jails and the
378.Va ip4.nosaddrsel
379setting of a parent jail is not inherited for any child jails.
380.It Va ip4
381Control the availability of IPv4 addresses.
382Possible values are
383.Dq inherit
384to allow unrestricted access to all system addresses,
385.Dq new
386to restrict addresses via
387.Va ip4.addr ,
388and
389.Dq disable
390to stop the jail from using IPv4 entirely.
391Setting the
392.Va ip4.addr
393parameter implies a value of
394.Dq new .
395.It Va ip6.addr , Va ip6.saddrsel , Va ip6
396A set of IPv6 options for the jail, the counterparts to
397.Va ip4.addr ,
398.Va ip4.saddrsel
399and
400.Va ip4
401above.
402.It Va vnet
403Create the jail with its own virtual network stack,
404with its own network interfaces, addresses, routing table, etc.
405The kernel must have been compiled with the
406.Sy VIMAGE option
407for this to be available.
408Possible values are
409.Dq inherit
410to use the system network stack, possibly with restricted IP addresses,
411and
412.Dq new
413to create a new network stack.
414.It Va host.hostname
415The hostname of the jail.
416Other similar parameters are
417.Va host.domainname ,
418.Va host.hostuuid
419and
420.Va host.hostid .
421.It Va host
422Set the origin of hostname and related information.
423Possible values are
424.Dq inherit
425to use the system information and
426.Dq new
427for the jail to use the information from the above fields.
428Setting any of the above fields implies a value of
429.Dq new .
430.It Va securelevel
431The value of the jail's
432.Va kern.securelevel
433sysctl.
434A jail never has a lower securelevel than its parent system, but by
435setting this parameter it may have a higher one.
436If the system securelevel is changed, any jail securelevels will be at
437least as secure.
438.It Va devfs_ruleset
439The number of the devfs ruleset that is enforced for mounting devfs in
440this jail.
441A value of zero (default) means no ruleset is enforced.
442Descendant jails inherit the parent jail's devfs ruleset enforcement.
443Mounting devfs inside a jail is possible only if the
444.Va allow.mount
445and
446.Va allow.mount.devfs
447permissions are effective and
448.Va enforce_statfs
449is set to a value lower than 2.
450Devfs rules and rulesets cannot be viewed or modified from inside a jail.
451.Pp
452NOTE: It is important that only appropriate device nodes in devfs be
453exposed to a jail; access to disk devices in the jail may permit processes
454in the jail to bypass the jail sandboxing by modifying files outside of
455the jail.
456See
457.Xr devfs 8
458for information on how to use devfs rules to limit access to entries
459in the per-jail devfs.
460A simple devfs ruleset for jails is available as ruleset #4 in
461.Pa /etc/defaults/devfs.rules .
462.It Va children.max
463The number of child jails allowed to be created by this jail (or by
464other jails under this jail).
465This limit is zero by default, indicating the jail is not allowed to
466create child jails.
467See the
468.Sx "Hierarchical Jails"
469section for more information.
470.It Va children.cur
471The number of descendants of this jail, including its own child jails
472and any jails created under them.
473.It Va enforce_statfs
474This determines what information processes in a jail are able to get
475about mount points.
476It affects the behaviour of the following syscalls:
477.Xr statfs 2 ,
478.Xr fstatfs 2 ,
479.Xr getfsstat 2 ,
480and
481.Xr fhstatfs 2
482(as well as similar compatibility syscalls).
483When set to 0, all mount points are available without any restrictions.
484When set to 1, only mount points below the jail's chroot directory are
485visible.
486In addition to that, the path to the jail's chroot directory is removed
487from the front of their pathnames.
488When set to 2 (default), above syscalls can operate only on a mount-point
489where the jail's chroot directory is located.
490.It Va persist
491Setting this boolean parameter allows a jail to exist without any
492processes.
493Normally, a command is run as part of jail creation, and then the jail
494is destroyed as its last process exits.
495A new jail must have either the
496.Va persist
497parameter or
498.Va exec.start
499or
500.Va command
501pseudo-parameter set.
502.It Va cpuset.id
503The ID of the cpuset associated with this jail (read-only).
504.It Va dying
505This is true if the jail is in the process of shutting down (read-only).
506.It Va parent
507The
508.Va jid
509of the parent of this jail, or zero if this is a top-level jail
510(read-only).
511.It Va osrelease
512The string for the jail's
513.Va kern.osrelease
514sysctl and uname -r.
515.It Va osreldate
516The number for the jail's
517.Va kern.osreldate
518and uname -K.
519.It Va meta , Va env
520An arbitrary string associated with the jail.
521Its maximum buffer size is controlled by the global
522.Va security.jail.meta_maxbufsize
523sysctl, which can only be adjusted by the non-jailed root user.
524While the
525.Va meta
526is hidden from the jail, the
527.Va env
528is readable through the
529.Va security.jail.env
530sysctl.
531.Pp
532Each buffer can be treated as a set of key=value\\n strings.
533In order to add or replace a specific key the
534.Va meta.keyname=value
535or
536.Va env.keyname=value
537parameter notations must be used.
538While
539.Va meta.keyname=
540or
541.Va env.keyname=
542reset the value to an empty string, the
543.Va meta.keyname
544or
545.Va env.keyname
546notations, without the equal sign, remove the given key.
547Respectively, the same
548.Va meta.keyname
549or
550.Va env.keyname
551notations are used to query a specific key while reading jail parameters
552using such commands as
553.Xr jls 8 .
554Multiple keys can be queried or modified with a single command.
555.It Va allow.*
556Some restrictions of the jail environment may be set on a per-jail
557basis.
558With the exception of
559.Va allow.set_hostname
560and
561.Va allow.reserved_ports ,
562these boolean parameters are off by default.
563.Bl -tag -width indent
564.It Va allow.set_hostname
565The jail's hostname may be changed via
566.Xr hostname 1
567or
568.Xr sethostname 3 .
569.It Va allow.sysvipc
570A process within the jail has access to System V IPC primitives.
571This is deprecated in favor of the per-module parameters (see below).
572When this parameter is set, it is equivalent to setting
573.Va sysvmsg ,
574.Va sysvsem ,
575and
576.Va sysvshm
577all to
578.Dq inherit .
579.It Va allow.raw_sockets
580The jail root is allowed to create raw sockets.
581Setting this parameter allows utilities like
582.Xr ping 8
583and
584.Xr traceroute 8
585to operate inside the jail.
586If this is set, the source IP addresses are enforced to comply
587with the IP address bound to the jail, regardless of whether or not
588the
589.Dv IP_HDRINCL
590flag has been set on the socket.
591Since raw sockets can be used to configure and interact with various
592network subsystems, extra caution should be used where privileged access
593to jails is given out to untrusted parties.
594.It Va allow.chflags
595Normally, privileged users inside a jail are treated as unprivileged by
596.Xr chflags 2 .
597When this parameter is set, such users are treated as privileged, and
598may manipulate system file flags subject to the usual constraints on
599.Va kern.securelevel .
600.It Va allow.mount
601privileged users inside the jail will be able to mount and unmount file
602system types marked as jail-friendly.
603The
604.Xr lsvfs 1
605command can be used to find file system types available for mount from
606within a jail.
607This permission is effective only if
608.Va enforce_statfs
609is set to a value lower than 2.
610.It Va allow.mount.devfs
611privileged users inside the jail will be able to mount and unmount the
612devfs file system.
613This permission is effective only together with
614.Va allow.mount
615and only when
616.Va enforce_statfs
617is set to a value lower than 2.
618The devfs ruleset should be restricted from the default by using the
619.Va devfs_ruleset
620option.
621.It Va allow.quotas
622The jail root may administer quotas on the jail's filesystem(s).
623This includes filesystems that the jail may share with other jails or
624with non-jailed parts of the system.
625.It Va allow.read_msgbuf
626Jailed users may read the kernel message buffer.
627If the
628.Va security.bsd.unprivileged_read_msgbuf
629MIB entry is zero, this will be restricted to the root user.
630.It Va allow.socket_af
631Sockets within a jail are normally restricted to IPv4, IPv6, local
632(UNIX), and route.
633This allows access to other protocol stacks that have not had jail
634functionality added to them.
635.It Va allow.mlock
636Locking or unlocking physical pages in memory are normally not available
637within a jail.
638When this parameter is set, users may
639.Xr mlock 2
640or
641.Xr munlock 2
642memory subject to
643.Va security.bsd.unprivileged_mlock
644and resource limits.
645.It Va allow.nfsd
646The
647.Xr mountd 8 ,
648.Xr nfsd 8 ,
649.Xr nfsuserd 8 ,
650.Xr gssd 8
651and
652.Xr rpc.tlsservd 8
653daemons are permitted to run inside a properly configured vnet-enabled jail.
654The jail's root must be a file system mount point and
655.Va enforce_statfs
656must not be set to 0, so that
657.Xr mountd 8
658can export file systems visible within the jail.
659.Va enforce_statfs
660must be set to 1 if file systems mounted under the
661jail's file system need to be exported by
662.Xr mount 8 .
663For exporting only the jail's file system, a setting of 2
664is sufficient.
665If the kernel configuration does not include the
666.Sy NFSD
667option,
668.Pa nfsd.ko
669must be loaded outside of the jails.
670This is normally done by adding
671.Dq nfsd
672to
673.Va kld_list
674in the
675.Xr rc.conf 5
676file outside of the jails.
677Similarily, if the
678.Xr gssd 8
679is to be run in a jail, either the kernel
680.Sy KGSSAPI
681option needs to be specified or
682.Dq kgssapi
683and
684.Dq kgssapi_krb5
685need to be in
686.Va kld_list
687in the
688.Xr rc.conf 5
689file outside of the jails.
690.It Va allow.reserved_ports
691The jail root may bind to ports lower than 1024.
692.It Va allow.unprivileged_parent_tampering
693Unprivileged processes in the jail's parent may tamper with processes of the
694same UID in the jail.
695This includes the ability to signal, debug, and
696.Xr cpuset 1
697processes that belong to the jail.
698.It Va allow.unprivileged_proc_debug
699Unprivileged processes in the jail may use debugging facilities.
700.It Va allow.suser
701The value of the jail's
702.Va security.bsd.suser_enabled
703sysctl.
704The super-user will be disabled automatically if its parent system has it
705disabled.
706The super-user is enabled by default.
707.It Va allow.extattr
708Allow privileged processes in the jail to manipulate filesystem extended
709attributes in the system namespace.
710.It Va allow.adjtime
711Allow privileged processes in the jail to slowly adjusting global operating
712system time.
713For example through utilities like
714.Xr ntpd 8 .
715.It Va allow.settime
716Allow privileged processes in the jail to set global operating system data
717and time.
718For example through utilities like
719.Xr date 1 .
720This permission includes also
721.Va allow.adjtime .
722.It Va allow.routing
723Allow privileged process in the non-VNET jail to modify the system routing
724table.
725.It Va allow.setaudit
726Allow privileged processes in the jail to set
727.Xr audit 4
728session state using
729.Xr setaudit 2
730and related system calls.
731This is useful, for example, for allowing a jailed
732.Xr sshd 8
733to set the audit user ID for an authenticated session.
734However, it gives jailed processes the ability to modify or disable audit
735session state, so should be configured with care.
736.El
737.El
738.Pp
739Kernel modules may add their own parameters, which only exist when the
740module is loaded.
741These are typically headed under a parameter named after the module,
742with values of
743.Dq inherit
744to give the jail full use of the module,
745.Dq new
746to encapsulate the jail in some module-specific way,
747and
748.Dq disable
749to make the module unavailable to the jail.
750There also may be other parameters to define jail behavior within the module.
751Module-specific parameters include:
752.Bl -tag -width indent
753.It Va allow.mount.fdescfs
754privileged users inside the jail will be able to mount and unmount the
755fdescfs file system.
756This permission is effective only together with
757.Va allow.mount
758and only when
759.Va enforce_statfs
760is set to a value lower than 2.
761.It Va allow.mount.fusefs
762privileged users inside the jail will be able to mount and unmount
763fuse-based file systems.
764This permission is effective only together with
765.Va allow.mount
766and only when
767.Va enforce_statfs
768is set to a value lower than 2.
769.It Va allow.mount.nullfs
770privileged users inside the jail will be able to mount and unmount the
771nullfs file system.
772This permission is effective only together with
773.Va allow.mount
774and only when
775.Va enforce_statfs
776is set to a value lower than 2.
777.It Va allow.mount.procfs
778privileged users inside the jail will be able to mount and unmount the
779procfs file system.
780This permission is effective only together with
781.Va allow.mount
782and only when
783.Va enforce_statfs
784is set to a value lower than 2.
785.It Va allow.mount.linprocfs
786privileged users inside the jail will be able to mount and unmount the
787linprocfs file system.
788This permission is effective only together with
789.Va allow.mount
790and only when
791.Va enforce_statfs
792is set to a value lower than 2.
793.It Va allow.mount.linsysfs
794privileged users inside the jail will be able to mount and unmount the
795linsysfs file system.
796This permission is effective only together with
797.Va allow.mount
798and only when
799.Va enforce_statfs
800is set to a value lower than 2.
801.It Va allow.mount.tmpfs
802privileged users inside the jail will be able to mount and unmount the
803tmpfs file system.
804This permission is effective only together with
805.Va allow.mount
806and only when
807.Va enforce_statfs
808is set to a value lower than 2.
809.It Va allow.mount.zfs
810privileged users inside the jail will be able to mount and unmount the
811ZFS file system.
812This permission is effective only together with
813.Va allow.mount
814and only when
815.Va enforce_statfs
816is set to a value lower than 2.
817See
818.Xr zfs-jail 8
819for information on how to configure the ZFS filesystem to operate from
820within a jail.
821.It Va allow.vmm
822The jail may access
823.Xr vmm 4 .
824This flag is only available when the
825.Xr vmm 4
826kernel module is loaded.
827.It Va linux
828Determine how a jail's Linux emulation environment appears.
829A value of
830.Dq inherit
831will keep the same environment, and
832.Dq new
833will give the jail its own environment (still originally inherited when
834the jail is created).
835.It Va linux.osname , linux.osrelease , linux.oss_version
836The Linux OS name, OS release, and OSS version associated with this jail.
837.It Va sysvmsg
838Allow access to SYSV IPC message primitives.
839If set to
840.Dq inherit ,
841all IPC objects on the system are visible to this jail, whether they
842were created by the jail itself, the base system, or other jails.
843If set to
844.Dq new ,
845the jail will have its own key namespace, and can only see the objects
846that it has created;
847the system (or parent jail) has access to the jail's objects, but not to
848its keys.
849If set to
850.Dq disable ,
851the jail cannot perform any sysvmsg-related system calls.
852.It Va sysvsem, sysvshm
853Allow access to SYSV IPC semaphore and shared memory primitives, in the
854same manner as
855.Va sysvmsg .
856.It Va zfs.mount_snapshot
857When set to 1, jailed users may access the contents of ZFS snapshots
858under the filesystem's
859.Pa .zfs
860directory.
861If
862.Va allow.mount.zfs
863is set, the snapshots may also be mounted.
864.El
865.Pp
866There are pseudo-parameters that are not passed to the kernel, but are
867used by
868.Nm
869to set up the jail environment, often by running specified commands
870when jails are created or removed.
871The
872.Va exec.*
873command parameters are
874.Xr sh 1
875command lines that are run in either the system or jail environment.
876They may be given multiple values, which would run the specified
877commands in sequence.
878All commands must succeed (return a zero exit status), or the jail will
879not be created or removed, as appropriate.
880.Pp
881The following variables are added to the environment:
882.Bl -tag -width indent -offset indent
883.It Ev JID
884The
885.Va jid ,
886or jail identifier.
887.It Ev JNAME
888The
889.Va name
890of the jail.
891.It Ev JPATH
892The
893.Va path
894of the jail.
895.El
896.Pp
897The pseudo-parameters are:
898.Bl -tag -width indent
899.It Va exec.prepare
900Command(s) to run in the system environment to prepare a jail for creation.
901These commands are executed before assigning IP addresses and mounting
902filesystems, so they may be used to create a new jail filesystem if it does
903not already exist.
904.It Va exec.prestart
905Command(s) to run in the system environment before a jail is created.
906.It Va exec.created
907Command(s) to run in the system environment right after a jail has been
908created, but before commands (or services) get executed in the jail.
909.It Va exec.start
910Command(s) to run in the jail environment when a jail is created.
911A typical command to run is
912.Dq sh /etc/rc .
913.It Va command
914A synonym for
915.Va exec.start
916for use when specifying a jail directly on the command line.
917Unlike other parameters whose value is a single string,
918.Va command
919uses the remainder of the
920.Nm
921command line as its own arguments.
922.It Va exec.poststart
923Command(s) to run in the system environment after a jail is created,
924and after any
925.Va exec.start
926commands have completed.
927.It Va exec.prestop
928Command(s) to run in the system environment before a jail is removed.
929.It Va exec.stop
930Command(s) to run in the jail environment before a jail is removed,
931and after any
932.Va exec.prestop
933commands have completed.
934A typical command to run is
935.Dq sh /etc/rc.shutdown jail .
936.It Va exec.poststop
937Command(s) to run in the system environment after a jail is removed.
938.It Va exec.release
939Command(s) to run in the system environment after all other actions are done.
940These commands are executed after unmounting filesystems and removing IP
941addresses, so they may be used to remove a jail filesystem if it is no longer
942needed.
943.It Va exec.clean
944Run commands in a clean environment.
945The environment is discarded except for
946.Ev HOME , SHELL , TERM
947and
948.Ev USER .
949.Ev HOME
950and
951.Ev SHELL
952are set to the target login's default values.
953.Ev USER
954is set to the target login.
955.Ev TERM
956is imported from the current environment.
957.Ev PATH
958is set to "/bin:/usr/bin".
959The environment variables from the login class capability database for the
960target login are also set.
961.Ev JID ,
962.Ev JNAME ,
963and
964.Ev JPATH
965are not set.
966If a user is specified (as with
967.Va exec.jail_user ) ,
968commands are run from that (possibly jailed) user's directory.
969.It Va exec.jail_user
970The user to run commands as, when running in the jail environment.
971The default is to run the commands as the current user.
972.It Va exec.system_jail_user
973This boolean option looks for the
974.Va exec.jail_user
975in the system
976.Xr passwd 5
977file, instead of in the jail's file.
978.It Va exec.system_user
979The user to run commands as, when running in the system environment.
980The default is to run the commands as the current user.
981.It Va exec.timeout
982The maximum amount of time to wait for a command to complete, in
983seconds.
984If a command is still running after this timeout has passed,
985the jail will not be created or removed, as appropriate.
986.It Va exec.consolelog
987A file to direct command output (stdout and stderr) to.
988.It Va exec.fib
989The FIB (routing table) to set when running commands inside the jail.
990.It Va stop.timeout
991The maximum amount of time to wait for a jail's processes to exit
992after sending them a
993.Dv SIGTERM
994signal (which happens after the
995.Va exec.stop
996commands have completed).
997After this many seconds have passed, the jail will be removed, which
998will kill any remaining processes.
999If this is set to zero, no
1000.Dv SIGTERM
1001is sent and the jail is immediately removed.
1002The default is 10 seconds.
1003.It Va interface
1004A network interface to add the jail's IP addresses
1005.Va ( ip4.addr
1006and
1007.Va ip6.addr )
1008to.
1009An alias for each address will be added to the interface before the
1010jail is created, and will be removed from the interface after the
1011jail is removed.
1012.It Va ip4.addr
1013In addition to the IP addresses that are passed to the kernel, an
1014interface, netmask and additional parameters (as supported by
1015.Xr ifconfig 8 )
1016may also be specified, in the form
1017.Dq Ar interface Ns | Ns Ar ip-address Ns / Ns Ar netmask param ... .
1018If an interface is given before the IP address, an alias for the address
1019will be added to that interface, as it is with the
1020.Va interface
1021parameter.
1022If a netmask in either dotted-quad or CIDR form is given
1023after an IP address, it will be used when adding the IP alias.
1024If additional parameters are specified then they will also be used when
1025adding the IP alias.
1026.It Va ip6.addr
1027In addition to the IP addresses that are passed to the kernel,
1028an interface, prefix and additional parameters (as supported by
1029.Xr ifconfig 8 )
1030may also be specified, in the form
1031.Dq Ar interface Ns | Ns Ar ip-address Ns / Ns Ar prefix param ... .
1032.It Va vnet.interface
1033A comma separated list of network interfaces to give to a vnet-enabled jail
1034after is it created.
1035The interfaces will automatically be released when the jail is removed.
1036.It Va zfs.dataset
1037A list of ZFS datasets to be attached to the jail.
1038This requires
1039.Va allow.mount.zfs
1040to be set.
1041See
1042.Xr zfs-jail 8
1043for information on how to configure a ZFS dataset to be operated from
1044within a jail.
1045.It Va ip_hostname
1046Resolve the
1047.Va host.hostname
1048parameter and add all IP addresses returned by the resolver
1049to the list of addresses
1050.Po Va ip4.addr
1051or
1052.Va ip6.addr Pc
1053for this jail.
1054This may affect default address selection for outgoing IPv4 connections
1055from jails.
1056The address first returned by the resolver for each address family
1057will be used as the primary address.
1058.It Va mount
1059A filesystem to mount before creating the jail (and to unmount after
1060removing it), given as a single
1061.Xr fstab 5
1062line.
1063.It Va mount.fstab
1064An
1065.Xr fstab 5
1066format file containing filesystems to mount before creating a jail.
1067.It Va mount.devfs
1068Mount a
1069.Xr devfs 4
1070filesystem on the chrooted
1071.Pa /dev
1072directory, and apply the ruleset in the
1073.Va devfs_ruleset
1074parameter (or a default of ruleset 4: devfsrules_jail)
1075to restrict the devices visible inside the jail.
1076.It Va mount.fdescfs
1077Mount a
1078.Xr fdescfs 4
1079filesystem on the chrooted
1080.Pa /dev/fd
1081directory.
1082.It Va mount.procfs
1083Mount a
1084.Xr procfs 4
1085filesystem on the chrooted
1086.Pa /proc
1087directory.
1088.It Va allow.dying
1089This is deprecated and has no effect.
1090It used to allow making changes to a
1091.Va dying
1092jail.
1093Now such jails are always replaced when a new jail is created with the same
1094.Va jid
1095or
1096.Va name .
1097.It Va depend
1098Specify a jail (or jails) that this jail depends on.
1099When this jail is to be created, any jail(s) it depends on must already exist.
1100If not, they will be created automatically, up to the completion of the last
1101.Va exec.poststart
1102command, before any action will taken to create this jail.
1103When jails are removed the opposite is true:
1104this jail will be removed, up to the last
1105.Va exec.poststop
1106command, before any jail(s) it depends on are stopped.
1107.El
1108.Sh EXAMPLES
1109Jails are typically set up using one of two philosophies: either to
1110constrain a specific application (possibly running with privilege), or
1111to create a
1112.Dq "virtual system image"
1113running a variety of daemons and services.
1114In both cases, a fairly complete file system install of
1115.Fx
1116is
1117required, so as to provide the necessary command line tools, daemons,
1118libraries, application configuration files, etc.
1119However, for a virtual server configuration, a fair amount of
1120additional work is required so as to replace the
1121.Dq boot
1122process.
1123This manual page documents the configuration steps necessary to support
1124either of these steps, although the configuration steps may need to be
1125refined based on local requirements.
1126.Ss Setting up a Jail Directory Tree From Source
1127To set up a jail directory tree containing an entire
1128.Fx
1129distribution, the following
1130.Xr sh 1
1131command script can be used:
1132.Bd -literal -offset indent
1133D=/here/is/the/jail
1134cd /usr/src
1135mkdir -p $D
1136make world DESTDIR=$D
1137make distribution DESTDIR=$D
1138.Ed
1139.Ss Setting up a Jail Directory Tree from Distribution Files
1140To set up a jail directory tree containing an entire
1141.Fx
1142distribution, the following
1143.Xr sh 1
1144command script can be used:
1145.Bd -literal -offset indent
1146D=/here/is/the/jail
1147mkdir -p $D
1148tar -xf /usr/freebsd-dist/base.txz -C $D --unlink
1149.Ed
1150.Pp
1151In many cases these examples would put far more in the jail than needed.
1152In the other extreme case a jail might contain only one file:
1153the executable to be run in the jail.
1154.Pp
1155We recommend experimentation, and caution that it is a lot easier to
1156start with a
1157.Dq fat
1158jail and remove things until it stops working,
1159than it is to start with a
1160.Dq thin
1161jail and add things until it works.
1162.Ss "Setting Up a Jail"
1163Do what was described in
1164.Sx "Setting Up a Jail Directory Tree"
1165to build the jail directory tree.
1166For the sake of this example, we will
1167assume you built it in
1168.Pa /data/jail/testjail ,
1169for a jail named
1170.Dq testjail .
1171Substitute below as needed with your
1172own directory, IP address, and hostname.
1173.Ss "Setting up the Host Environment"
1174First, set up the real system's environment to be
1175.Dq jail-friendly .
1176For consistency, we will refer to the parent box as the
1177.Dq "host environment" ,
1178and to the jailed virtual machine as the
1179.Dq "jail environment" .
1180Since jails are implemented using IP aliases, one of the first things to do
1181is to disable IP services on the host system that listen on all local
1182IP addresses for a service.
1183If a network service is present in the host environment that binds all
1184available IP addresses rather than specific IP addresses, it may service
1185requests sent to jail IP addresses if the jail did not bind the port.
1186This means changing
1187.Xr inetd 8
1188to only listen on the
1189appropriate IP address, and so forth.
1190Add the following to
1191.Pa /etc/rc.conf
1192in the host environment:
1193.Bd -literal -offset indent
1194sendmail_enable="NO"
1195inetd_flags="-wW -a 192.0.2.23"
1196rpcbind_enable="NO"
1197.Ed
1198.Pp
1199.Li 192.0.2.23
1200is the native IP address for the host system, in this example.
1201Daemons that run out of
1202.Xr inetd 8
1203can be easily configured to use only the specified host IP address.
1204Other daemons
1205will need to be manually configured \(em for some this is possible through
1206.Xr rc.conf 5
1207flags entries; for others it is necessary to modify per-application
1208configuration files, or to recompile the application.
1209The following frequently deployed services must have their individual
1210configuration files modified to limit the application to listening
1211to a specific IP address:
1212.Pp
1213To configure
1214.Xr sshd 8 ,
1215it is necessary to modify
1216.Pa /etc/ssh/sshd_config .
1217.Pp
1218To configure
1219.Xr sendmail 8 ,
1220it is necessary to modify
1221.Pa /etc/mail/sendmail.cf .
1222.Pp
1223In addition, a number of services must be recompiled in order to run
1224them in the host environment.
1225This includes most applications providing services using
1226.Xr rpc 3 ,
1227such as
1228.Xr rpcbind 8 ,
1229.Xr nfsd 8 ,
1230and
1231.Xr mountd 8 .
1232In general, applications for which it is not possible to specify which
1233IP address to bind should not be run in the host environment unless they
1234should also service requests sent to jail IP addresses.
1235Attempting to serve
1236NFS from the host environment may also cause confusion, and cannot be
1237easily reconfigured to use only specific IPs, as some NFS services are
1238hosted directly from the kernel.
1239Any third-party network software running
1240in the host environment should also be checked and configured so that it
1241does not bind all IP addresses, which would result in those services also
1242appearing to be offered by the jail environments.
1243.Pp
1244Once
1245these daemons have been disabled or fixed in the host environment, it is
1246best to reboot so that all daemons are in a known state, to reduce the
1247potential for confusion later (such as finding that when you send mail
1248to a jail, and its sendmail is down, the mail is delivered to the host,
1249etc.).
1250.Ss "Configuring the Jail"
1251Start any jail for the first time without configuring the network
1252interface so that you can clean it up a little and set up accounts.
1253As
1254with any machine (virtual or not), you will need to set a root password, time
1255zone, etc.
1256Some of these steps apply only if you intend to run a full virtual server
1257inside the jail; others apply both for constraining a particular application
1258or for running a virtual server.
1259.Pp
1260Start a shell in the jail:
1261.Bd -literal -offset indent
1262jail -c path=/data/jail/testjail mount.devfs \\
1263	host.hostname=testhostname ip4.addr=192.0.2.100 \\
1264	command=/bin/sh
1265.Ed
1266.Pp
1267Assuming no errors, you will end up with a shell prompt within the jail.
1268You can now run
1269.Xr bsdconfig 8
1270and do the post-install configuration to set various configuration options,
1271or perform these actions manually by editing
1272.Pa /etc/rc.conf ,
1273etc.
1274.Pp
1275.Bl -bullet -offset indent -compact
1276.It
1277Configure
1278.Pa /etc/resolv.conf
1279so that name resolution within the jail will work correctly.
1280.It
1281Run
1282.Xr newaliases 1
1283to quell
1284.Xr sendmail 8
1285warnings.
1286.It
1287Set a root password, probably different from the real host system.
1288.It
1289Set the timezone.
1290.It
1291Add accounts for users in the jail environment.
1292.It
1293Install any packages the environment requires.
1294.El
1295.Pp
1296You may also want to perform any package-specific configuration (web servers,
1297SSH servers, etc), patch up
1298.Pa /etc/syslog.conf
1299so it logs as you would like, etc.
1300If you are not using a virtual server, you may wish to modify
1301.Xr syslogd 8
1302in the host environment to listen on the syslog socket in the jail
1303environment; in this example, the syslog socket would be stored in
1304.Pa /data/jail/testjail/var/run/log .
1305.Pp
1306Exit from the shell, and the jail will be shut down.
1307.Ss "Starting the Jail"
1308You are now ready to restart the jail and bring up the environment with
1309all of its daemons and other programs.
1310Create an entry for the jail in
1311.Pa /etc/jail.conf :
1312.Bd -literal -offset indent
1313testjail {
1314	path = /tmp/jail/testjail;
1315	mount.devfs;
1316	host.hostname = testhostname;
1317	ip4.addr = 192.0.2.100;
1318	interface = em0;
1319	exec.start = "/bin/sh /etc/rc";
1320	exec.stop = "/bin/sh /etc/rc.shutdown jail";
1321}
1322.Ed
1323.Pp
1324To start a virtual server environment,
1325.Pa /etc/rc
1326is run to launch various daemons and services, and
1327.Pa /etc/rc.shutdown
1328is run to shut them down when the jail is removed.
1329If you are running a single application in the jail,
1330substitute the command used to start the application for
1331.Dq /bin/sh /etc/rc ;
1332there may be some script available to cleanly shut down the application,
1333or it may be sufficient to go without a stop command, and have
1334.Nm
1335send
1336.Dv SIGTERM
1337to the application.
1338.Pp
1339Start the jail by running:
1340.Bd -literal -offset indent
1341jail -c testjail
1342.Ed
1343.Pp
1344A few warnings may be produced; however, it should all work properly.
1345You should be able to see
1346.Xr inetd 8 ,
1347.Xr syslogd 8 ,
1348and other processes running within the jail using
1349.Xr ps 1 ,
1350with the
1351.Ql J
1352flag appearing beside jailed processes.
1353To see an active list of jails, use
1354.Xr jls 8 .
1355If
1356.Xr sshd 8
1357is enabled in the jail environment, you should be able to
1358.Xr ssh 1
1359to the hostname or IP address of the jailed environment, and log
1360in using the accounts you created previously.
1361.Pp
1362It is possible to have jails started at boot time.
1363Please refer to the
1364.Dq jail_*
1365variables in
1366.Xr rc.conf 5
1367for more information.
1368.Ss "Managing the Jail"
1369Normal machine shutdown commands, such as
1370.Xr halt 8 ,
1371.Xr reboot 8 ,
1372and
1373.Xr shutdown 8 ,
1374cannot be used successfully within the jail.
1375To kill all processes from within a jail, you may use one of the
1376following commands, depending on what you want to accomplish:
1377.Bd -literal -offset indent
1378kill -TERM -1
1379kill -KILL -1
1380.Ed
1381.Pp
1382This will send the
1383.Dv SIGTERM
1384or
1385.Dv SIGKILL
1386signals to all processes in the jail \(em be careful not to run this from
1387the host environment!
1388Once all of the jail's processes have died, unless the jail was created
1389with the
1390.Va persist
1391parameter, the jail will be removed.
1392Depending on
1393the intended use of the jail, you may also want to run
1394.Pa /etc/rc.shutdown
1395from within the jail.
1396.Pp
1397To shut down the jail from the outside, simply remove it with:
1398.Bd -literal -offset indent
1399jail -r
1400.Ed
1401.Pp
1402which will run any commands specified by
1403.Va exec.stop ,
1404and then send
1405.Dv SIGTERM
1406and eventually
1407.Dv SIGKILL
1408to any remaining jailed processes.
1409.Pp
1410The
1411.Pa /proc/ Ns Ar pid Ns Pa /status
1412file contains, as its last field, the name of the jail in which the
1413process runs, or
1414.Dq Li -
1415to indicate that the process is not running within a jail.
1416The
1417.Xr ps 1
1418command also shows a
1419.Ql J
1420flag for processes in a jail.
1421.Pp
1422You can also list/kill processes based on their jail ID.
1423To show processes and their jail ID, use the following command:
1424.Pp
1425.Dl "ps ax -o pid,jid,args"
1426.Pp
1427To show and then kill processes in jail number 3 use the following commands:
1428.Bd -literal -offset indent
1429pgrep -lfj 3
1430pkill -j 3
1431.Ed
1432or:
1433.Pp
1434.Dl "killall -j 3"
1435.Ss "Jails and File Systems"
1436It is not possible to
1437.Xr mount 8
1438or
1439.Xr umount 8
1440any file system inside a jail unless the file system is marked
1441jail-friendly, the jail's
1442.Va allow.mount
1443parameter is set, and the jail's
1444.Va enforce_statfs
1445parameter is lower than 2.
1446.Pp
1447Multiple jails sharing the same file system can influence each other.
1448For example, a user in one jail can fill the file system,
1449leaving no space for processes in the other jail.
1450Trying to use
1451.Xr quota 1
1452to prevent this will not work either, as the file system quotas
1453are not aware of jails but only look at the user and group IDs.
1454This means the same user ID in two jails share a single file
1455system quota.
1456One would need to use one file system per jail to make this work.
1457.Ss "Sysctl MIB Entries"
1458The read-only entry
1459.Va security.jail.jailed
1460can be used to determine if a process is running inside a jail (value
1461is one) or not (value is zero).
1462.Pp
1463The variable
1464.Va security.jail.jail_max_af_ips
1465determines how may address per address family a jail may have.
1466The default is 255.
1467.Pp
1468Some MIB variables have per-jail settings.
1469Changes to these variables by a jailed process do not affect the host
1470environment, only the jail environment.
1471These variables are
1472.Va kern.securelevel ,
1473.Va security.bsd.suser_enabled ,
1474.Va kern.hostname ,
1475.Va kern.domainname ,
1476.Va kern.hostid ,
1477and
1478.Va kern.hostuuid .
1479.Ss "Hierarchical Jails"
1480By setting a jail's
1481.Va children.max
1482parameter, processes within a jail may be able to create jails of their own.
1483These child jails are kept in a hierarchy, with jails only able to see and/or
1484modify the jails they created (or those jails' children).
1485Each jail has a read-only
1486.Va parent
1487parameter, containing the
1488.Va jid
1489of the jail that created it; a
1490.Va jid
1491of 0 indicates the jail is a child of the current jail (or is a top-level
1492jail if the current process isn't jailed).
1493.Pp
1494Jailed processes are not allowed to confer greater permissions than they
1495themselves are given, e.g., if a jail is created with
1496.Va allow.nomount ,
1497it is not able to create a jail with
1498.Va allow.mount
1499set.
1500Similarly, such restrictions as
1501.Va ip4.addr
1502and
1503.Va securelevel
1504may not be bypassed in child jails.
1505.Pp
1506A child jail may in turn create its own child jails if its own
1507.Va children.max
1508parameter is set (remember it is zero by default).
1509These jails are visible to and can be modified by their parent and all
1510ancestors.
1511.Pp
1512Jail names reflect this hierarchy, with a full name being an MIB-type string
1513separated by dots.
1514For example, if a base system process creates a jail
1515.Dq foo ,
1516and a process under that jail creates another jail
1517.Dq bar ,
1518then the second jail will be seen as
1519.Dq foo.bar
1520in the base system (though it is only seen as
1521.Dq bar
1522to any processes inside jail
1523.Dq foo ) .
1524Jids on the other hand exist in a single space, and each jail must have a
1525unique jid.
1526.Pp
1527Like the names, a child jail's
1528.Va path
1529appears relative to its creator's own
1530.Va path .
1531This is by virtue of the child jail being created in the chrooted
1532environment of the first jail.
1533.Sh SEE ALSO
1534.Xr date 1 ,
1535.Xr killall 1 ,
1536.Xr lsvfs 1 ,
1537.Xr newaliases 1 ,
1538.Xr pgrep 1 ,
1539.Xr pkill 1 ,
1540.Xr ps 1 ,
1541.Xr quota 1 ,
1542.Xr adjtime 2 ,
1543.Xr clock_settime 2 ,
1544.Xr jail_set 2 ,
1545.Xr ntp_adjtime 2 ,
1546.Xr devfs 4 ,
1547.Xr fdescfs 4 ,
1548.Xr linprocfs 4 ,
1549.Xr linsysfs 4 ,
1550.Xr procfs 4 ,
1551.Xr vmm 4 ,
1552.Xr jail.conf 5 ,
1553.Xr rc.conf 5 ,
1554.Xr sysctl.conf 5 ,
1555.Xr bsdconfig 8 ,
1556.Xr chroot 8 ,
1557.Xr devfs 8 ,
1558.Xr halt 8 ,
1559.Xr ifconfig 8 ,
1560.Xr inetd 8 ,
1561.Xr jexec 8 ,
1562.Xr jls 8 ,
1563.Xr mount 8 ,
1564.Xr mountd 8 ,
1565.Xr nfsd 8 ,
1566.Xr ntpd 8 ,
1567.Xr reboot 8 ,
1568.Xr rpcbind 8 ,
1569.Xr sendmail 8 ,
1570.Xr shutdown 8 ,
1571.Xr sysctl 8 ,
1572.Xr syslogd 8 ,
1573.Xr umount 8 ,
1574.Xr zfs-jail 8 ,
1575.Xr extattr 9
1576.Sh HISTORY
1577The
1578.Nm
1579utility appeared in
1580.Fx 4.0 .
1581Hierarchical/extensible jails were introduced in
1582.Fx 8.0 .
1583The configuration file was introduced in
1584.Fx 9.1 .
1585.Sh AUTHORS
1586.An -nosplit
1587The jail feature was written by
1588.An Poul-Henning Kamp
1589for R&D Associates
1590who contributed it to
1591.Fx .
1592.Pp
1593.An Robert Watson
1594wrote the extended documentation, found a few bugs, added
1595a few new features, and cleaned up the userland jail environment.
1596.Pp
1597.An Bjoern A. Zeeb
1598added multi-IP jail support for IPv4 and IPv6 based on a patch
1599originally done by
1600.An Pawel Jakub Dawidek
1601for IPv4.
1602.Pp
1603.An James Gritton
1604added the extensible jail parameters, hierarchical jails,
1605and the configuration file.
1606.Sh BUGS
1607It might be a good idea to add an
1608address alias flag such that daemons listening on all IPs
1609.Pq Dv INADDR_ANY
1610will not bind on that address, which would facilitate building a safe
1611host environment such that host daemons do not impose on services offered
1612from within jails.
1613Currently, the simplest answer is to minimize services
1614offered on the host, possibly limiting it to services offered from
1615.Xr inetd 8
1616which is easily configurable.
1617.Sh NOTES
1618Great care should be taken when managing directories visible within the jail.
1619For example, if a jailed process has its current working directory set to a
1620directory that is moved out of the jail's chroot, then the process may gain
1621access to the file space outside of the jail.
1622It is recommended that directories always be copied, rather than moved, out
1623of a jail.
1624.Pp
1625In addition, there are several ways in which an unprivileged user
1626outside the jail can cooperate with a privileged user inside the jail
1627and thereby obtain elevated privileges in the host environment.
1628Most of these attacks can be mitigated by ensuring that the jail root
1629is not accessible to unprivileged users in the host environment.
1630Regardless, as a general rule, untrusted users with privileged access
1631to a jail should not be given access to the host environment.
1632