|
Lines 1-1611
Link Here
|
| 1 |
<?xml version="1.0" encoding="iso-8859-1"?> |
1 |
<?xml version="1.0" encoding="iso-8859-1"?> |
| 2 |
<!-- |
2 |
<!-- |
| 3 |
The FreeBSD Documentation Project |
3 |
The FreeBSD Documentation Project |
| 4 |
|
4 |
|
| 5 |
$FreeBSD$ |
5 |
$FreeBSD$ |
| 6 |
--> |
6 |
--> |
| 7 |
<chapter xmlns="http://docbook.org/ns/docbook" |
7 |
<chapter xmlns="http://docbook.org/ns/docbook" |
| 8 |
xmlns:xlink="http://www.w3.org/1999/xlink" version="5.0" |
8 |
xmlns:xlink="http://www.w3.org/1999/xlink" version="5.0" |
| 9 |
xml:id="jails"> |
9 |
xml:id="jails"> |
| 10 |
<info> |
10 |
<info> |
| 11 |
<title>Jails</title> |
11 |
<title>Jails</title> |
| 12 |
|
12 |
|
| 13 |
<authorgroup> |
13 |
<authorgroup> |
| 14 |
<author><personname><firstname>Matteo</firstname><surname>Riondato</surname></personname><contrib>Contributed |
14 |
<author><personname><firstname>Matteo</firstname><surname>Riondato</surname></personname><contrib>Contributed |
| 15 |
by </contrib></author> |
15 |
by </contrib></author> |
| 16 |
</authorgroup> |
16 |
</authorgroup> |
| 17 |
</info> |
17 |
</info> |
| 18 |
|
18 |
|
| 19 |
<indexterm><primary>jails</primary></indexterm> |
19 |
<indexterm><primary>jails</primary></indexterm> |
| 20 |
|
20 |
|
| 21 |
<sect1 xml:id="jails-synopsis"> |
21 |
<sect1 xml:id="jails-synopsis"> |
| 22 |
<title>Synopsis</title> |
22 |
<title>Synopsis</title> |
| 23 |
|
23 |
|
| 24 |
<para>Since system administration is a difficult task, many tools |
24 |
<para>Since system administration is a difficult task, many tools |
| 25 |
have been developed to make life easier for the administrator. |
25 |
have been developed to make life easier for the administrator. |
| 26 |
These tools often enhance the way systems are installed, |
26 |
These tools often enhance the way systems are installed, |
| 27 |
configured, and maintained. One of the tools which can be used |
27 |
configured, and maintained. One of the tools which can be used |
| 28 |
to enhance the security of a &os; system is |
28 |
to enhance the security of a &os; system is |
| 29 |
<firstterm>jails</firstterm>. Jails have been available since |
29 |
<firstterm>jails</firstterm>. Jails have been available since |
| 30 |
&os; 4.X and continue to be enhanced in their usefulness, |
30 |
&os; 4.X and continue to be enhanced in their usefulness, |
| 31 |
performance, reliability, and security.</para> |
31 |
performance, reliability, and security.</para> |
| 32 |
|
32 |
|
| 33 |
<para>Jails build upon the &man.chroot.2; concept, which is used |
33 |
<para>Jails build upon the &man.chroot.2; concept (which is used |
| 34 |
to change the root directory of a set of processes, creating a |
34 |
to change the root directory of a set of processes) to create a |
| 35 |
safe environment, separate from the rest of the system. |
35 |
safe environment, separate from the rest of the system. |
| 36 |
Processes created in the chrooted environment can not access |
36 |
Processes created in the chrooted environment can not access |
| 37 |
files or resources outside of it. For that reason, compromising |
37 |
files or resources outside of it. For that reason, compromising |
| 38 |
a service running in a chrooted environment should not allow the |
38 |
a service running in a "chroot-ed" environment should not allow the |
| 39 |
attacker to compromise the entire system. However, a chroot has |
39 |
attacker to compromise the entire system. However, a chroot has |
| 40 |
several limitations. It is suited to easy tasks which do not |
40 |
several limitations. It is suited to easy tasks which do not |
| 41 |
require much flexibility or complex, advanced features. Over |
41 |
require much flexibility or complex, advanced features. Over |
| 42 |
time many ways have been found to escape from a chrooted |
42 |
time many ways have been found to escape from a chrooted |
| 43 |
environment, making it a less than ideal solution for securing |
43 |
environment, making it a less than ideal solution for securing |
| 44 |
services.</para> |
44 |
services.</para> |
| 45 |
|
45 |
|
| 46 |
<para>Jails improve on the concept of the traditional chroot |
46 |
<para>Jails improve on the concept of the traditional chroot |
| 47 |
environment in several ways. In a traditional chroot |
47 |
environment in several ways. In a traditional chroot |
| 48 |
environment, processes are only limited in the part of the file |
48 |
environment, processes are only limited in the part of the file |
| 49 |
system they can access. The rest of the system resources, |
49 |
system they can access. The rest of the system resources, |
| 50 |
system users, running processes, and the networking subsystem |
50 |
system users, running processes, and the networking subsystem |
| 51 |
are shared by the chrooted processes and the processes of the |
51 |
are shared by the chrooted processes and the processes of the |
| 52 |
host system. Jails expand this model by virtualizing access to |
52 |
host system. Jails expand this model by virtualizing access to |
| 53 |
the file system, the set of users, and the networking subsystem. |
53 |
the file system, the set of users, and the networking subsystem. |
| 54 |
More fine-grained controls are available for tuning the access |
54 |
More fine-grained controls are available for tuning the access |
| 55 |
of a jailed environment. Jails can be considered as a type of |
55 |
of a jailed environment. Jails can be considered as a type of |
| 56 |
operating system-level virtualization.</para> |
56 |
operating system-level virtualization.</para> |
| 57 |
|
57 |
|
| 58 |
<para>A jail is characterized by four elements:</para> |
58 |
<para>A jail is characterized by four elements:</para> |
| 59 |
|
59 |
|
| 60 |
<itemizedlist> |
60 |
<itemizedlist> |
| 61 |
<listitem> |
61 |
<listitem> |
| 62 |
<para>A directory subtree: the starting point from which a |
62 |
<para>A directory subtree: the starting point from which a |
| 63 |
jail is entered. Once inside the jail, a process is not |
63 |
jail is entered. Once inside the jail, a process is not |
| 64 |
permitted to escape outside of this subtree.</para> |
64 |
permitted to escape outside of this subtree.</para> |
| 65 |
</listitem> |
65 |
</listitem> |
| 66 |
|
66 |
|
| 67 |
<listitem> |
67 |
<listitem> |
| 68 |
<para>A hostname: which will be used by the jail.</para> |
68 |
<para>A hostname: which will be used by the jail.</para> |
| 69 |
</listitem> |
69 |
</listitem> |
| 70 |
|
70 |
|
| 71 |
<listitem> |
71 |
<listitem> |
| 72 |
<para>An <acronym>IP</acronym> address: which is assigned to |
72 |
<para>An <acronym>IP</acronym> address: which is assigned to |
| 73 |
the jail. The <acronym>IP</acronym> address of a jail is |
73 |
the jail. The <acronym>IP</acronym> address of a jail is |
| 74 |
often an alias address for an existing network |
74 |
often an alias address for an existing network |
| 75 |
interface.</para> |
75 |
interface.</para> |
| 76 |
</listitem> |
76 |
</listitem> |
| 77 |
|
77 |
|
| 78 |
<listitem> |
78 |
<listitem> |
| 79 |
<para>A command: the path name of an executable to run inside |
79 |
<para>A command: the path name of an executable to run inside |
| 80 |
the jail. The path is relative to the root directory of the |
80 |
the jail. The path is relative to the root directory of the |
| 81 |
jail environment.</para> |
81 |
jail environment.</para> |
| 82 |
</listitem> |
82 |
</listitem> |
| 83 |
</itemizedlist> |
83 |
</itemizedlist> |
| 84 |
|
84 |
|
| 85 |
<para>Jails have their own set of users and their own <systemitem |
85 |
<para>Jails have their own set of users and their own <systemitem |
| 86 |
class="username">root</systemitem> account which are limited |
86 |
class="username">root</systemitem> account which are limited |
| 87 |
to the jail environment. The <systemitem |
87 |
to the jail environment. The <systemitem |
| 88 |
class="username">root</systemitem> account of a jail is not |
88 |
class="username">root</systemitem> account of a jail is not |
| 89 |
allowed to perform operations to the system outside of the |
89 |
allowed to perform operations to the system outside of the |
| 90 |
associated jail environment.</para> |
90 |
associated jail environment.</para> |
| 91 |
|
91 |
|
| 92 |
<para>This chapter provides an overview of the terminology and |
92 |
<para>This chapter provides an overview of the terminology and |
| 93 |
commands for managing &os; jails. Jails are a powerful tool for |
93 |
commands for managing &os; jails. Jails are a powerful tool for |
| 94 |
both system administrators, and advanced users.</para> |
94 |
both system administrators, and advanced users.</para> |
| 95 |
|
95 |
|
| 96 |
<para>After reading this chapter, you will know:</para> |
96 |
<para>After reading this chapter, you will know:</para> |
| 97 |
|
97 |
|
| 98 |
<itemizedlist> |
98 |
<itemizedlist> |
| 99 |
<listitem> |
99 |
<listitem> |
| 100 |
<para>What a jail is and what purpose it may serve in &os; |
100 |
<para>What a jail is and what purpose it may serve in &os; |
| 101 |
installations.</para> |
101 |
installations.</para> |
| 102 |
</listitem> |
102 |
</listitem> |
| 103 |
|
103 |
|
| 104 |
<listitem> |
104 |
<listitem> |
| 105 |
<para>How to build, start, and stop a jail.</para> |
105 |
<para>How to build, start, and stop a jail.</para> |
| 106 |
</listitem> |
106 |
</listitem> |
| 107 |
|
107 |
|
| 108 |
<listitem> |
108 |
<listitem> |
| 109 |
<para>The basics of jail administration, both from inside and |
109 |
<para>The basics of jail administration, both from inside and |
| 110 |
outside the jail.</para> |
110 |
outside the jail.</para> |
| 111 |
</listitem> |
111 |
</listitem> |
| 112 |
</itemizedlist> |
112 |
</itemizedlist> |
| 113 |
|
113 |
|
| 114 |
<important> |
114 |
<important> |
| 115 |
<para>Jails are a powerful tool, but they are not a security |
115 |
<para>Jails are a powerful tool, but they are not a security |
| 116 |
panacea. While it is not possible for a jailed process to |
116 |
panacea. While it is not possible for a jailed process to |
| 117 |
break out on its own, there are several ways in which an |
117 |
break out on its own, there are several ways in which an |
| 118 |
unprivileged user outside the jail can cooperate with a |
118 |
unprivileged user outside the jail can cooperate with a |
| 119 |
privileged user inside the jail to obtain elevated privileges |
119 |
privileged user inside the jail to obtain elevated privileges |
| 120 |
in the host environment.</para> |
120 |
in the host environment.</para> |
| 121 |
|
121 |
|
| 122 |
<para>Most of these attacks can be mitigated by ensuring that |
122 |
<para>Most of these attacks can be mitigated by ensuring that |
| 123 |
the jail root is not accessible to unprivileged users in the |
123 |
the jail root is not accessible to unprivileged users in the |
| 124 |
host environment. As a general rule, untrusted users with |
124 |
host environment. As a general rule, untrusted users with |
| 125 |
privileged access to a jail should not be given access to the |
125 |
privileged access to a jail should not be given access to the |
| 126 |
host environment.</para> |
126 |
host environment.</para> |
| 127 |
</important> |
127 |
</important> |
| 128 |
</sect1> |
128 |
</sect1> |
| 129 |
|
129 |
|
| 130 |
<sect1 xml:id="jails-terms"> |
130 |
<sect1 xml:id="jails-terms"> |
| 131 |
<title>Terms Related to Jails</title> |
131 |
<title>Terms Related to Jails</title> |
| 132 |
|
132 |
|
| 133 |
<para>To facilitate better understanding of parts of the &os; |
133 |
<para>To facilitate better understanding of parts of the &os; |
| 134 |
system related to jails, their internals and the way they |
134 |
system related to jails, their internals and the way they |
| 135 |
interact with the rest of &os;, the following terms are used |
135 |
interact with the rest of &os;, the following terms are used |
| 136 |
further in this chapter:</para> |
136 |
further in this chapter:</para> |
| 137 |
|
137 |
|
| 138 |
<variablelist> |
138 |
<variablelist> |
| 139 |
<varlistentry> |
139 |
<varlistentry> |
| 140 |
<term>&man.chroot.8; (command)</term> |
140 |
<term>&man.chroot.8; (command)</term> |
| 141 |
<listitem> |
141 |
<listitem> |
| 142 |
<para>Utility, which uses &man.chroot.2; &os; system call to |
142 |
<para>Utility, which uses &man.chroot.2; &os; system call to |
| 143 |
change the root directory of a process and all its |
143 |
change the root directory of a process and all its |
| 144 |
descendants.</para> |
144 |
descendants.</para> |
| 145 |
</listitem> |
145 |
</listitem> |
| 146 |
</varlistentry> |
146 |
</varlistentry> |
| 147 |
|
147 |
|
| 148 |
<varlistentry> |
148 |
<varlistentry> |
| 149 |
<term>&man.chroot.2; (environment)</term> |
149 |
<term>&man.chroot.2; (environment)</term> |
| 150 |
<listitem> |
150 |
<listitem> |
| 151 |
<para>The environment of processes running in a |
151 |
<para>The environment of processes running in a |
| 152 |
<quote>chroot</quote>. This includes resources such as |
152 |
<quote>chroot</quote>. This includes resources such as |
| 153 |
the part of the file system which is visible, user and |
153 |
the part of the file system which is visible, user and |
| 154 |
group IDs which are available, network interfaces and |
154 |
group IDs which are available, network interfaces and |
| 155 |
other IPC mechanisms, etc.</para> |
155 |
other IPC mechanisms, etc.</para> |
| 156 |
</listitem> |
156 |
</listitem> |
| 157 |
</varlistentry> |
157 |
</varlistentry> |
| 158 |
|
158 |
|
| 159 |
<varlistentry> |
159 |
<varlistentry> |
| 160 |
<term>&man.jail.8; (command)</term> |
160 |
<term>&man.jail.8; (command)</term> |
| 161 |
<listitem> |
161 |
<listitem> |
| 162 |
<para>The system administration utility which allows |
162 |
<para>The system administration utility which allows |
| 163 |
launching of processes within a jail environment.</para> |
163 |
launching of processes within a jail environment.</para> |
| 164 |
</listitem> |
164 |
</listitem> |
| 165 |
</varlistentry> |
165 |
</varlistentry> |
| 166 |
|
166 |
|
| 167 |
<varlistentry> |
167 |
<varlistentry> |
| 168 |
<term>host (system, process, user, etc.)</term> |
168 |
<term>host (system, process, user, etc.)</term> |
| 169 |
<listitem> |
169 |
<listitem> |
| 170 |
<para>The controlling system of a jail environment. The |
170 |
<para>The controlling system of a jail environment. The |
| 171 |
host system has access to all the hardware resources |
171 |
host system has access to all the hardware resources |
| 172 |
available, and can control processes both outside of and |
172 |
available, and can control processes both outside of and |
| 173 |
inside a jail environment. One of the important |
173 |
inside a jail environment. One of the important |
| 174 |
differences of the host system from a jail is that the |
174 |
differences of the host system from a jail is that the |
| 175 |
limitations which apply to superuser processes inside a |
175 |
limitations which apply to superuser processes inside a |
| 176 |
jail are not enforced for processes of the host |
176 |
jail are not enforced for processes of the host |
| 177 |
system.</para> |
177 |
system.</para> |
| 178 |
</listitem> |
178 |
</listitem> |
| 179 |
</varlistentry> |
179 |
</varlistentry> |
| 180 |
|
180 |
|
| 181 |
<varlistentry> |
181 |
<varlistentry> |
| 182 |
<term>hosted (system, process, user, etc.)</term> |
182 |
<term>hosted (system, process, user, etc.)</term> |
| 183 |
<listitem> |
183 |
<listitem> |
| 184 |
<para>A process, user or other entity, whose access to |
184 |
<para>A process, user or other entity, whose access to |
| 185 |
resources is restricted by a &os; jail.</para> |
185 |
resources is restricted by a &os; jail.</para> |
| 186 |
</listitem> |
186 |
</listitem> |
| 187 |
</varlistentry> |
187 |
</varlistentry> |
| 188 |
</variablelist> |
188 |
</variablelist> |
| 189 |
</sect1> |
189 |
</sect1> |
| 190 |
|
190 |
|
| 191 |
<sect1 xml:id="jails-build"> |
191 |
<sect1 xml:id="jails-build"> |
| 192 |
<title>Creating and Controlling Jails</title> |
192 |
<title>Creating and Controlling Jails</title> |
| 193 |
|
193 |
|
| 194 |
<para>Some administrators divide jails into the following two |
194 |
<para>Some administrators divide jails into the following two |
| 195 |
types: <quote>complete</quote> jails, which resemble a real &os; |
195 |
types: <quote>complete</quote> jails, which resemble a real &os; |
| 196 |
system, and <quote>service</quote> jails, dedicated to one |
196 |
system, and <quote>service</quote> jails, dedicated to one |
| 197 |
application or service, possibly running with privileges. This |
197 |
application or service, possibly running with privileges. This |
| 198 |
is only a conceptual division and the process of building a jail |
198 |
is only a conceptual division and the process of building a jail |
| 199 |
is not affected by it. When creating a <quote>complete</quote> |
199 |
is not affected by it. When creating a <quote>complete</quote> |
| 200 |
jail there are two options for the source of the userland: use |
200 |
jail there are two options for the source of the userland: use |
| 201 |
prebuilt binaries (such as those supplied on an install media) |
201 |
prebuilt binaries (such as those supplied on an install media) |
| 202 |
or build from source.</para> |
202 |
or build from source.</para> |
| 203 |
|
203 |
|
| 204 |
<para>To install the userland from installation media, first |
204 |
<para>To install the userland from installation media, first |
| 205 |
create the root directory for the jail. This can be done by |
205 |
create the root directory for the jail. This can be done by |
| 206 |
setting the <varname>DESTDIR</varname> variable to the proper |
206 |
setting the <varname>DESTDIR</varname> variable to the proper |
| 207 |
location.</para> |
207 |
location.</para> |
| 208 |
|
208 |
|
| 209 |
<para>Start a shell and define <varname>DESTDIR</varname>:</para> |
209 |
<para>Start a shell and define <varname>DESTDIR</varname>:</para> |
| 210 |
|
210 |
|
| 211 |
<screen>&prompt.root; <userinput>sh</userinput> |
211 |
<screen>&prompt.root; <userinput>sh</userinput> |
| 212 |
&prompt.root; <userinput>export DESTDIR=<replaceable>/here/is/the/jail</replaceable></userinput></screen> |
212 |
&prompt.root; <userinput>export DESTDIR=<replaceable>/here/is/the/jail</replaceable></userinput></screen> |
| 213 |
|
213 |
|
| 214 |
<para>Mount the install media as covered in &man.mdconfig.8; |
214 |
<para>Mount the install media as covered in &man.mdconfig.8; |
| 215 |
when using the install ISO:</para> |
215 |
when using the install ISO:</para> |
| 216 |
|
216 |
|
| 217 |
<screen>&prompt.root; <userinput>mount -t cd9660 /dev/`mdconfig -f cdimage.iso` /mnt</userinput></screen> |
217 |
<screen>&prompt.root; <userinput>mount -t cd9660 /dev/`mdconfig -f cdimage.iso` /mnt</userinput></screen> |
| 218 |
|
218 |
|
| 219 |
<para>Extract the binaries from the tarballs on the install media |
219 |
<para>Extract the binaries from the tarballs on the install media |
| 220 |
into the declared destination. Minimally, only the base set |
220 |
into the declared destination. Minimally, only the base set |
| 221 |
needs to be extracted, but a complete install can be performed |
221 |
needs to be extracted, but a complete install can be performed |
| 222 |
when preferred.</para> |
222 |
when preferred.</para> |
| 223 |
|
223 |
|
| 224 |
<para>To install just the base system:</para> |
224 |
<para>To install just the base system:</para> |
| 225 |
|
225 |
|
| 226 |
<screen>&prompt.root; <userinput>tar -xf /mnt/usr/freebsd-dist/base.txz -C $DESTDIR</userinput></screen> |
226 |
<screen>&prompt.root; <userinput>tar -xf /mnt/usr/freebsd-dist/base.txz -C $DESTDIR</userinput></screen> |
| 227 |
|
227 |
|
| 228 |
<para>To install everything except the kernel:</para> |
228 |
<para>To install everything except the kernel:</para> |
| 229 |
|
229 |
|
| 230 |
<screen>&prompt.root; <userinput>for <replaceable>sets</replaceable> in BASE PORTS; do tar -xf /mnt/FREEBSD_INSTALL/USR/FREEBSD_DIST/$<replaceable>sets</replaceable>.TXZ -C $DESTDIR ; done</userinput></screen> |
230 |
<screen>&prompt.root; <userinput>for <replaceable>sets</replaceable> in BASE PORTS; do tar -xf /mnt/FREEBSD_INSTALL/USR/FREEBSD_DIST/$<replaceable>sets</replaceable>.TXZ -C $DESTDIR ; done</userinput></screen> |
| 231 |
|
231 |
|
| 232 |
<para>The &man.jail.8; manual page explains the procedure for |
232 |
<para>The &man.jail.8; manual page explains the procedure for |
| 233 |
building a jail:</para> |
233 |
building a jail:</para> |
| 234 |
|
234 |
|
| 235 |
<screen>&prompt.root; <userinput>setenv D <replaceable>/here/is/the/jail</replaceable></userinput> |
235 |
<screen>&prompt.root; <userinput>setenv D <replaceable>/here/is/the/jail</replaceable></userinput> |
| 236 |
&prompt.root; <userinput>mkdir -p $D</userinput> <co xml:id="jailpath"/> |
236 |
&prompt.root; <userinput>mkdir -p $D</userinput> <co xml:id="jailpath"/> |
| 237 |
&prompt.root; <userinput>cd /usr/src</userinput> |
237 |
&prompt.root; <userinput>cd /usr/src</userinput> |
| 238 |
&prompt.root; <userinput>make buildworld</userinput> <co xml:id="jailbuildworld"/> |
238 |
&prompt.root; <userinput>make buildworld</userinput> <co xml:id="jailbuildworld"/> |
| 239 |
&prompt.root; <userinput>make installworld DESTDIR=$D</userinput> <co xml:id="jailinstallworld"/> |
239 |
&prompt.root; <userinput>make installworld DESTDIR=$D</userinput> <co xml:id="jailinstallworld"/> |
| 240 |
&prompt.root; <userinput>make distribution DESTDIR=$D</userinput> <co xml:id="jaildistrib"/> |
240 |
&prompt.root; <userinput>make distribution DESTDIR=$D</userinput> <co xml:id="jaildistrib"/> |
| 241 |
&prompt.root; <userinput>mount -t devfs devfs $D/dev</userinput> <co xml:id="jaildevfs"/></screen> |
241 |
&prompt.root; <userinput>mount -t devfs devfs $D/dev</userinput> <co xml:id="jaildevfs"/></screen> |
| 242 |
|
242 |
|
| 243 |
<calloutlist> |
243 |
<calloutlist> |
| 244 |
<callout arearefs="jailpath"> |
244 |
<callout arearefs="jailpath"> |
| 245 |
<para>Selecting a location for a jail is the best starting |
245 |
<para>Selecting a location for a jail is the best starting |
| 246 |
point. This is where the jail will physically reside within |
246 |
point. This is where the jail will physically reside within |
| 247 |
the file system of the jail's host. A good choice can be |
247 |
the file system of the jail's host. A good choice can be |
| 248 |
<filename |
248 |
<filename |
| 249 |
>/usr/jail/<replaceable>jailname</replaceable></filename>, |
249 |
>/usr/jail/<replaceable>jailname</replaceable></filename>, |
| 250 |
where <replaceable>jailname</replaceable> is the hostname |
250 |
where <replaceable>jailname</replaceable> is the hostname |
| 251 |
identifying the jail. Usually, <filename>/usr/</filename> |
251 |
identifying the jail. Usually, <filename>/usr/</filename> |
| 252 |
has enough space for the jail file system, which for |
252 |
has enough space for the jail file system, which for |
| 253 |
<quote>complete</quote> jails is, essentially, a replication |
253 |
<quote>complete</quote> jails is, essentially, a replication |
| 254 |
of every file present in a default installation of the &os; |
254 |
of every file present in a default installation of the &os; |
| 255 |
base system.</para> |
255 |
base system.</para> |
| 256 |
</callout> |
256 |
</callout> |
| 257 |
|
257 |
|
| 258 |
<callout arearefs="jailbuildworld"> |
258 |
<callout arearefs="jailbuildworld"> |
| 259 |
<para>If you have already rebuilt your userland using |
259 |
<para>If you have already rebuilt your userland using |
| 260 |
<command>make world</command> or |
260 |
<command>make world</command> or |
| 261 |
<command>make buildworld</command>, you can skip this step |
261 |
<command>make buildworld</command>, you can skip this step |
| 262 |
and install your existing userland into the new jail.</para> |
262 |
and install your existing userland into the new jail.</para> |
| 263 |
</callout> |
263 |
</callout> |
| 264 |
|
264 |
|
| 265 |
<callout arearefs="jailinstallworld"> |
265 |
<callout arearefs="jailinstallworld"> |
| 266 |
<para>This command will populate the directory subtree chosen |
266 |
<para>This command will populate the directory subtree chosen |
| 267 |
as jail's physical location on the file system with the |
267 |
as jail's physical location on the file system with the |
| 268 |
necessary binaries, libraries, manual pages and so |
268 |
necessary binaries, libraries, manual pages and so |
| 269 |
on.</para> |
269 |
on.</para> |
| 270 |
</callout> |
270 |
</callout> |
| 271 |
|
271 |
|
| 272 |
<callout arearefs="jaildistrib"> |
272 |
<callout arearefs="jaildistrib"> |
| 273 |
<para>The <buildtarget>distribution</buildtarget> target for |
273 |
<para>The <buildtarget>distribution</buildtarget> target for |
| 274 |
<application>make</application> installs every needed |
274 |
<application>make</application> installs every needed |
| 275 |
configuration file. In simple words, it installs every |
275 |
configuration file. In simple words, it installs every |
| 276 |
installable file of |
276 |
installable file of |
| 277 |
<filename>/usr/src/etc/</filename> to the |
277 |
<filename>/usr/src/etc/</filename> to the |
| 278 |
<filename>/etc</filename> directory of the |
278 |
<filename>/etc</filename> directory of the |
| 279 |
jail environment: |
279 |
jail environment: |
| 280 |
<filename>$D/etc/</filename>.</para> |
280 |
<filename>$D/etc/</filename>.</para> |
| 281 |
</callout> |
281 |
</callout> |
| 282 |
|
282 |
|
| 283 |
<callout arearefs="jaildevfs"> |
283 |
<callout arearefs="jaildevfs"> |
| 284 |
<para>Mounting the &man.devfs.8; file system inside a jail is |
284 |
<para>Mounting the &man.devfs.8; file system inside a jail is |
| 285 |
not required. On the other hand, any, or almost any |
285 |
not required. On the other hand, any, or almost any |
| 286 |
application requires access to at least one device, |
286 |
application requires access to at least one device, |
| 287 |
depending on the purpose of the given application. It is |
287 |
depending on the purpose of the given application. It is |
| 288 |
very important to control access to devices from inside a |
288 |
very important to control access to devices from inside a |
| 289 |
jail, as improper settings could permit an attacker to do |
289 |
jail, as improper settings could permit an attacker to do |
| 290 |
nasty things in the jail. Control over &man.devfs.8; is |
290 |
nasty things in the jail. Control over &man.devfs.8; is |
| 291 |
managed through rulesets which are described in the |
291 |
managed through rulesets which are described in the |
| 292 |
&man.devfs.8; and &man.devfs.conf.5; manual pages.</para> |
292 |
&man.devfs.8; and &man.devfs.conf.5; manual pages.</para> |
| 293 |
</callout> |
293 |
</callout> |
| 294 |
</calloutlist> |
294 |
</calloutlist> |
| 295 |
|
295 |
|
| 296 |
<para>Once a jail is installed, it can be started by using the |
296 |
<para>Once a jail is installed, it can be started by using the |
| 297 |
&man.jail.8; utility. The &man.jail.8; utility takes four |
297 |
&man.jail.8; utility. The &man.jail.8; utility takes four |
| 298 |
mandatory arguments which are described in the <xref |
298 |
mandatory arguments which are described in the <xref |
| 299 |
linkend="jails-synopsis"/>. Other arguments may be specified |
299 |
linkend="jails-synopsis"/>. Other arguments may be specified |
| 300 |
too, e.g., to run the jailed process with the credentials of a |
300 |
too, e.g., to run the jailed process with the credentials of a |
| 301 |
specific user. The |
301 |
specific user. The |
| 302 |
<option><replaceable>command</replaceable></option> argument |
302 |
<option><replaceable>command</replaceable></option> argument |
| 303 |
depends on the type of the jail; for a |
303 |
depends on the type of the jail; for a |
| 304 |
<emphasis>virtual system</emphasis>, |
304 |
<emphasis>virtual system</emphasis>, |
| 305 |
<filename>/etc/rc</filename> is a good choice, since it will |
305 |
<filename>/etc/rc</filename> is a good choice, since it will |
| 306 |
replicate the startup sequence of a real &os; system. For a |
306 |
replicate the startup sequence of a real &os; system. For a |
| 307 |
<emphasis>service</emphasis> jail, it depends on the service or |
307 |
<emphasis>service</emphasis> jail, it depends on the service or |
| 308 |
application that will run within the jail.</para> |
308 |
application that will run within the jail.</para> |
| 309 |
|
309 |
|
| 310 |
<para>Jails are often started at boot time and the &os; |
310 |
<para>Jails are often started at boot time and the &os; |
| 311 |
<filename>rc</filename> mechanism provides an easy way to do |
311 |
<filename>rc</filename> mechanism provides an easy way to do |
| 312 |
this.</para> |
312 |
this.</para> |
| 313 |
|
313 |
|
| 314 |
<procedure> |
314 |
<procedure> |
| 315 |
<step> |
315 |
<step> |
| 316 |
<para>A list of the jails which are enabled to start at boot |
316 |
<para>A list of the jails which are enabled to start at boot |
| 317 |
time should be added to the &man.rc.conf.5; file:</para> |
317 |
time should be added to the &man.rc.conf.5; file:</para> |
| 318 |
|
318 |
|
| 319 |
<programlisting>jail_enable="YES" # Set to NO to disable starting of any jails |
319 |
<programlisting>jail_enable="YES" # Set to NO to disable starting of any jails |
| 320 |
jail_list="<replaceable>www</replaceable>" # Space separated list of names of jails</programlisting> |
320 |
jail_list="<replaceable>www</replaceable>" # Space separated list of names of jails</programlisting> |
| 321 |
|
321 |
|
| 322 |
<note> |
322 |
<note> |
| 323 |
<para>Jail names in <varname>jail_list</varname> should |
323 |
<para>Jail names in <varname>jail_list</varname> should |
| 324 |
contain alphanumeric characters only.</para> |
324 |
contain alphanumeric characters only.</para> |
| 325 |
</note> |
325 |
</note> |
| 326 |
</step> |
326 |
</step> |
| 327 |
|
327 |
|
| 328 |
<step> |
328 |
<step> |
| 329 |
<para>For each jail listed in <varname>jail_list</varname>, a |
329 |
<para>For each jail listed in <varname>jail_list</varname>, a |
| 330 |
group of &man.rc.conf.5; settings, which describe the |
330 |
group of &man.rc.conf.5; settings, which describe the |
| 331 |
particular jail, should be added:</para> |
331 |
particular jail, should be added:</para> |
| 332 |
|
332 |
|
| 333 |
<programlisting>jail_<replaceable>www</replaceable>_rootdir="/usr/jail/www" # jail's root directory |
333 |
<programlisting>jail_<replaceable>www</replaceable>_rootdir="/usr/jail/www" # jail's root directory |
| 334 |
jail_<replaceable>www</replaceable>_hostname="<replaceable>www</replaceable>.example.org" # jail's hostname |
334 |
jail_<replaceable>www</replaceable>_hostname="<replaceable>www</replaceable>.example.org" # jail's hostname |
| 335 |
jail_<replaceable>www</replaceable>_ip="192.168.0.10" # jail's IP address |
335 |
jail_<replaceable>www</replaceable>_ip="192.168.0.10" # jail's IP address |
| 336 |
jail_<replaceable>www</replaceable>_devfs_enable="YES" # mount devfs in the jail</programlisting> |
336 |
jail_<replaceable>www</replaceable>_devfs_enable="YES" # mount devfs in the jail</programlisting> |
| 337 |
|
337 |
|
| 338 |
<para>The default startup of jails configured in |
338 |
<para>The default startup of jails configured in |
| 339 |
&man.rc.conf.5;, will run the <filename>/etc/rc</filename> |
339 |
&man.rc.conf.5;, will run the <filename>/etc/rc</filename> |
| 340 |
script of the jail, which assumes the jail is a complete |
340 |
script of the jail, which assumes the jail is a complete |
| 341 |
virtual system. For service jails, the default startup |
341 |
virtual system. For service jails, the default startup |
| 342 |
command of the jail should be changed, by setting the |
342 |
command of the jail should be changed, by setting the |
| 343 |
<varname>jail_<replaceable>jailname</replaceable>_exec_start</varname> |
343 |
<varname>jail_<replaceable>jailname</replaceable>_exec_start</varname> |
| 344 |
option appropriately.</para> |
344 |
option appropriately.</para> |
| 345 |
|
345 |
|
| 346 |
<note> |
346 |
<note> |
| 347 |
<para>For a full list of available options, please see the |
347 |
<para>For a full list of available options, please see the |
| 348 |
&man.rc.conf.5; manual page.</para> |
348 |
&man.rc.conf.5; manual page.</para> |
| 349 |
</note> |
349 |
</note> |
| 350 |
</step> |
350 |
</step> |
| 351 |
</procedure> |
351 |
</procedure> |
| 352 |
|
352 |
|
| 353 |
<para>&man.service.8; can be used to start or stop a jail by hand, |
353 |
<para>&man.service.8; can be used to start or stop a jail by hand, |
| 354 |
if an entry for it exists in |
354 |
if an entry for it exists in |
| 355 |
<filename>rc.conf</filename>:</para> |
355 |
<filename>rc.conf</filename>:</para> |
| 356 |
|
356 |
|
| 357 |
<screen>&prompt.root; <userinput>service jail start <replaceable>www</replaceable></userinput> |
357 |
<screen>&prompt.root; <userinput>service jail start <replaceable>www</replaceable></userinput> |
| 358 |
&prompt.root; <userinput>service jail stop <replaceable>www</replaceable></userinput></screen> |
358 |
&prompt.root; <userinput>service jail stop <replaceable>www</replaceable></userinput></screen> |
| 359 |
|
359 |
|
| 360 |
<para>Jails can be shut down with &man.jexec.8;. Use &man.jls.8; |
360 |
<para>Jails can be shut down with &man.jexec.8;. Use &man.jls.8; |
| 361 |
to identify the jail's <varname>JID</varname>, then use |
361 |
to identify the jail's <varname>JID</varname>, then use |
| 362 |
&man.jexec.8; to run the shutdown script in that jail.</para> |
362 |
&man.jexec.8; to run the shutdown script in that jail.</para> |
| 363 |
|
363 |
|
| 364 |
<screen>&prompt.root; <userinput>jls</userinput> |
364 |
<screen>&prompt.root; <userinput>jls</userinput> |
| 365 |
JID IP Address Hostname Path |
365 |
JID IP Address Hostname Path |
| 366 |
3 192.168.0.10 www /usr/jail/www |
366 |
3 192.168.0.10 www /usr/jail/www |
| 367 |
&prompt.root; <userinput>jexec <replaceable>3</replaceable> /etc/rc.shutdown</userinput></screen> |
367 |
&prompt.root; <userinput>jexec <replaceable>3</replaceable> /etc/rc.shutdown</userinput></screen> |
| 368 |
|
368 |
|
| 369 |
<para>More information about this can be found in the &man.jail.8; |
369 |
<para>More information about this can be found in the &man.jail.8; |
| 370 |
manual page.</para> |
370 |
manual page.</para> |
| 371 |
</sect1> |
371 |
</sect1> |
| 372 |
|
372 |
|
| 373 |
<sect1 xml:id="jails-tuning"> |
373 |
<sect1 xml:id="jails-tuning"> |
| 374 |
<title>Fine Tuning and Administration</title> |
374 |
<title>Fine Tuning and Administration</title> |
| 375 |
|
375 |
|
| 376 |
<para>There are several options which can be set for any jail, and |
376 |
<para>There are several options which can be set for any jail, and |
| 377 |
various ways of combining a host &os; system with jails, to |
377 |
various ways of combining a host &os; system with jails, to |
| 378 |
produce higher level applications. This section |
378 |
produce higher level applications. This section |
| 379 |
presents:</para> |
379 |
presents:</para> |
| 380 |
|
380 |
|
| 381 |
<itemizedlist> |
381 |
<itemizedlist> |
| 382 |
<listitem> |
382 |
<listitem> |
| 383 |
<para>Some of the options available for tuning the behavior |
383 |
<para>Some of the options available for tuning the behavior |
| 384 |
and security restrictions implemented by a jail |
384 |
and security restrictions implemented by a jail |
| 385 |
installation.</para> |
385 |
installation.</para> |
| 386 |
</listitem> |
386 |
</listitem> |
| 387 |
|
387 |
|
| 388 |
<listitem> |
388 |
<listitem> |
| 389 |
<para>Some of the high-level applications for jail management, |
389 |
<para>Some of the high-level applications for jail management, |
| 390 |
which are available through the &os; Ports Collection, and |
390 |
which are available through the &os; Ports Collection, and |
| 391 |
can be used to implement overall jail-based |
391 |
can be used to implement overall jail-based |
| 392 |
solutions.</para> |
392 |
solutions.</para> |
| 393 |
</listitem> |
393 |
</listitem> |
| 394 |
</itemizedlist> |
394 |
</itemizedlist> |
| 395 |
|
395 |
|
| 396 |
<sect2 xml:id="jails-tuning-utilities"> |
396 |
<sect2 xml:id="jails-tuning-utilities"> |
| 397 |
<title>System Tools for Jail Tuning in &os;</title> |
397 |
<title>System Tools for Jail Tuning in &os;</title> |
| 398 |
|
398 |
|
| 399 |
<para>Fine tuning of a jail's configuration is mostly done by |
399 |
<para>Fine tuning of a jail's configuration is mostly done by |
| 400 |
setting &man.sysctl.8; variables. A special subtree of sysctl |
400 |
setting &man.sysctl.8; variables. A special subtree of sysctl |
| 401 |
exists as a basis for organizing all the relevant options: the |
401 |
exists as a basis for organizing all the relevant options: the |
| 402 |
<varname>security.jail.*</varname> hierarchy of &os; kernel |
402 |
<varname>security.jail.*</varname> hierarchy of &os; kernel |
| 403 |
options. Here is a list of the main jail-related sysctls, |
403 |
options. Here is a list of the main jail-related sysctls, |
| 404 |
complete with their default value. Names should be |
404 |
complete with their default value. Names should be |
| 405 |
self-explanatory, but for more information about them, please |
405 |
self-explanatory, but for more information about them, please |
| 406 |
refer to the &man.jail.8; and &man.sysctl.8; manual |
406 |
refer to the &man.jail.8; and &man.sysctl.8; manual |
| 407 |
pages.</para> |
407 |
pages.</para> |
| 408 |
|
408 |
|
| 409 |
<itemizedlist> |
409 |
<itemizedlist> |
| 410 |
<listitem> |
410 |
<listitem> |
| 411 |
<para><varname>security.jail.set_hostname_allowed: |
411 |
<para><varname>security.jail.set_hostname_allowed: |
| 412 |
1</varname></para> |
412 |
1</varname></para> |
| 413 |
</listitem> |
413 |
</listitem> |
| 414 |
|
414 |
|
| 415 |
<listitem> |
415 |
<listitem> |
| 416 |
<para><varname>security.jail.socket_unixiproute_only: |
416 |
<para><varname>security.jail.socket_unixiproute_only: |
| 417 |
1</varname></para> |
417 |
1</varname></para> |
| 418 |
</listitem> |
418 |
</listitem> |
| 419 |
|
419 |
|
| 420 |
<listitem> |
420 |
<listitem> |
| 421 |
<para><varname>security.jail.sysvipc_allowed: |
421 |
<para><varname>security.jail.sysvipc_allowed: |
| 422 |
0</varname></para> |
422 |
0</varname></para> |
| 423 |
</listitem> |
423 |
</listitem> |
| 424 |
|
424 |
|
| 425 |
<listitem> |
425 |
<listitem> |
| 426 |
<para><varname>security.jail.enforce_statfs: |
426 |
<para><varname>security.jail.enforce_statfs: |
| 427 |
2</varname></para> |
427 |
2</varname></para> |
| 428 |
</listitem> |
428 |
</listitem> |
| 429 |
|
429 |
|
| 430 |
<listitem> |
430 |
<listitem> |
| 431 |
<para><varname>security.jail.allow_raw_sockets: |
431 |
<para><varname>security.jail.allow_raw_sockets: |
| 432 |
0</varname></para> |
432 |
0</varname></para> |
| 433 |
</listitem> |
433 |
</listitem> |
| 434 |
|
434 |
|
| 435 |
<listitem> |
435 |
<listitem> |
| 436 |
<para><varname>security.jail.chflags_allowed: |
436 |
<para><varname>security.jail.chflags_allowed: |
| 437 |
0</varname></para> |
437 |
0</varname></para> |
| 438 |
</listitem> |
438 |
</listitem> |
| 439 |
|
439 |
|
| 440 |
<listitem> |
440 |
<listitem> |
| 441 |
<para><varname>security.jail.jailed: 0</varname></para> |
441 |
<para><varname>security.jail.jailed: 0</varname></para> |
| 442 |
</listitem> |
442 |
</listitem> |
| 443 |
</itemizedlist> |
443 |
</itemizedlist> |
| 444 |
|
444 |
|
| 445 |
<para>These variables can be used by the system administrator of |
445 |
<para>These variables can be used by the system administrator of |
| 446 |
the <emphasis>host system</emphasis> to add or remove some of |
446 |
the <emphasis>host system</emphasis> to add or remove some of |
| 447 |
the limitations imposed by default on the <systemitem |
447 |
the limitations imposed by default on the <systemitem |
| 448 |
class="username">root</systemitem> user. Note that there |
448 |
class="username">root</systemitem> user. Note that there |
| 449 |
are some limitations which cannot be removed. The |
449 |
are some limitations which cannot be removed. The |
| 450 |
<systemitem class="username">root</systemitem> user is not |
450 |
<systemitem class="username">root</systemitem> user is not |
| 451 |
allowed to mount or unmount file systems from within a |
451 |
allowed to mount or unmount file systems from within a |
| 452 |
&man.jail.8;. The <systemitem |
452 |
&man.jail.8;. The <systemitem |
| 453 |
class="username">root</systemitem> inside a jail may not |
453 |
class="username">root</systemitem> inside a jail may not |
| 454 |
load or unload &man.devfs.8; rulesets, set firewall rules, or |
454 |
load or unload &man.devfs.8; rulesets, set firewall rules, or |
| 455 |
do many other administrative tasks which require modifications |
455 |
do many other administrative tasks which require modifications |
| 456 |
of in-kernel data, such as setting the |
456 |
of in-kernel data, such as setting the |
| 457 |
<varname>securelevel</varname> of the kernel.</para> |
457 |
<varname>securelevel</varname> of the kernel.</para> |
| 458 |
|
458 |
|
| 459 |
<para>The base system of &os; contains a basic set of tools for |
459 |
<para>The base system of &os; contains a basic set of tools for |
| 460 |
viewing information about the active jails, and attaching to a |
460 |
viewing information about the active jails, and attaching to a |
| 461 |
jail to run administrative commands. The &man.jls.8; and |
461 |
jail to run administrative commands. The &man.jls.8; and |
| 462 |
&man.jexec.8; commands are part of the base &os; system, and |
462 |
&man.jexec.8; commands are part of the base &os; system, and |
| 463 |
can be used to perform the following simple tasks:</para> |
463 |
can be used to perform the following simple tasks:</para> |
| 464 |
|
464 |
|
| 465 |
<itemizedlist> |
465 |
<itemizedlist> |
| 466 |
<listitem> |
466 |
<listitem> |
| 467 |
<para>Print a list of active jails and their corresponding |
467 |
<para>Print a list of active jails and their corresponding |
| 468 |
jail identifier (<acronym>JID</acronym>), |
468 |
jail identifier (<acronym>JID</acronym>), |
| 469 |
<acronym>IP</acronym> address, hostname and path.</para> |
469 |
<acronym>IP</acronym> address, hostname and path.</para> |
| 470 |
</listitem> |
470 |
</listitem> |
| 471 |
|
471 |
|
| 472 |
<listitem> |
472 |
<listitem> |
| 473 |
<para>Attach to a running jail, from its host system, and |
473 |
<para>Attach to a running jail, from its host system, and |
| 474 |
run a command inside the jail or perform administrative |
474 |
run a command inside the jail or perform administrative |
| 475 |
tasks inside the jail itself. This is especially useful |
475 |
tasks inside the jail itself. This is especially useful |
| 476 |
when the <systemitem class="username">root</systemitem> |
476 |
when the <systemitem class="username">root</systemitem> |
| 477 |
user wants to cleanly shut down a jail. The &man.jexec.8; |
477 |
user wants to cleanly shut down a jail. The &man.jexec.8; |
| 478 |
utility can also be used to start a shell in a jail to do |
478 |
utility can also be used to start a shell in a jail to do |
| 479 |
administration in it; for example:</para> |
479 |
administration in it; for example:</para> |
| 480 |
|
480 |
|
| 481 |
<screen>&prompt.root; <userinput>jexec <replaceable>1</replaceable> tcsh</userinput></screen> |
481 |
<screen>&prompt.root; <userinput>jexec <replaceable>1</replaceable> tcsh</userinput></screen> |
| 482 |
</listitem> |
482 |
</listitem> |
| 483 |
</itemizedlist> |
483 |
</itemizedlist> |
| 484 |
</sect2> |
484 |
</sect2> |
| 485 |
|
485 |
|
| 486 |
<sect2 xml:id="jails-tuning-admintools"> |
486 |
<sect2 xml:id="jails-tuning-admintools"> |
| 487 |
<title>High-Level Administrative Tools in the &os; Ports |
487 |
<title>High-Level Administrative Tools in the &os; Ports |
| 488 |
Collection</title> |
488 |
Collection</title> |
| 489 |
|
489 |
|
| 490 |
<para>Among the many third-party utilities for jail |
490 |
<para>Among the many third-party utilities for jail |
| 491 |
administration, one of the most complete and useful is |
491 |
administration, one of the most complete and useful is |
| 492 |
<package>sysutils/ezjail</package>. It is a set of scripts |
492 |
<package>sysutils/ezjail</package>. It is a set of scripts |
| 493 |
that contribute to &man.jail.8; management. Please refer to |
493 |
that contribute to &man.jail.8; management. Please refer to |
| 494 |
<link xlink:href="&url.books.handbook;/jails-ezjail.html">the |
494 |
<link xlink:href="&url.books.handbook;/jails-ezjail.html">the |
| 495 |
handbook section on <application>ezjail</application></link> |
495 |
handbook section on <application>ezjail</application></link> |
| 496 |
for more information.</para> |
496 |
for more information.</para> |
| 497 |
</sect2> |
497 |
</sect2> |
| 498 |
|
498 |
|
| 499 |
<sect2 xml:id="jails-updating"> |
499 |
<sect2 xml:id="jails-updating"> |
| 500 |
<title>Keeping Jails Patched and up to Date</title> |
500 |
<title>Keeping Jails Patched and up to Date</title> |
| 501 |
|
501 |
|
| 502 |
<para>Jails should be kept up to date from the host operating |
502 |
<para>Jails should be kept up to date from the host operating |
| 503 |
system as attempting to patch userland from within the jail |
503 |
system as attempting to patch userland from within the jail |
| 504 |
may likely fail as the default behaviour in FreeBSD is to |
504 |
may likely fail as the default behaviour in FreeBSD is to |
| 505 |
disallow the use of &man.chflags.1; in a jail which prevents |
505 |
disallow the use of &man.chflags.1; in a jail which prevents |
| 506 |
the replacement of some files. It is possible to change this |
506 |
the replacement of some files. It is possible to change this |
| 507 |
behavior but it is recommended to use &man.freebsd-update.8; |
507 |
behavior but it is recommended to use &man.freebsd-update.8; |
| 508 |
to maintain jails instead. Use <option>-b</option> to specify |
508 |
to maintain jails instead. Use <option>-b</option> to specify |
| 509 |
the path of the jail to be updated.</para> |
509 |
the path of the jail to be updated.</para> |
| 510 |
|
510 |
|
| 511 |
<screen>&prompt.root; <userinput>freebsd-update -b <replaceable>/here/is/the/jail</replaceable> fetch</userinput> |
511 |
<screen>&prompt.root; <userinput>freebsd-update -b <replaceable>/here/is/the/jail</replaceable> fetch</userinput> |
| 512 |
&prompt.root; <userinput>freebsd-update -b <replaceable>/here/is/the/jail</replaceable> install</userinput></screen> |
512 |
&prompt.root; <userinput>freebsd-update -b <replaceable>/here/is/the/jail</replaceable> install</userinput></screen> |
| 513 |
</sect2> |
513 |
</sect2> |
| 514 |
</sect1> |
514 |
</sect1> |
| 515 |
|
515 |
|
| 516 |
<sect1 xml:id="jails-application"> |
516 |
<sect1 xml:id="jails-application"> |
| 517 |
<info> |
517 |
<info> |
| 518 |
<title>Updating Multiple Jails</title> |
518 |
<title>Updating Multiple Jails</title> |
| 519 |
|
519 |
|
| 520 |
<authorgroup> |
520 |
<authorgroup> |
| 521 |
<author> |
521 |
<author> |
| 522 |
<personname> |
522 |
<personname> |
| 523 |
<firstname>Daniel</firstname> |
523 |
<firstname>Daniel</firstname> |
| 524 |
<surname>Gerzo</surname> |
524 |
<surname>Gerzo</surname> |
| 525 |
</personname> |
525 |
</personname> |
| 526 |
<contrib>Contributed by </contrib> |
526 |
<contrib>Contributed by </contrib> |
| 527 |
</author> |
527 |
</author> |
| 528 |
</authorgroup> |
528 |
</authorgroup> |
| 529 |
<authorgroup> |
529 |
<authorgroup> |
| 530 |
<author> |
530 |
<author> |
| 531 |
<personname> |
531 |
<personname> |
| 532 |
<firstname>Simon</firstname> |
532 |
<firstname>Simon</firstname> |
| 533 |
<surname>L. B. Nielsen</surname> |
533 |
<surname>L. B. Nielsen</surname> |
| 534 |
</personname> |
534 |
</personname> |
| 535 |
<contrib>Based upon an idea presented by </contrib> |
535 |
<contrib>Based upon an idea presented by </contrib> |
| 536 |
</author> |
536 |
</author> |
| 537 |
</authorgroup> |
537 |
</authorgroup> |
| 538 |
<authorgroup> |
538 |
<authorgroup> |
| 539 |
<author> |
539 |
<author> |
| 540 |
<personname> |
540 |
<personname> |
| 541 |
<firstname>Ken</firstname> |
541 |
<firstname>Ken</firstname> |
| 542 |
<surname>Tom</surname> |
542 |
<surname>Tom</surname> |
| 543 |
</personname> |
543 |
</personname> |
| 544 |
<contrib>And an article written by </contrib> |
544 |
<contrib>And an article written by </contrib> |
| 545 |
</author> |
545 |
</author> |
| 546 |
</authorgroup> |
546 |
</authorgroup> |
| 547 |
</info> |
547 |
</info> |
| 548 |
|
548 |
|
| 549 |
<para>The management of multiple jails can become problematic |
549 |
<para>The management of multiple jails can become problematic |
| 550 |
because every jail has to be rebuilt from scratch whenever it is |
550 |
because every jail has to be rebuilt from scratch whenever it is |
| 551 |
upgraded. This can be time consuming and tedious if a lot of |
551 |
upgraded. This can be time consuming and tedious if a lot of |
| 552 |
jails are created and manually updated.</para> |
552 |
jails are created and manually updated.</para> |
| 553 |
|
553 |
|
| 554 |
<para>This section demonstrates one method to resolve this issue |
554 |
<para>This section demonstrates one method to resolve this issue |
| 555 |
by safely sharing as much as is possible between jails using |
555 |
by safely sharing as much as is possible between jails using |
| 556 |
read-only &man.mount.nullfs.8; mounts, so that updating is |
556 |
read-only &man.mount.nullfs.8; mounts, so that updating is |
| 557 |
simpler. This makes it more attractive to put single services, |
557 |
simpler. This makes it more attractive to put single services, |
| 558 |
such as <acronym>HTTP</acronym>, <acronym>DNS</acronym>, and |
558 |
such as <acronym>HTTP</acronym>, <acronym>DNS</acronym>, and |
| 559 |
<acronym>SMTP</acronym>, into individual jails. Additionally, |
559 |
<acronym>SMTP</acronym>, into individual jails. Additionally, |
| 560 |
it provides a simple way to add, remove, and upgrade |
560 |
it provides a simple way to add, remove, and upgrade |
| 561 |
jails.</para> |
561 |
jails.</para> |
| 562 |
|
562 |
|
| 563 |
<note> |
563 |
<note> |
| 564 |
<para>Simpler solutions exist, such as |
564 |
<para>Simpler solutions exist, such as |
| 565 |
<application>ezjail</application>, which provides an easier |
565 |
<application>ezjail</application>, which provides an easier |
| 566 |
method of administering &os; jails but is less versatile than |
566 |
method of administering &os; jails but is less versatile than |
| 567 |
this setup. <application>ezjail</application> is covered in |
567 |
this setup. <application>ezjail</application> is covered in |
| 568 |
more detail in <xref linkend="jails-ezjail"/>.</para> |
568 |
more detail in <xref linkend="jails-ezjail"/>.</para> |
| 569 |
</note> |
569 |
</note> |
| 570 |
|
570 |
|
| 571 |
<para>The goals of the setup described in this section are:</para> |
571 |
<para>The goals of the setup described in this section are:</para> |
| 572 |
|
572 |
|
| 573 |
<itemizedlist> |
573 |
<itemizedlist> |
| 574 |
<listitem> |
574 |
<listitem> |
| 575 |
<para>Create a simple and easy to understand jail structure |
575 |
<para>Create a simple and easy to understand jail structure |
| 576 |
that does not require running a full installworld on each |
576 |
that does not require running a full installworld on each |
| 577 |
and every jail.</para> |
577 |
and every jail.</para> |
| 578 |
</listitem> |
578 |
</listitem> |
| 579 |
|
579 |
|
| 580 |
<listitem> |
580 |
<listitem> |
| 581 |
<para>Make it easy to add new jails or remove existing |
581 |
<para>Make it easy to add new jails or remove existing |
| 582 |
ones.</para> |
582 |
ones.</para> |
| 583 |
</listitem> |
583 |
</listitem> |
| 584 |
|
584 |
|
| 585 |
<listitem> |
585 |
<listitem> |
| 586 |
<para>Make it easy to update or upgrade existing jails.</para> |
586 |
<para>Make it easy to update or upgrade existing jails.</para> |
| 587 |
</listitem> |
587 |
</listitem> |
| 588 |
|
588 |
|
| 589 |
<listitem> |
589 |
<listitem> |
| 590 |
<para>Make it possible to run a customized &os; branch.</para> |
590 |
<para>Make it possible to run a customized &os; branch.</para> |
| 591 |
</listitem> |
591 |
</listitem> |
| 592 |
|
592 |
|
| 593 |
<listitem> |
593 |
<listitem> |
| 594 |
<para>Be paranoid about security, reducing as much as |
594 |
<para>Be paranoid about security, reducing as much as |
| 595 |
possible the possibility of compromise.</para> |
595 |
possible the possibility of compromise.</para> |
| 596 |
</listitem> |
596 |
</listitem> |
| 597 |
|
597 |
|
| 598 |
<listitem> |
598 |
<listitem> |
| 599 |
<para>Save space and inodes, as much as possible.</para> |
599 |
<para>Save space and inodes, as much as possible.</para> |
| 600 |
</listitem> |
600 |
</listitem> |
| 601 |
</itemizedlist> |
601 |
</itemizedlist> |
| 602 |
|
602 |
|
| 603 |
<para>This design relies on a single, read-only master template |
603 |
<para>This design relies on a single, read-only master template |
| 604 |
which is mounted into each jail and one read-write device per |
604 |
which is mounted into each jail and one read-write device per |
| 605 |
jail. A device can be a separate physical disc, a partition, or |
605 |
jail. A device can be a separate physical disc, a partition, or |
| 606 |
a vnode backed memory device. This example uses read-write |
606 |
a vnode backed memory device. This example uses read-write |
| 607 |
<application>nullfs</application> mounts.</para> |
607 |
<application>nullfs</application> mounts.</para> |
| 608 |
|
608 |
|
| 609 |
<para>The file system layout is as follows:</para> |
609 |
<para>The file system layout is as follows:</para> |
| 610 |
|
610 |
|
| 611 |
<itemizedlist> |
611 |
<itemizedlist> |
| 612 |
<listitem> |
612 |
<listitem> |
| 613 |
<para>The jails are based under the |
613 |
<para>The jails are based under the |
| 614 |
<filename>/home</filename> partition.</para> |
614 |
<filename>/home</filename> partition.</para> |
| 615 |
</listitem> |
615 |
</listitem> |
| 616 |
|
616 |
|
| 617 |
<listitem> |
617 |
<listitem> |
| 618 |
<para>Each jail will be mounted under the |
618 |
<para>Each jail will be mounted under the |
| 619 |
<filename>/home/j</filename> directory.</para> |
619 |
<filename>/home/j</filename> directory.</para> |
| 620 |
</listitem> |
620 |
</listitem> |
| 621 |
|
621 |
|
| 622 |
<listitem> |
622 |
<listitem> |
| 623 |
<para>The template for each jail and the read-only partition |
623 |
<para>The template for each jail and the read-only partition |
| 624 |
for all of the jails is |
624 |
for all of the jails is |
| 625 |
<filename>/home/j/mroot</filename>.</para> |
625 |
<filename>/home/j/mroot</filename>.</para> |
| 626 |
</listitem> |
626 |
</listitem> |
| 627 |
|
627 |
|
| 628 |
<listitem> |
628 |
<listitem> |
| 629 |
<para>A blank directory will be created for each jail under |
629 |
<para>A blank directory will be created for each jail under |
| 630 |
the <filename>/home/j</filename> directory.</para> |
630 |
the <filename>/home/j</filename> directory.</para> |
| 631 |
</listitem> |
631 |
</listitem> |
| 632 |
|
632 |
|
| 633 |
<listitem> |
633 |
<listitem> |
| 634 |
<para>Each jail will have a <filename>/s</filename> directory |
634 |
<para>Each jail will have a <filename>/s</filename> directory |
| 635 |
that will be linked to the read-write portion of the |
635 |
that will be linked to the read-write portion of the |
| 636 |
system.</para> |
636 |
system.</para> |
| 637 |
</listitem> |
637 |
</listitem> |
| 638 |
|
638 |
|
| 639 |
<listitem> |
639 |
<listitem> |
| 640 |
<para>Each jail will have its own read-write system that is |
640 |
<para>Each jail will have its own read-write system that is |
| 641 |
based upon <filename>/home/j/skel</filename>.</para> |
641 |
based upon <filename>/home/j/skel</filename>.</para> |
| 642 |
</listitem> |
642 |
</listitem> |
| 643 |
|
643 |
|
| 644 |
<listitem> |
644 |
<listitem> |
| 645 |
<para>The read-write portion of each jail will be created in |
645 |
<para>The read-write portion of each jail will be created in |
| 646 |
<filename>/home/js</filename>.</para> |
646 |
<filename>/home/js</filename>.</para> |
| 647 |
</listitem> |
647 |
</listitem> |
| 648 |
</itemizedlist> |
648 |
</itemizedlist> |
| 649 |
|
649 |
|
| 650 |
<!-- Insert an image or drawing here to illustrate the example. --> |
650 |
<!-- Insert an image or drawing here to illustrate the example. --> |
| 651 |
|
651 |
|
| 652 |
<sect2 xml:id="jails-service-jails-template"> |
652 |
<sect2 xml:id="jails-service-jails-template"> |
| 653 |
<title>Creating the Template</title> |
653 |
<title>Creating the Template</title> |
| 654 |
|
654 |
|
| 655 |
<para>This section describes the steps needed to create the |
655 |
<para>This section describes the steps needed to create the |
| 656 |
master template.</para> |
656 |
master template.</para> |
| 657 |
|
657 |
|
| 658 |
<para>It is recommended to first update the host &os; system to |
658 |
<para>It is recommended to first update the host &os; system to |
| 659 |
the latest -RELEASE branch using the instructions in <xref |
659 |
the latest -RELEASE branch using the instructions in <xref |
| 660 |
linkend="makeworld"/>. Additionally, this template uses the |
660 |
linkend="makeworld"/>. Additionally, this template uses the |
| 661 |
<package>sysutils/cpdup</package> package or port and |
661 |
<package>sysutils/cpdup</package> package or port and |
| 662 |
<application>portsnap</application> will be used to download |
662 |
<application>portsnap</application> will be used to download |
| 663 |
the &os; Ports Collection.</para> |
663 |
the &os; Ports Collection.</para> |
| 664 |
|
664 |
|
| 665 |
<procedure> |
665 |
<procedure> |
| 666 |
<step> |
666 |
<step> |
| 667 |
<para>First, create a directory structure for the read-only |
667 |
<para>First, create a directory structure for the read-only |
| 668 |
file system which will contain the &os; binaries for the |
668 |
file system which will contain the &os; binaries for the |
| 669 |
jails. Then, change directory to the &os; source tree and |
669 |
jails. Then, change directory to the &os; source tree and |
| 670 |
install the read-only file system to the jail |
670 |
install the read-only file system to the jail |
| 671 |
template:</para> |
671 |
template:</para> |
| 672 |
|
672 |
|
| 673 |
<screen>&prompt.root; <userinput>mkdir /home/j /home/j/mroot</userinput> |
673 |
<screen>&prompt.root; <userinput>mkdir /home/j /home/j/mroot</userinput> |
| 674 |
&prompt.root; <userinput>cd /usr/src</userinput> |
674 |
&prompt.root; <userinput>cd /usr/src</userinput> |
| 675 |
&prompt.root; <userinput>make installworld DESTDIR=/home/j/mroot</userinput></screen> |
675 |
&prompt.root; <userinput>make installworld DESTDIR=/home/j/mroot</userinput></screen> |
| 676 |
</step> |
676 |
</step> |
| 677 |
|
677 |
|
| 678 |
<step> |
678 |
<step> |
| 679 |
<para>Next, prepare a &os; Ports Collection for the jails as |
679 |
<para>Next, prepare a &os; Ports Collection for the jails as |
| 680 |
well as a &os; source tree, which is required for |
680 |
well as a &os; source tree, which is required for |
| 681 |
<application>mergemaster</application>:</para> |
681 |
<application>mergemaster</application>:</para> |
| 682 |
|
682 |
|
| 683 |
<screen>&prompt.root; <userinput>cd /home/j/mroot</userinput> |
683 |
<screen>&prompt.root; <userinput>cd /home/j/mroot</userinput> |
| 684 |
&prompt.root; <userinput>mkdir usr/ports</userinput> |
684 |
&prompt.root; <userinput>mkdir usr/ports</userinput> |
| 685 |
&prompt.root; <userinput>portsnap -p /home/j/mroot/usr/ports fetch extract</userinput> |
685 |
&prompt.root; <userinput>portsnap -p /home/j/mroot/usr/ports fetch extract</userinput> |
| 686 |
&prompt.root; <userinput>cpdup /usr/src /home/j/mroot/usr/src</userinput></screen> |
686 |
&prompt.root; <userinput>cpdup /usr/src /home/j/mroot/usr/src</userinput></screen> |
| 687 |
</step> |
687 |
</step> |
| 688 |
|
688 |
|
| 689 |
<step> |
689 |
<step> |
| 690 |
<para>Create a skeleton for the read-write portion of the |
690 |
<para>Create a skeleton for the read-write portion of the |
| 691 |
system:</para> |
691 |
system:</para> |
| 692 |
|
692 |
|
| 693 |
<screen>&prompt.root; <userinput>mkdir /home/j/skel /home/j/skel/home /home/j/skel/usr-X11R6 /home/j/skel/distfiles</userinput> |
693 |
<screen>&prompt.root; <userinput>mkdir /home/j/skel /home/j/skel/home /home/j/skel/usr-X11R6 /home/j/skel/distfiles</userinput> |
| 694 |
&prompt.root; <userinput>mv etc /home/j/skel</userinput> |
694 |
&prompt.root; <userinput>mv etc /home/j/skel</userinput> |
| 695 |
&prompt.root; <userinput>mv usr/local /home/j/skel/usr-local</userinput> |
695 |
&prompt.root; <userinput>mv usr/local /home/j/skel/usr-local</userinput> |
| 696 |
&prompt.root; <userinput>mv tmp /home/j/skel</userinput> |
696 |
&prompt.root; <userinput>mv tmp /home/j/skel</userinput> |
| 697 |
&prompt.root; <userinput>mv var /home/j/skel</userinput> |
697 |
&prompt.root; <userinput>mv var /home/j/skel</userinput> |
| 698 |
&prompt.root; <userinput>mv root /home/j/skel</userinput></screen> |
698 |
&prompt.root; <userinput>mv root /home/j/skel</userinput></screen> |
| 699 |
</step> |
699 |
</step> |
| 700 |
|
700 |
|
| 701 |
<step> |
701 |
<step> |
| 702 |
<para>Use <application>mergemaster</application> to install |
702 |
<para>Use <application>mergemaster</application> to install |
| 703 |
missing configuration files. Then, remove the extra |
703 |
missing configuration files. Then, remove the extra |
| 704 |
directories that <application>mergemaster</application> |
704 |
directories that <application>mergemaster</application> |
| 705 |
creates:</para> |
705 |
creates:</para> |
| 706 |
|
706 |
|
| 707 |
<screen>&prompt.root; <userinput>mergemaster -t /home/j/skel/var/tmp/temproot -D /home/j/skel -i</userinput> |
707 |
<screen>&prompt.root; <userinput>mergemaster -t /home/j/skel/var/tmp/temproot -D /home/j/skel -i</userinput> |
| 708 |
&prompt.root; <userinput>cd /home/j/skel</userinput> |
708 |
&prompt.root; <userinput>cd /home/j/skel</userinput> |
| 709 |
&prompt.root; <userinput>rm -R bin boot lib libexec mnt proc rescue sbin sys usr dev</userinput></screen> |
709 |
&prompt.root; <userinput>rm -R bin boot lib libexec mnt proc rescue sbin sys usr dev</userinput></screen> |
| 710 |
</step> |
710 |
</step> |
| 711 |
|
711 |
|
| 712 |
<step> |
712 |
<step> |
| 713 |
<para>Now, symlink the read-write file system to the |
713 |
<para>Now, symlink the read-write file system to the |
| 714 |
read-only file system. Ensure that the symlinks are |
714 |
read-only file system. Ensure that the symlinks are |
| 715 |
created in the correct <filename>s/</filename> locations |
715 |
created in the correct <filename>s/</filename> locations |
| 716 |
as the creation of directories in the wrong locations will |
716 |
as the creation of directories in the wrong locations will |
| 717 |
cause the installation to fail.</para> |
717 |
cause the installation to fail.</para> |
| 718 |
|
718 |
|
| 719 |
<screen>&prompt.root; <userinput>cd /home/j/mroot</userinput> |
719 |
<screen>&prompt.root; <userinput>cd /home/j/mroot</userinput> |
| 720 |
&prompt.root; <userinput>mkdir s</userinput> |
720 |
&prompt.root; <userinput>mkdir s</userinput> |
| 721 |
&prompt.root; <userinput>ln -s s/etc etc</userinput> |
721 |
&prompt.root; <userinput>ln -s s/etc etc</userinput> |
| 722 |
&prompt.root; <userinput>ln -s s/home home</userinput> |
722 |
&prompt.root; <userinput>ln -s s/home home</userinput> |
| 723 |
&prompt.root; <userinput>ln -s s/root root</userinput> |
723 |
&prompt.root; <userinput>ln -s s/root root</userinput> |
| 724 |
&prompt.root; <userinput>ln -s s/usr-local usr/local</userinput> |
724 |
&prompt.root; <userinput>ln -s s/usr-local usr/local</userinput> |
| 725 |
&prompt.root; <userinput>ln -s s/usr-X11R6 usr/X11R6</userinput> |
725 |
&prompt.root; <userinput>ln -s s/usr-X11R6 usr/X11R6</userinput> |
| 726 |
&prompt.root; <userinput>ln -s s/distfiles usr/ports/distfiles</userinput> |
726 |
&prompt.root; <userinput>ln -s s/distfiles usr/ports/distfiles</userinput> |
| 727 |
&prompt.root; <userinput>ln -s s/tmp tmp</userinput> |
727 |
&prompt.root; <userinput>ln -s s/tmp tmp</userinput> |
| 728 |
&prompt.root; <userinput>ln -s s/var var</userinput></screen> |
728 |
&prompt.root; <userinput>ln -s s/var var</userinput></screen> |
| 729 |
</step> |
729 |
</step> |
| 730 |
|
730 |
|
| 731 |
<step> |
731 |
<step> |
| 732 |
<para>As a last step, create a generic |
732 |
<para>As a last step, create a generic |
| 733 |
<filename>/home/j/skel/etc/make.conf</filename> containing |
733 |
<filename>/home/j/skel/etc/make.conf</filename> containing |
| 734 |
this line:</para> |
734 |
this line:</para> |
| 735 |
|
735 |
|
| 736 |
<programlisting>WRKDIRPREFIX?= /s/portbuild</programlisting> |
736 |
<programlisting>WRKDIRPREFIX?= /s/portbuild</programlisting> |
| 737 |
|
737 |
|
| 738 |
<para>This makes it possible to compile &os; ports inside |
738 |
<para>This makes it possible to compile &os; ports inside |
| 739 |
each jail. Remember that the ports directory is part of |
739 |
each jail. Remember that the ports directory is part of |
| 740 |
the read-only system. The custom path for |
740 |
the read-only system. The custom path for |
| 741 |
<literal>WRKDIRPREFIX</literal> allows builds to be done |
741 |
<literal>WRKDIRPREFIX</literal> allows builds to be done |
| 742 |
in the read-write portion of every jail.</para> |
742 |
in the read-write portion of every jail.</para> |
| 743 |
</step> |
743 |
</step> |
| 744 |
</procedure> |
744 |
</procedure> |
| 745 |
</sect2> |
745 |
</sect2> |
| 746 |
|
746 |
|
| 747 |
<sect2 xml:id="jails-service-jails-creating"> |
747 |
<sect2 xml:id="jails-service-jails-creating"> |
| 748 |
<title>Creating Jails</title> |
748 |
<title>Creating Jails</title> |
| 749 |
|
749 |
|
| 750 |
<para>The jail template can now be used to setup and configure |
750 |
<para>The jail template can now be used to setup and configure |
| 751 |
the jails in <filename>/etc/rc.conf</filename>. This example |
751 |
the jails in <filename>/etc/rc.conf</filename>. This example |
| 752 |
demonstrates the creation of 3 jails: <literal>NS</literal>, |
752 |
demonstrates the creation of 3 jails: <literal>NS</literal>, |
| 753 |
<literal>MAIL</literal> and <literal>WWW</literal>.</para> |
753 |
<literal>MAIL</literal> and <literal>WWW</literal>.</para> |
| 754 |
|
754 |
|
| 755 |
<procedure> |
755 |
<procedure> |
| 756 |
<step> |
756 |
<step> |
| 757 |
<para>Add the following lines to |
757 |
<para>Add the following lines to |
| 758 |
<filename>/etc/fstab</filename>, so that the read-only |
758 |
<filename>/etc/fstab</filename>, so that the read-only |
| 759 |
template for the jails and the read-write space will be |
759 |
template for the jails and the read-write space will be |
| 760 |
available in the respective jails:</para> |
760 |
available in the respective jails:</para> |
| 761 |
|
761 |
|
| 762 |
<programlisting>/home/j/mroot /home/j/ns nullfs ro 0 0 |
762 |
<programlisting>/home/j/mroot /home/j/ns nullfs ro 0 0 |
| 763 |
/home/j/mroot /home/j/mail nullfs ro 0 0 |
763 |
/home/j/mroot /home/j/mail nullfs ro 0 0 |
| 764 |
/home/j/mroot /home/j/www nullfs ro 0 0 |
764 |
/home/j/mroot /home/j/www nullfs ro 0 0 |
| 765 |
/home/js/ns /home/j/ns/s nullfs rw 0 0 |
765 |
/home/js/ns /home/j/ns/s nullfs rw 0 0 |
| 766 |
/home/js/mail /home/j/mail/s nullfs rw 0 0 |
766 |
/home/js/mail /home/j/mail/s nullfs rw 0 0 |
| 767 |
/home/js/www /home/j/www/s nullfs rw 0 0</programlisting> |
767 |
/home/js/www /home/j/www/s nullfs rw 0 0</programlisting> |
| 768 |
|
768 |
|
| 769 |
<para>To prevent |
769 |
<para>To prevent |
| 770 |
<application>fsck</application> from checking |
770 |
<application>fsck</application> from checking |
| 771 |
<application>nullfs</application> mounts during boot and |
771 |
<application>nullfs</application> mounts during boot and |
| 772 |
<application>dump</application> from backing up the |
772 |
<application>dump</application> from backing up the |
| 773 |
read-only nullfs mounts of the jails, the last two |
773 |
read-only nullfs mounts of the jails, the last two |
| 774 |
columns are both set to <literal>0</literal>.</para> |
774 |
columns are both set to <literal>0</literal>.</para> |
| 775 |
</step> |
775 |
</step> |
| 776 |
|
776 |
|
| 777 |
<step> |
777 |
<step> |
| 778 |
<para>Configure the jails in |
778 |
<para>Configure the jails in |
| 779 |
<filename>/etc/rc.conf</filename>:</para> |
779 |
<filename>/etc/rc.conf</filename>:</para> |
| 780 |
|
780 |
|
| 781 |
<programlisting>jail_enable="YES" |
781 |
<programlisting>jail_enable="YES" |
| 782 |
jail_set_hostname_allow="NO" |
782 |
jail_set_hostname_allow="NO" |
| 783 |
jail_list="ns mail www" |
783 |
jail_list="ns mail www" |
| 784 |
jail_ns_hostname="ns.example.org" |
784 |
jail_ns_hostname="ns.example.org" |
| 785 |
jail_ns_ip="192.168.3.17" |
785 |
jail_ns_ip="192.168.3.17" |
| 786 |
jail_ns_rootdir="/usr/home/j/ns" |
786 |
jail_ns_rootdir="/usr/home/j/ns" |
| 787 |
jail_ns_devfs_enable="YES" |
787 |
jail_ns_devfs_enable="YES" |
| 788 |
jail_mail_hostname="mail.example.org" |
788 |
jail_mail_hostname="mail.example.org" |
| 789 |
jail_mail_ip="192.168.3.18" |
789 |
jail_mail_ip="192.168.3.18" |
| 790 |
jail_mail_rootdir="/usr/home/j/mail" |
790 |
jail_mail_rootdir="/usr/home/j/mail" |
| 791 |
jail_mail_devfs_enable="YES" |
791 |
jail_mail_devfs_enable="YES" |
| 792 |
jail_www_hostname="www.example.org" |
792 |
jail_www_hostname="www.example.org" |
| 793 |
jail_www_ip="62.123.43.14" |
793 |
jail_www_ip="62.123.43.14" |
| 794 |
jail_www_rootdir="/usr/home/j/www" |
794 |
jail_www_rootdir="/usr/home/j/www" |
| 795 |
jail_www_devfs_enable="YES"</programlisting> |
795 |
jail_www_devfs_enable="YES"</programlisting> |
| 796 |
|
796 |
|
| 797 |
<para>The |
797 |
<para>The |
| 798 |
<varname>jail_<replaceable>name</replaceable>_rootdir</varname> |
798 |
<varname>jail_<replaceable>name</replaceable>_rootdir</varname> |
| 799 |
variable is set to |
799 |
variable is set to |
| 800 |
<filename>/usr/home</filename> instead |
800 |
<filename>/usr/home</filename> instead |
| 801 |
of <filename>/home</filename> because |
801 |
of <filename>/home</filename> because |
| 802 |
the physical path of <filename |
802 |
the physical path of <filename |
| 803 |
>/home</filename> on a default &os; |
803 |
>/home</filename> on a default &os; |
| 804 |
installation is <filename |
804 |
installation is <filename |
| 805 |
>/usr/home</filename>. The |
805 |
>/usr/home</filename>. The |
| 806 |
<varname>jail_<replaceable>name</replaceable>_rootdir</varname> |
806 |
<varname>jail_<replaceable>name</replaceable>_rootdir</varname> |
| 807 |
variable must <emphasis>not</emphasis> be set to a path |
807 |
variable must <emphasis>not</emphasis> be set to a path |
| 808 |
which includes a symbolic link, otherwise the jails will |
808 |
which includes a symbolic link, otherwise the jails will |
| 809 |
refuse to start.</para> |
809 |
refuse to start.</para> |
| 810 |
</step> |
810 |
</step> |
| 811 |
|
811 |
|
| 812 |
<step> |
812 |
<step> |
| 813 |
<para>Create the required mount points for the read-only |
813 |
<para>Create the required mount points for the read-only |
| 814 |
file system of each jail:</para> |
814 |
file system of each jail:</para> |
| 815 |
|
815 |
|
| 816 |
<screen>&prompt.root; <userinput>mkdir /home/j/ns /home/j/mail /home/j/www</userinput></screen> |
816 |
<screen>&prompt.root; <userinput>mkdir /home/j/ns /home/j/mail /home/j/www</userinput></screen> |
| 817 |
</step> |
817 |
</step> |
| 818 |
|
818 |
|
| 819 |
<step> |
819 |
<step> |
| 820 |
<para>Install the read-write template into each jail using |
820 |
<para>Install the read-write template into each jail using |
| 821 |
<package>sysutils/cpdup</package>:</para> |
821 |
<package>sysutils/cpdup</package>:</para> |
| 822 |
<!-- keramida: Why is cpdup required here? Doesn't cpio(1) |
822 |
<!-- keramida: Why is cpdup required here? Doesn't cpio(1) |
| 823 |
already include adequate functionality for performing this |
823 |
already include adequate functionality for performing this |
| 824 |
job *and* have the advantage of being part of the base |
824 |
job *and* have the advantage of being part of the base |
| 825 |
system of FreeBSD? --> |
825 |
system of FreeBSD? --> |
| 826 |
|
826 |
|
| 827 |
<screen>&prompt.root; <userinput>mkdir /home/js</userinput> |
827 |
<screen>&prompt.root; <userinput>mkdir /home/js</userinput> |
| 828 |
&prompt.root; <userinput>cpdup /home/j/skel /home/js/ns</userinput> |
828 |
&prompt.root; <userinput>cpdup /home/j/skel /home/js/ns</userinput> |
| 829 |
&prompt.root; <userinput>cpdup /home/j/skel /home/js/mail</userinput> |
829 |
&prompt.root; <userinput>cpdup /home/j/skel /home/js/mail</userinput> |
| 830 |
&prompt.root; <userinput>cpdup /home/j/skel /home/js/www</userinput></screen> |
830 |
&prompt.root; <userinput>cpdup /home/j/skel /home/js/www</userinput></screen> |
| 831 |
</step> |
831 |
</step> |
| 832 |
|
832 |
|
| 833 |
<step> |
833 |
<step> |
| 834 |
<para>In this phase, the jails are built and prepared to |
834 |
<para>In this phase, the jails are built and prepared to |
| 835 |
run. First, mount the required file systems for each |
835 |
run. First, mount the required file systems for each |
| 836 |
jail, and then start them:</para> |
836 |
jail, and then start them:</para> |
| 837 |
|
837 |
|
| 838 |
<screen>&prompt.root; <userinput>mount -a</userinput> |
838 |
<screen>&prompt.root; <userinput>mount -a</userinput> |
| 839 |
&prompt.root; <userinput>service jail start</userinput></screen> |
839 |
&prompt.root; <userinput>service jail start</userinput></screen> |
| 840 |
</step> |
840 |
</step> |
| 841 |
</procedure> |
841 |
</procedure> |
| 842 |
|
842 |
|
| 843 |
<para>The jails should be running now. To check if they have |
843 |
<para>The jails should be running now. To check if they have |
| 844 |
started correctly, use <command>jls</command>. Its output |
844 |
started correctly, use <command>jls</command>. Its output |
| 845 |
should be similar to the following:</para> |
845 |
should be similar to the following:</para> |
| 846 |
|
846 |
|
| 847 |
<screen>&prompt.root; <userinput>jls</userinput> |
847 |
<screen>&prompt.root; <userinput>jls</userinput> |
| 848 |
JID IP Address Hostname Path |
848 |
JID IP Address Hostname Path |
| 849 |
3 192.168.3.17 ns.example.org /home/j/ns |
849 |
3 192.168.3.17 ns.example.org /home/j/ns |
| 850 |
2 192.168.3.18 mail.example.org /home/j/mail |
850 |
2 192.168.3.18 mail.example.org /home/j/mail |
| 851 |
1 62.123.43.14 www.example.org /home/j/www</screen> |
851 |
1 62.123.43.14 www.example.org /home/j/www</screen> |
| 852 |
|
852 |
|
| 853 |
<para>At this point, it should be possible to log onto each |
853 |
<para>At this point, it should be possible to log onto each |
| 854 |
jail, add new users, or configure daemons. The |
854 |
jail, add new users, or configure daemons. The |
| 855 |
<literal>JID</literal> column indicates the jail |
855 |
<literal>JID</literal> column indicates the jail |
| 856 |
identification number of each running jail. Use the following |
856 |
identification number of each running jail. Use the following |
| 857 |
command to perform administrative tasks in the jail whose |
857 |
command to perform administrative tasks in the jail whose |
| 858 |
<acronym>JID</acronym> is <literal>3</literal>:</para> |
858 |
<acronym>JID</acronym> is <literal>3</literal>:</para> |
| 859 |
|
859 |
|
| 860 |
<screen>&prompt.root; <userinput>jexec 3 tcsh</userinput></screen> |
860 |
<screen>&prompt.root; <userinput>jexec 3 tcsh</userinput></screen> |
| 861 |
</sect2> |
861 |
</sect2> |
| 862 |
|
862 |
|
| 863 |
<sect2 xml:id="jails-service-jails-upgrading"> |
863 |
<sect2 xml:id="jails-service-jails-upgrading"> |
| 864 |
<title>Upgrading</title> |
864 |
<title>Upgrading</title> |
| 865 |
|
865 |
|
| 866 |
<para>The design of this setup provides an easy way to upgrade |
866 |
<para>The design of this setup provides an easy way to upgrade |
| 867 |
existing jails while minimizing their downtime. Also, it |
867 |
existing jails while minimizing their downtime. Also, it |
| 868 |
provides a way to roll back to the older version should a |
868 |
provides a way to roll back to the older version should a |
| 869 |
problem occur.</para> |
869 |
problem occur.</para> |
| 870 |
|
870 |
|
| 871 |
<procedure> |
871 |
<procedure> |
| 872 |
<step> |
872 |
<step> |
| 873 |
<para>The first step is to upgrade the host system. Then, |
873 |
<para>The first step is to upgrade the host system. Then, |
| 874 |
create a new temporary read-only template in |
874 |
create a new temporary read-only template in |
| 875 |
<filename>/home/j/mroot2</filename>.</para> |
875 |
<filename>/home/j/mroot2</filename>.</para> |
| 876 |
|
876 |
|
| 877 |
<screen>&prompt.root; <userinput>mkdir /home/j/mroot2</userinput> |
877 |
<screen>&prompt.root; <userinput>mkdir /home/j/mroot2</userinput> |
| 878 |
&prompt.root; <userinput>cd /usr/src</userinput> |
878 |
&prompt.root; <userinput>cd /usr/src</userinput> |
| 879 |
&prompt.root; <userinput>make installworld DESTDIR=/home/j/mroot2</userinput> |
879 |
&prompt.root; <userinput>make installworld DESTDIR=/home/j/mroot2</userinput> |
| 880 |
&prompt.root; <userinput>cd /home/j/mroot2</userinput> |
880 |
&prompt.root; <userinput>cd /home/j/mroot2</userinput> |
| 881 |
&prompt.root; <userinput>cpdup /usr/src usr/src</userinput> |
881 |
&prompt.root; <userinput>cpdup /usr/src usr/src</userinput> |
| 882 |
&prompt.root; <userinput>mkdir s</userinput></screen> |
882 |
&prompt.root; <userinput>mkdir s</userinput></screen> |
| 883 |
|
883 |
|
| 884 |
<para>The <buildtarget>installworld</buildtarget> creates a |
884 |
<para>The <buildtarget>installworld</buildtarget> creates a |
| 885 |
few unnecessary directories, which should be |
885 |
few unnecessary directories, which should be |
| 886 |
removed:</para> |
886 |
removed:</para> |
| 887 |
|
887 |
|
| 888 |
<screen>&prompt.root; <userinput>chflags -R 0 var</userinput> |
888 |
<screen>&prompt.root; <userinput>chflags -R 0 var</userinput> |
| 889 |
&prompt.root; <userinput>rm -R etc var root usr/local tmp</userinput></screen> |
889 |
&prompt.root; <userinput>rm -R etc var root usr/local tmp</userinput></screen> |
| 890 |
</step> |
890 |
</step> |
| 891 |
|
891 |
|
| 892 |
<step> |
892 |
<step> |
| 893 |
<para>Recreate the read-write symlinks for the master file |
893 |
<para>Recreate the read-write symlinks for the master file |
| 894 |
system:</para> |
894 |
system:</para> |
| 895 |
|
895 |
|
| 896 |
<screen>&prompt.root; <userinput>ln -s s/etc etc</userinput> |
896 |
<screen>&prompt.root; <userinput>ln -s s/etc etc</userinput> |
| 897 |
&prompt.root; <userinput>ln -s s/root root</userinput> |
897 |
&prompt.root; <userinput>ln -s s/root root</userinput> |
| 898 |
&prompt.root; <userinput>ln -s s/home home</userinput> |
898 |
&prompt.root; <userinput>ln -s s/home home</userinput> |
| 899 |
&prompt.root; <userinput>ln -s ../s/usr-local usr/local</userinput> |
899 |
&prompt.root; <userinput>ln -s ../s/usr-local usr/local</userinput> |
| 900 |
&prompt.root; <userinput>ln -s ../s/usr-X11R6 usr/X11R6</userinput> |
900 |
&prompt.root; <userinput>ln -s ../s/usr-X11R6 usr/X11R6</userinput> |
| 901 |
&prompt.root; <userinput>ln -s s/tmp tmp</userinput> |
901 |
&prompt.root; <userinput>ln -s s/tmp tmp</userinput> |
| 902 |
&prompt.root; <userinput>ln -s s/var var</userinput></screen> |
902 |
&prompt.root; <userinput>ln -s s/var var</userinput></screen> |
| 903 |
</step> |
903 |
</step> |
| 904 |
|
904 |
|
| 905 |
<step> |
905 |
<step> |
| 906 |
<para>Next, stop the jails:</para> |
906 |
<para>Next, stop the jails:</para> |
| 907 |
|
907 |
|
| 908 |
<screen>&prompt.root; <userinput>service jail stop</userinput></screen> |
908 |
<screen>&prompt.root; <userinput>service jail stop</userinput></screen> |
| 909 |
</step> |
909 |
</step> |
| 910 |
|
910 |
|
| 911 |
<step> |
911 |
<step> |
| 912 |
<para>Unmount the original file systems as the read-write |
912 |
<para>Unmount the original file systems as the read-write |
| 913 |
systems are attached to the read-only system |
913 |
systems are attached to the read-only system |
| 914 |
(<filename>/s</filename>):</para> |
914 |
(<filename>/s</filename>):</para> |
| 915 |
<!-- keramida: Shouldn't we suggest a short script-based |
915 |
<!-- keramida: Shouldn't we suggest a short script-based |
| 916 |
loop here, instead of tediously copying the same commands |
916 |
loop here, instead of tediously copying the same commands |
| 917 |
multiple times? --> |
917 |
multiple times? --> |
| 918 |
|
918 |
|
| 919 |
<screen>&prompt.root; <userinput>umount /home/j/ns/s</userinput> |
919 |
<screen>&prompt.root; <userinput>umount /home/j/ns/s</userinput> |
| 920 |
&prompt.root; <userinput>umount /home/j/ns</userinput> |
920 |
&prompt.root; <userinput>umount /home/j/ns</userinput> |
| 921 |
&prompt.root; <userinput>umount /home/j/mail/s</userinput> |
921 |
&prompt.root; <userinput>umount /home/j/mail/s</userinput> |
| 922 |
&prompt.root; <userinput>umount /home/j/mail</userinput> |
922 |
&prompt.root; <userinput>umount /home/j/mail</userinput> |
| 923 |
&prompt.root; <userinput>umount /home/j/www/s</userinput> |
923 |
&prompt.root; <userinput>umount /home/j/www/s</userinput> |
| 924 |
&prompt.root; <userinput>umount /home/j/www</userinput></screen> |
924 |
&prompt.root; <userinput>umount /home/j/www</userinput></screen> |
| 925 |
</step> |
925 |
</step> |
| 926 |
|
926 |
|
| 927 |
<step> |
927 |
<step> |
| 928 |
<para>Move the old read-only file system and replace it with |
928 |
<para>Move the old read-only file system and replace it with |
| 929 |
the new one. This will serve as a backup and archive of |
929 |
the new one. This will serve as a backup and archive of |
| 930 |
the old read-only file system should something go wrong. |
930 |
the old read-only file system should something go wrong. |
| 931 |
The naming convention used here corresponds to when a new |
931 |
The naming convention used here corresponds to when a new |
| 932 |
read-only file system has been created. Move the original |
932 |
read-only file system has been created. Move the original |
| 933 |
&os; Ports Collection over to the new file system to save |
933 |
&os; Ports Collection over to the new file system to save |
| 934 |
some space and inodes:</para> |
934 |
some space and inodes:</para> |
| 935 |
|
935 |
|
| 936 |
<screen>&prompt.root; <userinput>cd /home/j</userinput> |
936 |
<screen>&prompt.root; <userinput>cd /home/j</userinput> |
| 937 |
&prompt.root; <userinput>mv mroot mroot.20060601</userinput> |
937 |
&prompt.root; <userinput>mv mroot mroot.20060601</userinput> |
| 938 |
&prompt.root; <userinput>mv mroot2 mroot</userinput> |
938 |
&prompt.root; <userinput>mv mroot2 mroot</userinput> |
| 939 |
&prompt.root; <userinput>mv mroot.20060601/usr/ports mroot/usr</userinput></screen> |
939 |
&prompt.root; <userinput>mv mroot.20060601/usr/ports mroot/usr</userinput></screen> |
| 940 |
</step> |
940 |
</step> |
| 941 |
|
941 |
|
| 942 |
<step> |
942 |
<step> |
| 943 |
<para>At this point the new read-only template is ready, so |
943 |
<para>At this point the new read-only template is ready, so |
| 944 |
the only remaining task is to remount the file systems and |
944 |
the only remaining task is to remount the file systems and |
| 945 |
start the jails:</para> |
945 |
start the jails:</para> |
| 946 |
|
946 |
|
| 947 |
<screen>&prompt.root; <userinput>mount -a</userinput> |
947 |
<screen>&prompt.root; <userinput>mount -a</userinput> |
| 948 |
&prompt.root; <userinput>service jail start</userinput></screen> |
948 |
&prompt.root; <userinput>service jail start</userinput></screen> |
| 949 |
</step> |
949 |
</step> |
| 950 |
</procedure> |
950 |
</procedure> |
| 951 |
|
951 |
|
| 952 |
<para>Use <command>jls</command> to check if the jails started |
952 |
<para>Use <command>jls</command> to check if the jails started |
| 953 |
correctly. Run <command>mergemaster</command> in each jail to |
953 |
correctly. Run <command>mergemaster</command> in each jail to |
| 954 |
update the configuration files.</para> |
954 |
update the configuration files.</para> |
| 955 |
</sect2> |
955 |
</sect2> |
| 956 |
</sect1> |
956 |
</sect1> |
| 957 |
|
957 |
|
| 958 |
<sect1 xml:id="jails-ezjail"> |
958 |
<sect1 xml:id="jails-ezjail"> |
| 959 |
<info> |
959 |
<info> |
| 960 |
<title>Managing Jails with |
960 |
<title>Managing Jails with |
| 961 |
<application>ezjail</application></title> |
961 |
<application>ezjail</application></title> |
| 962 |
|
962 |
|
| 963 |
<authorgroup> |
963 |
<authorgroup> |
| 964 |
<author> |
964 |
<author> |
| 965 |
<personname> |
965 |
<personname> |
| 966 |
<firstname>Warren</firstname> |
966 |
<firstname>Warren</firstname> |
| 967 |
<surname>Block</surname> |
967 |
<surname>Block</surname> |
| 968 |
</personname><contrib>Originally contributed by </contrib> |
968 |
</personname><contrib>Originally contributed by </contrib> |
| 969 |
</author> |
969 |
</author> |
| 970 |
</authorgroup> |
970 |
</authorgroup> |
| 971 |
</info> |
971 |
</info> |
| 972 |
|
972 |
|
| 973 |
<para>Creating and managing multiple jails can quickly become |
973 |
<para>Creating and managing multiple jails can quickly become |
| 974 |
tedious and error-prone. Dirk Engling's |
974 |
tedious and error-prone. Dirk Engling's |
| 975 |
<application>ezjail</application> automates and greatly |
975 |
<application>ezjail</application> automates and greatly |
| 976 |
simplifies many jail tasks. A <emphasis>basejail</emphasis> is |
976 |
simplifies many jail tasks. A <emphasis>basejail</emphasis> is |
| 977 |
created as a template. Additional jails use |
977 |
created as a template. Additional jails use |
| 978 |
&man.mount.nullfs.8; to share many of the basejail directories |
978 |
&man.mount.nullfs.8; to share many of the basejail directories |
| 979 |
without using additional disk space. Each additional jail takes |
979 |
without using additional disk space. Each additional jail takes |
| 980 |
only a few megabytes of disk space before applications are |
980 |
only a few megabytes of disk space before applications are |
| 981 |
installed. Upgrading the copy of the userland in the basejail |
981 |
installed. Upgrading the copy of the userland in the basejail |
| 982 |
automatically upgrades all of the other jails.</para> |
982 |
automatically upgrades all of the other jails.</para> |
| 983 |
|
983 |
|
| 984 |
<para>Additional benefits and features are described in detail on |
984 |
<para>Additional benefits and features are described in detail on |
| 985 |
the <application>ezjail</application> web site, <link |
985 |
the <application>ezjail</application> web site, <link |
| 986 |
xlink:href="https://erdgeist.org/arts/software/ezjail/"></link>.</para> |
986 |
xlink:href="https://erdgeist.org/arts/software/ezjail/"></link>.</para> |
| 987 |
|
987 |
|
| 988 |
<sect2 xml:id="jails-ezjail-install"> |
988 |
<sect2 xml:id="jails-ezjail-install"> |
| 989 |
<title>Installing <application>ezjail</application></title> |
989 |
<title>Installing <application>ezjail</application></title> |
| 990 |
|
990 |
|
| 991 |
<para>Installing <application>ezjail</application> consists of |
991 |
<para>Installing <application>ezjail</application> consists of |
| 992 |
adding a loopback interface for use in jails, installing the |
992 |
adding a loopback interface for use in jails, installing the |
| 993 |
port or package, and enabling the service.</para> |
993 |
port or package, and enabling the service.</para> |
| 994 |
|
994 |
|
| 995 |
<procedure xml:id="jails-ezjail-install-procedure"> |
995 |
<procedure xml:id="jails-ezjail-install-procedure"> |
| 996 |
<step> |
996 |
<step> |
| 997 |
<para>To keep jail loopback traffic off the host's loopback |
997 |
<para>To keep jail loopback traffic off the host's loopback |
| 998 |
network interface <literal>lo0</literal>, a second |
998 |
network interface <literal>lo0</literal>, a second |
| 999 |
loopback interface is created by adding an entry to |
999 |
loopback interface is created by adding an entry to |
| 1000 |
<filename>/etc/rc.conf</filename>:</para> |
1000 |
<filename>/etc/rc.conf</filename>:</para> |
| 1001 |
|
1001 |
|
| 1002 |
<programlisting>cloned_interfaces="lo1"</programlisting> |
1002 |
<programlisting>cloned_interfaces="lo1"</programlisting> |
| 1003 |
|
1003 |
|
| 1004 |
<para>The second loopback interface <literal>lo1</literal> |
1004 |
<para>The second loopback interface <literal>lo1</literal> |
| 1005 |
will be created when the system starts. It can also be |
1005 |
will be created when the system starts. It can also be |
| 1006 |
created manually without a restart:</para> |
1006 |
created manually without a restart:</para> |
| 1007 |
|
1007 |
|
| 1008 |
<screen>&prompt.root; <userinput>service netif cloneup</userinput> |
1008 |
<screen>&prompt.root; <userinput>service netif cloneup</userinput> |
| 1009 |
Created clone interfaces: lo1.</screen> |
1009 |
Created clone interfaces: lo1.</screen> |
| 1010 |
|
1010 |
|
| 1011 |
<para>Jails can be allowed to use aliases of this secondary |
1011 |
<para>Jails can be allowed to use aliases of this secondary |
| 1012 |
loopback interface without interfering with the |
1012 |
loopback interface without interfering with the |
| 1013 |
host.</para> |
1013 |
host.</para> |
| 1014 |
|
1014 |
|
| 1015 |
<para>Inside a jail, access to the loopback address |
1015 |
<para>Inside a jail, access to the loopback address |
| 1016 |
<systemitem class="ipaddress">127.0.0.1</systemitem> is |
1016 |
<systemitem class="ipaddress">127.0.0.1</systemitem> is |
| 1017 |
redirected to the first <acronym>IP</acronym> address |
1017 |
redirected to the first <acronym>IP</acronym> address |
| 1018 |
assigned to the jail. To make the jail loopback |
1018 |
assigned to the jail. To make the jail loopback |
| 1019 |
correspond with the new <literal>lo1</literal> interface, |
1019 |
correspond with the new <literal>lo1</literal> interface, |
| 1020 |
that interface must be specified first in the list of |
1020 |
that interface must be specified first in the list of |
| 1021 |
interfaces and <acronym>IP</acronym> addresses given when |
1021 |
interfaces and <acronym>IP</acronym> addresses given when |
| 1022 |
creating a new jail.</para> |
1022 |
creating a new jail.</para> |
| 1023 |
|
1023 |
|
| 1024 |
<para>Give each jail a unique loopback address in the |
1024 |
<para>Give each jail a unique loopback address in the |
| 1025 |
<systemitem |
1025 |
<systemitem |
| 1026 |
class="ipaddress">127.0.0.0</systemitem><systemitem |
1026 |
class="ipaddress">127.0.0.0</systemitem><systemitem |
| 1027 |
class="netmask">/8</systemitem> netblock.</para> |
1027 |
class="netmask">/8</systemitem> netblock.</para> |
| 1028 |
</step> |
1028 |
</step> |
| 1029 |
|
1029 |
|
| 1030 |
<step> |
1030 |
<step> |
| 1031 |
<para>Install |
1031 |
<para>Install |
| 1032 |
<package role="port">sysutils/ezjail</package>:</para> |
1032 |
<package role="port">sysutils/ezjail</package>:</para> |
| 1033 |
|
1033 |
|
| 1034 |
<screen>&prompt.root; <userinput>cd /usr/ports/sysutils/ezjail</userinput> |
1034 |
<screen>&prompt.root; <userinput>cd /usr/ports/sysutils/ezjail</userinput> |
| 1035 |
&prompt.root; <userinput>make install clean</userinput></screen> |
1035 |
&prompt.root; <userinput>make install clean</userinput></screen> |
| 1036 |
</step> |
1036 |
</step> |
| 1037 |
|
1037 |
|
| 1038 |
<step> |
1038 |
<step> |
| 1039 |
<para>Enable <application>ezjail</application> by adding |
1039 |
<para>Enable <application>ezjail</application> by adding |
| 1040 |
this line to <filename>/etc/rc.conf</filename>:</para> |
1040 |
this line to <filename>/etc/rc.conf</filename>:</para> |
| 1041 |
|
1041 |
|
| 1042 |
<programlisting>ezjail_enable="YES"</programlisting> |
1042 |
<programlisting>ezjail_enable="YES"</programlisting> |
| 1043 |
</step> |
1043 |
</step> |
| 1044 |
|
1044 |
|
| 1045 |
<step> |
1045 |
<step> |
| 1046 |
<para>The service will automatically start on system boot. |
1046 |
<para>The service will automatically start on system boot. |
| 1047 |
It can be started immediately for the current |
1047 |
It can be started immediately for the current |
| 1048 |
session:</para> |
1048 |
session:</para> |
| 1049 |
|
1049 |
|
| 1050 |
<screen>&prompt.root; <userinput>service ezjail start</userinput></screen> |
1050 |
<screen>&prompt.root; <userinput>service ezjail start</userinput></screen> |
| 1051 |
</step> |
1051 |
</step> |
| 1052 |
</procedure> |
1052 |
</procedure> |
| 1053 |
</sect2> |
1053 |
</sect2> |
| 1054 |
|
1054 |
|
| 1055 |
<sect2 xml:id="jails-ezjail-initialsetup"> |
1055 |
<sect2 xml:id="jails-ezjail-initialsetup"> |
| 1056 |
<title>Initial Setup</title> |
1056 |
<title>Initial Setup</title> |
| 1057 |
|
1057 |
|
| 1058 |
<para>With <application>ezjail</application> installed, the |
1058 |
<para>With <application>ezjail</application> installed, the |
| 1059 |
basejail directory structure can be created and populated. |
1059 |
basejail directory structure can be created and populated. |
| 1060 |
This step is only needed once on the jail host |
1060 |
This step is only needed once on the jail host |
| 1061 |
computer.</para> |
1061 |
computer.</para> |
| 1062 |
|
1062 |
|
| 1063 |
<para>In both of these examples, <option>-p</option> causes the |
1063 |
<para>In both of these examples, <option>-p</option> causes the |
| 1064 |
ports tree to be retrieved with &man.portsnap.8; into the |
1064 |
ports tree to be retrieved with &man.portsnap.8; into the |
| 1065 |
basejail. That single copy of the ports directory will be |
1065 |
basejail. That single copy of the ports directory will be |
| 1066 |
shared by all the jails. Using a separate copy of the ports |
1066 |
shared by all the jails. Using a separate copy of the ports |
| 1067 |
directory for jails isolates them from the host. The |
1067 |
directory for jails isolates them from the host. The |
| 1068 |
<application>ezjail</application> <acronym>FAQ</acronym> |
1068 |
<application>ezjail</application> <acronym>FAQ</acronym> |
| 1069 |
explains in more detail: <link |
1069 |
explains in more detail: <link |
| 1070 |
xlink:href="http://erdgeist.org/arts/software/ezjail/#FAQ"></link>.</para> |
1070 |
xlink:href="http://erdgeist.org/arts/software/ezjail/#FAQ"></link>.</para> |
| 1071 |
|
1071 |
|
| 1072 |
<procedure xml:id="jails-ezjail-initialsetup-procedure"> |
1072 |
<procedure xml:id="jails-ezjail-initialsetup-procedure"> |
| 1073 |
<step> |
1073 |
<step> |
| 1074 |
<stepalternatives> |
1074 |
<stepalternatives> |
| 1075 |
<step> |
1075 |
<step> |
| 1076 |
<title>To Populate the Jail with &os;-RELEASE</title> |
1076 |
<title>To Populate the Jail with &os;-RELEASE</title> |
| 1077 |
|
1077 |
|
| 1078 |
<para>For a basejail based on the &os; RELEASE matching |
1078 |
<para>For a basejail based on the &os; RELEASE matching |
| 1079 |
that of the host computer, use |
1079 |
that of the host computer, use |
| 1080 |
<command>install</command>. For example, on a host |
1080 |
<command>install</command>. For example, on a host |
| 1081 |
computer running &os; 10-STABLE, the latest |
1081 |
computer running &os; 10-STABLE, the latest |
| 1082 |
RELEASE version of &os; -10 will be installed in |
1082 |
RELEASE version of &os; -10 will be installed in |
| 1083 |
the jail):</para> |
1083 |
the jail):</para> |
| 1084 |
|
1084 |
|
| 1085 |
<screen>&prompt.root; <userinput>ezjail-admin install -p</userinput></screen> |
1085 |
<screen>&prompt.root; <userinput>ezjail-admin install -p</userinput></screen> |
| 1086 |
</step> |
1086 |
</step> |
| 1087 |
|
1087 |
|
| 1088 |
<step> |
1088 |
<step> |
| 1089 |
<title>To Populate the Jail with |
1089 |
<title>To Populate the Jail with |
| 1090 |
<command>installworld</command></title> |
1090 |
<command>installworld</command></title> |
| 1091 |
|
1091 |
|
| 1092 |
<para>The basejail can be installed from binaries |
1092 |
<para>The basejail can be installed from binaries |
| 1093 |
created by <buildtarget>buildworld</buildtarget> on |
1093 |
created by <buildtarget>buildworld</buildtarget> on |
| 1094 |
the host with |
1094 |
the host with |
| 1095 |
<command>ezjail-admin update</command>.</para> |
1095 |
<command>ezjail-admin update</command>.</para> |
| 1096 |
|
1096 |
|
| 1097 |
<para>In this example, &os; 10-STABLE has been |
1097 |
<para>In this example, &os; 10-STABLE has been |
| 1098 |
built from source. The jail directories are created. |
1098 |
built from source. The jail directories are created. |
| 1099 |
Then <buildtarget>installworld</buildtarget> is |
1099 |
Then <buildtarget>installworld</buildtarget> is |
| 1100 |
executed, installing the host's |
1100 |
executed, installing the host's |
| 1101 |
<filename>/usr/obj</filename> into the |
1101 |
<filename>/usr/obj</filename> into the |
| 1102 |
basejail.</para> |
1102 |
basejail.</para> |
| 1103 |
|
1103 |
|
| 1104 |
<screen>&prompt.root; <userinput>ezjail-admin update -i -p</userinput></screen> |
1104 |
<screen>&prompt.root; <userinput>ezjail-admin update -i -p</userinput></screen> |
| 1105 |
|
1105 |
|
| 1106 |
<para>The host's <filename>/usr/src</filename> is used |
1106 |
<para>The host's <filename>/usr/src</filename> is used |
| 1107 |
by default. A different source directory on the host |
1107 |
by default. A different source directory on the host |
| 1108 |
can be specified with <option>-s</option> and a path, |
1108 |
can be specified with <option>-s</option> and a path, |
| 1109 |
or set with <varname>ezjail_sourcetree</varname> in |
1109 |
or set with <varname>ezjail_sourcetree</varname> in |
| 1110 |
<filename>/usr/local/etc/ezjail.conf</filename>.</para> |
1110 |
<filename>/usr/local/etc/ezjail.conf</filename>.</para> |
| 1111 |
</step> |
1111 |
</step> |
| 1112 |
</stepalternatives> |
1112 |
</stepalternatives> |
| 1113 |
</step> |
1113 |
</step> |
| 1114 |
</procedure> |
1114 |
</procedure> |
| 1115 |
|
1115 |
|
| 1116 |
<tip> |
1116 |
<tip> |
| 1117 |
<para>The basejail's ports tree is shared by other jails. |
1117 |
<para>The basejail's ports tree is shared by other jails. |
| 1118 |
However, downloaded distfiles are stored in the jail that |
1118 |
However, downloaded distfiles are stored in the jail that |
| 1119 |
downloaded them. By default, these files are stored in |
1119 |
downloaded them. By default, these files are stored in |
| 1120 |
<filename>/var/ports/distfiles</filename> within each |
1120 |
<filename>/var/ports/distfiles</filename> within each |
| 1121 |
jail. <filename>/var/ports</filename> inside each jail is |
1121 |
jail. <filename>/var/ports</filename> inside each jail is |
| 1122 |
also used as a work directory when building ports.</para> |
1122 |
also used as a work directory when building ports.</para> |
| 1123 |
</tip> |
1123 |
</tip> |
| 1124 |
</sect2> |
1124 |
</sect2> |
| 1125 |
|
1125 |
|
| 1126 |
<sect2 xml:id="jails-ezjail-create"> |
1126 |
<sect2 xml:id="jails-ezjail-create"> |
| 1127 |
<title>Creating and Starting a New Jail</title> |
1127 |
<title>Creating and Starting a New Jail</title> |
| 1128 |
|
1128 |
|
| 1129 |
<para>New jails are created with |
1129 |
<para>New jails are created with |
| 1130 |
<command>ezjail-admin create</command>. In these examples, |
1130 |
<command>ezjail-admin create</command>. In these examples, |
| 1131 |
the <literal>lo1</literal> loopback interface is used as |
1131 |
the <literal>lo1</literal> loopback interface is used as |
| 1132 |
described above.</para> |
1132 |
described above.</para> |
| 1133 |
|
1133 |
|
| 1134 |
<procedure xml:id="jails-ezjail-create-steps"> |
1134 |
<procedure xml:id="jails-ezjail-create-steps"> |
| 1135 |
<title>Create and Start a New Jail</title> |
1135 |
<title>Create and Start a New Jail</title> |
| 1136 |
|
1136 |
|
| 1137 |
<step> |
1137 |
<step> |
| 1138 |
<para>Create the jail, specifying a name and the loopback |
1138 |
<para>Create the jail, specifying a name and the loopback |
| 1139 |
and network interfaces to use, along with their |
1139 |
and network interfaces to use, along with their |
| 1140 |
<acronym>IP</acronym> addresses. In this example, the |
1140 |
<acronym>IP</acronym> addresses. In this example, the |
| 1141 |
jail is named <literal>dnsjail</literal>.</para> |
1141 |
jail is named <literal>dnsjail</literal>.</para> |
| 1142 |
|
1142 |
|
| 1143 |
<screen>&prompt.root; <userinput>ezjail-admin create <replaceable>dnsjail</replaceable> '<replaceable>lo1|127.0.1.1</replaceable>,<replaceable>em0</replaceable>|<replaceable>192.168.1.50</replaceable>'</userinput></screen> |
1143 |
<screen>&prompt.root; <userinput>ezjail-admin create <replaceable>dnsjail</replaceable> '<replaceable>lo1|127.0.1.1</replaceable>,<replaceable>em0</replaceable>|<replaceable>192.168.1.50</replaceable>'</userinput></screen> |
| 1144 |
|
1144 |
|
| 1145 |
<tip xml:id="jails-ezjail-raw-network-sockets"> |
1145 |
<tip xml:id="jails-ezjail-raw-network-sockets"> |
| 1146 |
<para>Most network services run in jails without |
1146 |
<para>Most network services run in jails without |
| 1147 |
problems. A few network services, most notably |
1147 |
problems. A few network services, most notably |
| 1148 |
&man.ping.8;, use |
1148 |
&man.ping.8;, use |
| 1149 |
<emphasis>raw network sockets</emphasis>. In jails, raw |
1149 |
<emphasis>raw network sockets</emphasis>. In jails, raw |
| 1150 |
network sockets are disabled by default for security. |
1150 |
network sockets are disabled by default for security. |
| 1151 |
Services that require them will not work.</para> |
1151 |
Services that require them will not work.</para> |
| 1152 |
|
1152 |
|
| 1153 |
<para>Occasionally, a jail genuinely needs raw sockets. |
1153 |
<para>Occasionally, a jail genuinely needs raw sockets. |
| 1154 |
For example, network monitoring applications often use |
1154 |
For example, network monitoring applications often use |
| 1155 |
&man.ping.8; to check the availability of other |
1155 |
&man.ping.8; to check the availability of other |
| 1156 |
computers. When raw network sockets are actually needed |
1156 |
computers. When raw network sockets are actually needed |
| 1157 |
in a jail, they can be enabled by editing the |
1157 |
in a jail, they can be enabled by editing the |
| 1158 |
<application>ezjail</application> |
1158 |
<application>ezjail</application> |
| 1159 |
configuration file for the individual jail, |
1159 |
configuration file for the individual jail, |
| 1160 |
<filename>/usr/local/etc/ezjail/<replaceable>jailname</replaceable></filename>. |
1160 |
<filename>/usr/local/etc/ezjail/<replaceable>jailname</replaceable></filename>. |
| 1161 |
Modify the <literal>parameters</literal> |
1161 |
Modify the <literal>parameters</literal> |
| 1162 |
entry:</para> |
1162 |
entry:</para> |
| 1163 |
|
1163 |
|
| 1164 |
<programlisting>export jail_<replaceable>jailname</replaceable>_parameters="allow.raw_sockets=1"</programlisting> |
1164 |
<programlisting>export jail_<replaceable>jailname</replaceable>_parameters="allow.raw_sockets=1"</programlisting> |
| 1165 |
|
1165 |
|
| 1166 |
<para>Do not enable raw network sockets unless services in |
1166 |
<para>Do not enable raw network sockets unless services in |
| 1167 |
the jail actually require them.</para> |
1167 |
the jail actually require them.</para> |
| 1168 |
</tip> |
1168 |
</tip> |
| 1169 |
</step> |
1169 |
</step> |
| 1170 |
|
1170 |
|
| 1171 |
<step> |
1171 |
<step> |
| 1172 |
<para>Start the jail:</para> |
1172 |
<para>Start the jail:</para> |
| 1173 |
|
1173 |
|
| 1174 |
<screen>&prompt.root; <userinput>ezjail-admin start <replaceable>dnsjail</replaceable></userinput></screen> |
1174 |
<screen>&prompt.root; <userinput>ezjail-admin start <replaceable>dnsjail</replaceable></userinput></screen> |
| 1175 |
</step> |
1175 |
</step> |
| 1176 |
|
1176 |
|
| 1177 |
<step> |
1177 |
<step> |
| 1178 |
<para>Use a console on the jail:</para> |
1178 |
<para>Use a console on the jail:</para> |
| 1179 |
|
1179 |
|
| 1180 |
<screen>&prompt.root; <userinput>ezjail-admin console <replaceable>dnsjail</replaceable></userinput></screen> |
1180 |
<screen>&prompt.root; <userinput>ezjail-admin console <replaceable>dnsjail</replaceable></userinput></screen> |
| 1181 |
</step> |
1181 |
</step> |
| 1182 |
</procedure> |
1182 |
</procedure> |
| 1183 |
|
1183 |
|
| 1184 |
<para>The jail is operating and additional configuration can be |
1184 |
<para>The jail is operating and additional configuration can be |
| 1185 |
completed. Typical settings added at this point |
1185 |
completed. Typical settings added at this point |
| 1186 |
include:</para> |
1186 |
include:</para> |
| 1187 |
|
1187 |
|
| 1188 |
<procedure> |
1188 |
<procedure> |
| 1189 |
<step> |
1189 |
<step> |
| 1190 |
<title>Set the |
1190 |
<title>Set the |
| 1191 |
<systemitem class="username">root</systemitem> |
1191 |
<systemitem class="username">root</systemitem> |
| 1192 |
Password</title> |
1192 |
Password</title> |
| 1193 |
|
1193 |
|
| 1194 |
<para>Connect to the jail and set the |
1194 |
<para>Connect to the jail and set the |
| 1195 |
<systemitem class="username">root</systemitem> user's |
1195 |
<systemitem class="username">root</systemitem> user's |
| 1196 |
password:</para> |
1196 |
password:</para> |
| 1197 |
|
1197 |
|
| 1198 |
<screen>&prompt.root; <userinput>ezjail-admin console <replaceable>dnsjail</replaceable></userinput> |
1198 |
<screen>&prompt.root; <userinput>ezjail-admin console <replaceable>dnsjail</replaceable></userinput> |
| 1199 |
&prompt.root; <userinput>passwd</userinput> |
1199 |
&prompt.root; <userinput>passwd</userinput> |
| 1200 |
Changing local password for root |
1200 |
Changing local password for root |
| 1201 |
New Password: |
1201 |
New Password: |
| 1202 |
Retype New Password:</screen> |
1202 |
Retype New Password:</screen> |
| 1203 |
</step> |
1203 |
</step> |
| 1204 |
|
1204 |
|
| 1205 |
<step> |
1205 |
<step> |
| 1206 |
<title>Time Zone Configuration</title> |
1206 |
<title>Time Zone Configuration</title> |
| 1207 |
|
1207 |
|
| 1208 |
<para>The jail's time zone can be set with &man.tzsetup.8;. |
1208 |
<para>The jail's time zone can be set with &man.tzsetup.8;. |
| 1209 |
To avoid spurious error messages, the &man.adjkerntz.8; |
1209 |
To avoid spurious error messages, the &man.adjkerntz.8; |
| 1210 |
entry in <filename>/etc/crontab</filename> can be |
1210 |
entry in <filename>/etc/crontab</filename> can be |
| 1211 |
commented or removed. This job attempts to update the |
1211 |
commented or removed. This job attempts to update the |
| 1212 |
computer's hardware clock with time zone changes, but |
1212 |
computer's hardware clock with time zone changes, but |
| 1213 |
jails are not allowed to access that hardware.</para> |
1213 |
jails are not allowed to access that hardware.</para> |
| 1214 |
</step> |
1214 |
</step> |
| 1215 |
|
1215 |
|
| 1216 |
<step> |
1216 |
<step> |
| 1217 |
<title><acronym>DNS</acronym> Servers</title> |
1217 |
<title><acronym>DNS</acronym> Servers</title> |
| 1218 |
|
1218 |
|
| 1219 |
<para>Enter domain name server lines in |
1219 |
<para>Enter domain name server lines in |
| 1220 |
<filename>/etc/resolv.conf</filename> so |
1220 |
<filename>/etc/resolv.conf</filename> so |
| 1221 |
<acronym>DNS</acronym> works in the jail.</para> |
1221 |
<acronym>DNS</acronym> works in the jail.</para> |
| 1222 |
</step> |
1222 |
</step> |
| 1223 |
|
1223 |
|
| 1224 |
<step> |
1224 |
<step> |
| 1225 |
<title>Edit <filename>/etc/hosts</filename></title> |
1225 |
<title>Edit <filename>/etc/hosts</filename></title> |
| 1226 |
|
1226 |
|
| 1227 |
<para>Change the address and add the jail name to the |
1227 |
<para>Change the address and add the jail name to the |
| 1228 |
<literal>localhost</literal> entries in |
1228 |
<literal>localhost</literal> entries in |
| 1229 |
<filename>/etc/hosts</filename>.</para> |
1229 |
<filename>/etc/hosts</filename>.</para> |
| 1230 |
</step> |
1230 |
</step> |
| 1231 |
|
1231 |
|
| 1232 |
<step> |
1232 |
<step> |
| 1233 |
<title>Configure <filename>/etc/rc.conf</filename></title> |
1233 |
<title>Configure <filename>/etc/rc.conf</filename></title> |
| 1234 |
|
1234 |
|
| 1235 |
<para>Enter configuration settings in |
1235 |
<para>Enter configuration settings in |
| 1236 |
<filename>/etc/rc.conf</filename>. This is much like |
1236 |
<filename>/etc/rc.conf</filename>. This is much like |
| 1237 |
configuring a full computer. The host name and |
1237 |
configuring a full computer. The host name and |
| 1238 |
<acronym>IP</acronym> address are not set here. Those |
1238 |
<acronym>IP</acronym> address are not set here. Those |
| 1239 |
values are already provided by the jail |
1239 |
values are already provided by the jail |
| 1240 |
configuration.</para> |
1240 |
configuration.</para> |
| 1241 |
</step> |
1241 |
</step> |
| 1242 |
</procedure> |
1242 |
</procedure> |
| 1243 |
|
1243 |
|
| 1244 |
<para>With the jail configured, the applications for which the |
1244 |
<para>With the jail configured, the applications for which the |
| 1245 |
jail was created can be installed.</para> |
1245 |
jail was created can be installed.</para> |
| 1246 |
|
1246 |
|
| 1247 |
<tip> |
1247 |
<tip> |
| 1248 |
<para>Some ports must be built with special options to be used |
1248 |
<para>Some ports must be built with special options to be used |
| 1249 |
in a jail. For example, both of the network monitoring |
1249 |
in a jail. For example, both of the network monitoring |
| 1250 |
plugin packages |
1250 |
plugin packages |
| 1251 |
<package role="port">net-mgmt/nagios-plugins</package> and |
1251 |
<package role="port">net-mgmt/nagios-plugins</package> and |
| 1252 |
<package role="port">net-mgmt/monitoring-plugins</package> |
1252 |
<package role="port">net-mgmt/monitoring-plugins</package> |
| 1253 |
have a <literal>JAIL</literal> option which must be enabled |
1253 |
have a <literal>JAIL</literal> option which must be enabled |
| 1254 |
for them to work correctly inside a jail.</para> |
1254 |
for them to work correctly inside a jail.</para> |
| 1255 |
</tip> |
1255 |
</tip> |
| 1256 |
</sect2> |
1256 |
</sect2> |
| 1257 |
|
1257 |
|
| 1258 |
<sect2 xml:id="jails-ezjail-update"> |
1258 |
<sect2 xml:id="jails-ezjail-update"> |
| 1259 |
<title>Updating Jails</title> |
1259 |
<title>Updating Jails</title> |
| 1260 |
|
1260 |
|
| 1261 |
<sect3 xml:id="jails-ezjail-update-os"> |
1261 |
<sect3 xml:id="jails-ezjail-update-os"> |
| 1262 |
<title>Updating the Operating System</title> |
1262 |
<title>Updating the Operating System</title> |
| 1263 |
|
1263 |
|
| 1264 |
<para>Because the basejail's copy of the userland is shared by |
1264 |
<para>Because the basejail's copy of the userland is shared by |
| 1265 |
the other jails, updating the basejail automatically updates |
1265 |
the other jails, updating the basejail automatically updates |
| 1266 |
all of the other jails. Either source or binary updates can |
1266 |
all of the other jails. Either source or binary updates can |
| 1267 |
be used.</para> |
1267 |
be used.</para> |
| 1268 |
|
1268 |
|
| 1269 |
<para>To build the world from source on the host, then |
1269 |
<para>To build the world from source on the host, then |
| 1270 |
install it in the basejail, use:</para> |
1270 |
install it in the basejail, use:</para> |
| 1271 |
|
1271 |
|
| 1272 |
<screen>&prompt.root; <userinput>ezjail-admin update -b</userinput></screen> |
1272 |
<screen>&prompt.root; <userinput>ezjail-admin update -b</userinput></screen> |
| 1273 |
|
1273 |
|
| 1274 |
<para>If the world has already been compiled on the host, |
1274 |
<para>If the world has already been compiled on the host, |
| 1275 |
install it in the basejail with:</para> |
1275 |
install it in the basejail with:</para> |
| 1276 |
|
1276 |
|
| 1277 |
<screen>&prompt.root; <userinput>ezjail-admin update -i</userinput></screen> |
1277 |
<screen>&prompt.root; <userinput>ezjail-admin update -i</userinput></screen> |
| 1278 |
|
1278 |
|
| 1279 |
<para>Binary updates use &man.freebsd-update.8;. These |
1279 |
<para>Binary updates use &man.freebsd-update.8;. These |
| 1280 |
updates have the same limitations as if |
1280 |
updates have the same limitations as if |
| 1281 |
&man.freebsd-update.8; were being run directly. The most |
1281 |
&man.freebsd-update.8; were being run directly. The most |
| 1282 |
important one is that only -RELEASE versions of &os; are |
1282 |
important one is that only -RELEASE versions of &os; are |
| 1283 |
available with this method.</para> |
1283 |
available with this method.</para> |
| 1284 |
|
1284 |
|
| 1285 |
<para>Update the basejail to the latest patched release of |
1285 |
<para>Update the basejail to the latest patched release of |
| 1286 |
the version of &os; on the host. For example, updating from |
1286 |
the version of &os; on the host. For example, updating from |
| 1287 |
RELEASE-p1 to RELEASE-p2.</para> |
1287 |
RELEASE-p1 to RELEASE-p2.</para> |
| 1288 |
|
1288 |
|
| 1289 |
<screen>&prompt.root; <userinput>ezjail-admin update -u</userinput></screen> |
1289 |
<screen>&prompt.root; <userinput>ezjail-admin update -u</userinput></screen> |
| 1290 |
|
1290 |
|
| 1291 |
<para>To upgrade the basejail to a new version, first |
1291 |
<para>To upgrade the basejail to a new version, first |
| 1292 |
upgrade the host system as described in <xref |
1292 |
upgrade the host system as described in <xref |
| 1293 |
linkend="freebsdupdate-upgrade" />. Once the host has |
1293 |
linkend="freebsdupdate-upgrade" />. Once the host has |
| 1294 |
been upgraded and rebooted, the basejail can then be |
1294 |
been upgraded and rebooted, the basejail can then be |
| 1295 |
upgraded. &man.freebsd-update.8; has no way of determining |
1295 |
upgraded. &man.freebsd-update.8; has no way of determining |
| 1296 |
which version is currently installed in the basejail, so the |
1296 |
which version is currently installed in the basejail, so the |
| 1297 |
original version must be specified. Use &man.file.1; to |
1297 |
original version must be specified. Use &man.file.1; to |
| 1298 |
determine the original version in the basejail:</para> |
1298 |
determine the original version in the basejail:</para> |
| 1299 |
|
1299 |
|
| 1300 |
<screen>&prompt.root; <userinput>file /usr/jails/basejail/bin/sh</userinput> |
1300 |
<screen>&prompt.root; <userinput>file /usr/jails/basejail/bin/sh</userinput> |
| 1301 |
/usr/jails/basejail/bin/sh: ELF 64-bit LSB executable, x86-64, version 1 (FreeBSD), dynamically linked (uses shared libs), for FreeBSD 9.3, stripped</screen> |
1301 |
/usr/jails/basejail/bin/sh: ELF 64-bit LSB executable, x86-64, version 1 (FreeBSD), dynamically linked (uses shared libs), for FreeBSD 9.3, stripped</screen> |
| 1302 |
|
1302 |
|
| 1303 |
<para>Now use this information to perform the upgrade from |
1303 |
<para>Now use this information to perform the upgrade from |
| 1304 |
<literal>9.3-RELEASE</literal> to the current version of |
1304 |
<literal>9.3-RELEASE</literal> to the current version of |
| 1305 |
the host system:</para> |
1305 |
the host system:</para> |
| 1306 |
|
1306 |
|
| 1307 |
<screen>&prompt.root; <userinput>ezjail-admin update -U -s <replaceable>9.3-RELEASE</replaceable></userinput></screen> |
1307 |
<screen>&prompt.root; <userinput>ezjail-admin update -U -s <replaceable>9.3-RELEASE</replaceable></userinput></screen> |
| 1308 |
|
1308 |
|
| 1309 |
<para>After updating the basejail, &man.mergemaster.8; must |
1309 |
<para>After updating the basejail, &man.mergemaster.8; must |
| 1310 |
be run to update each jail's configuration files.</para> |
1310 |
be run to update each jail's configuration files.</para> |
| 1311 |
|
1311 |
|
| 1312 |
<para>How to use &man.mergemaster.8; depends on the purpose |
1312 |
<para>How to use &man.mergemaster.8; depends on the purpose |
| 1313 |
and trustworthiness of a jail. If a jail's services or |
1313 |
and trustworthiness of a jail. If a jail's services or |
| 1314 |
users are not trusted, then &man.mergemaster.8; should only |
1314 |
users are not trusted, then &man.mergemaster.8; should only |
| 1315 |
be run from within that jail:</para> |
1315 |
be run from within that jail:</para> |
| 1316 |
|
1316 |
|
| 1317 |
<example xml:id="jails-ezjail-update-mergemaster-untrusted"> |
1317 |
<example xml:id="jails-ezjail-update-mergemaster-untrusted"> |
| 1318 |
<title>&man.mergemaster.8; on Untrusted Jail</title> |
1318 |
<title>&man.mergemaster.8; on Untrusted Jail</title> |
| 1319 |
|
1319 |
|
| 1320 |
<para>Delete the link from the jail's |
1320 |
<para>Delete the link from the jail's |
| 1321 |
<filename>/usr/src</filename> into the basejail and |
1321 |
<filename>/usr/src</filename> into the basejail and |
| 1322 |
create a new <filename>/usr/src</filename> in the jail |
1322 |
create a new <filename>/usr/src</filename> in the jail |
| 1323 |
as a mountpoint. Mount the host computer's |
1323 |
as a mountpoint. Mount the host computer's |
| 1324 |
<filename>/usr/src</filename> read-only on the jail's |
1324 |
<filename>/usr/src</filename> read-only on the jail's |
| 1325 |
new <filename>/usr/src</filename> mountpoint:</para> |
1325 |
new <filename>/usr/src</filename> mountpoint:</para> |
| 1326 |
|
1326 |
|
| 1327 |
<screen>&prompt.root; <userinput>rm /usr/jails/<replaceable>jailname</replaceable>/usr/src</userinput> |
1327 |
<screen>&prompt.root; <userinput>rm /usr/jails/<replaceable>jailname</replaceable>/usr/src</userinput> |
| 1328 |
&prompt.root; <userinput>mkdir /usr/jails/<replaceable>jailname</replaceable>/usr/src</userinput> |
1328 |
&prompt.root; <userinput>mkdir /usr/jails/<replaceable>jailname</replaceable>/usr/src</userinput> |
| 1329 |
&prompt.root; <userinput>mount -t nullfs -o ro /usr/src /usr/jails/<replaceable>jailname</replaceable>/usr/src</userinput></screen> |
1329 |
&prompt.root; <userinput>mount -t nullfs -o ro /usr/src /usr/jails/<replaceable>jailname</replaceable>/usr/src</userinput></screen> |
| 1330 |
|
1330 |
|
| 1331 |
<para>Get a console in the jail:</para> |
1331 |
<para>Get a console in the jail:</para> |
| 1332 |
|
1332 |
|
| 1333 |
<screen>&prompt.root; <userinput>ezjail-admin console <replaceable>jailname</replaceable></userinput></screen> |
1333 |
<screen>&prompt.root; <userinput>ezjail-admin console <replaceable>jailname</replaceable></userinput></screen> |
| 1334 |
|
1334 |
|
| 1335 |
<para>Inside the jail, run <command>mergemaster</command>. |
1335 |
<para>Inside the jail, run <command>mergemaster</command>. |
| 1336 |
Then exit the jail console:</para> |
1336 |
Then exit the jail console:</para> |
| 1337 |
|
1337 |
|
| 1338 |
<screen>&prompt.root; <userinput>cd /usr/src</userinput> |
1338 |
<screen>&prompt.root; <userinput>cd /usr/src</userinput> |
| 1339 |
&prompt.root; <userinput>mergemaster -U</userinput> |
1339 |
&prompt.root; <userinput>mergemaster -U</userinput> |
| 1340 |
&prompt.root; <userinput>exit</userinput></screen> |
1340 |
&prompt.root; <userinput>exit</userinput></screen> |
| 1341 |
|
1341 |
|
| 1342 |
<para>Finally, unmount the jail's |
1342 |
<para>Finally, unmount the jail's |
| 1343 |
<filename>/usr/src</filename>:</para> |
1343 |
<filename>/usr/src</filename>:</para> |
| 1344 |
|
1344 |
|
| 1345 |
<screen>&prompt.root; <userinput>umount /usr/jails/<replaceable>jailname</replaceable>/usr/src</userinput></screen> |
1345 |
<screen>&prompt.root; <userinput>umount /usr/jails/<replaceable>jailname</replaceable>/usr/src</userinput></screen> |
| 1346 |
</example> |
1346 |
</example> |
| 1347 |
|
1347 |
|
| 1348 |
<example xml:id="jails-ezjail-update-mergemaster-trusted"> |
1348 |
<example xml:id="jails-ezjail-update-mergemaster-trusted"> |
| 1349 |
|
1349 |
|
| 1350 |
<title>&man.mergemaster.8; on Trusted Jail</title> |
1350 |
<title>&man.mergemaster.8; on Trusted Jail</title> |
| 1351 |
|
1351 |
|
| 1352 |
<para>If the users and services in a jail are trusted, |
1352 |
<para>If the users and services in a jail are trusted, |
| 1353 |
&man.mergemaster.8; can be run from the host:</para> |
1353 |
&man.mergemaster.8; can be run from the host:</para> |
| 1354 |
|
1354 |
|
| 1355 |
<screen>&prompt.root; <userinput>mergemaster -U -D /usr/jails/<replaceable>jailname</replaceable></userinput></screen> |
1355 |
<screen>&prompt.root; <userinput>mergemaster -U -D /usr/jails/<replaceable>jailname</replaceable></userinput></screen> |
| 1356 |
</example> |
1356 |
</example> |
| 1357 |
</sect3> |
1357 |
</sect3> |
| 1358 |
|
1358 |
|
| 1359 |
<sect3 xml:id="jails-ezjail-update-ports"> |
1359 |
<sect3 xml:id="jails-ezjail-update-ports"> |
| 1360 |
<title>Updating Ports</title> |
1360 |
<title>Updating Ports</title> |
| 1361 |
|
1361 |
|
| 1362 |
<para>The ports tree in the basejail is shared by the other |
1362 |
<para>The ports tree in the basejail is shared by the other |
| 1363 |
jails. Updating that copy of the ports tree gives the other |
1363 |
jails. Updating that copy of the ports tree gives the other |
| 1364 |
jails the updated version also.</para> |
1364 |
jails the updated version also.</para> |
| 1365 |
|
1365 |
|
| 1366 |
<para>The basejail ports tree is updated with |
1366 |
<para>The basejail ports tree is updated with |
| 1367 |
&man.portsnap.8;:</para> |
1367 |
&man.portsnap.8;:</para> |
| 1368 |
|
1368 |
|
| 1369 |
<screen>&prompt.root; <userinput>ezjail-admin update -P</userinput></screen> |
1369 |
<screen>&prompt.root; <userinput>ezjail-admin update -P</userinput></screen> |
| 1370 |
</sect3> |
1370 |
</sect3> |
| 1371 |
</sect2> |
1371 |
</sect2> |
| 1372 |
|
1372 |
|
| 1373 |
<sect2 xml:id="jails-ezjail-control"> |
1373 |
<sect2 xml:id="jails-ezjail-control"> |
| 1374 |
<title>Controlling Jails</title> |
1374 |
<title>Controlling Jails</title> |
| 1375 |
|
1375 |
|
| 1376 |
<sect3 xml:id="jails-ezjail-control-stop-start"> |
1376 |
<sect3 xml:id="jails-ezjail-control-stop-start"> |
| 1377 |
<title>Stopping and Starting Jails</title> |
1377 |
<title>Stopping and Starting Jails</title> |
| 1378 |
|
1378 |
|
| 1379 |
<para><application>ezjail</application> automatically starts |
1379 |
<para><application>ezjail</application> automatically starts |
| 1380 |
jails when the computer is started. Jails can be manually |
1380 |
jails when the computer is started. Jails can be manually |
| 1381 |
stopped and restarted with <command>stop</command> and |
1381 |
stopped and restarted with <command>stop</command> and |
| 1382 |
<command>start</command>:</para> |
1382 |
<command>start</command>:</para> |
| 1383 |
|
1383 |
|
| 1384 |
<screen>&prompt.root; <userinput>ezjail-admin stop <replaceable>sambajail</replaceable></userinput> |
1384 |
<screen>&prompt.root; <userinput>ezjail-admin stop <replaceable>sambajail</replaceable></userinput> |
| 1385 |
Stopping jails: sambajail.</screen> |
1385 |
Stopping jails: sambajail.</screen> |
| 1386 |
|
1386 |
|
| 1387 |
<para>By default, jails are started automatically when the |
1387 |
<para>By default, jails are started automatically when the |
| 1388 |
host computer starts. Autostarting can be disabled |
1388 |
host computer starts. Autostarting can be disabled |
| 1389 |
with <command>config</command>:</para> |
1389 |
with <command>config</command>:</para> |
| 1390 |
|
1390 |
|
| 1391 |
<screen>&prompt.root; <userinput>ezjail-admin config -r norun <replaceable>seldomjail</replaceable></userinput></screen> |
1391 |
<screen>&prompt.root; <userinput>ezjail-admin config -r norun <replaceable>seldomjail</replaceable></userinput></screen> |
| 1392 |
|
1392 |
|
| 1393 |
<para>This takes effect the next time the host computer is |
1393 |
<para>This takes effect the next time the host computer is |
| 1394 |
started. A jail that is already running will not be |
1394 |
started. A jail that is already running will not be |
| 1395 |
stopped.</para> |
1395 |
stopped.</para> |
| 1396 |
|
1396 |
|
| 1397 |
<para>Enabling autostart is very similar:</para> |
1397 |
<para>Enabling autostart is very similar:</para> |
| 1398 |
|
1398 |
|
| 1399 |
<screen>&prompt.root; <userinput>ezjail-admin config -r run <replaceable>oftenjail</replaceable></userinput></screen> |
1399 |
<screen>&prompt.root; <userinput>ezjail-admin config -r run <replaceable>oftenjail</replaceable></userinput></screen> |
| 1400 |
</sect3> |
1400 |
</sect3> |
| 1401 |
|
1401 |
|
| 1402 |
<sect3 xml:id="jails-ezjail-control-backup"> |
1402 |
<sect3 xml:id="jails-ezjail-control-backup"> |
| 1403 |
<title>Archiving and Restoring Jails</title> |
1403 |
<title>Archiving and Restoring Jails</title> |
| 1404 |
|
1404 |
|
| 1405 |
<para>Use <command>archive</command> to create a |
1405 |
<para>Use <command>archive</command> to create a |
| 1406 |
<filename>.tar.gz</filename> archive of a jail. The file |
1406 |
<filename>.tar.gz</filename> archive of a jail. The file |
| 1407 |
name is composed from the name of the jail and the current |
1407 |
name is composed from the name of the jail and the current |
| 1408 |
date. Archive files are written to the archive directory, |
1408 |
date. Archive files are written to the archive directory, |
| 1409 |
<filename>/usr/jails/ezjail_archives</filename>. A |
1409 |
<filename>/usr/jails/ezjail_archives</filename>. A |
| 1410 |
different archive directory can be chosen by setting |
1410 |
different archive directory can be chosen by setting |
| 1411 |
<varname>ezjail_archivedir</varname> in the configuration |
1411 |
<varname>ezjail_archivedir</varname> in the configuration |
| 1412 |
file.</para> |
1412 |
file.</para> |
| 1413 |
|
1413 |
|
| 1414 |
<para>The archive file can be copied elsewhere as a backup, or |
1414 |
<para>The archive file can be copied elsewhere as a backup, or |
| 1415 |
an existing jail can be restored from it with |
1415 |
an existing jail can be restored from it with |
| 1416 |
<command>restore</command>. A new jail can be created from |
1416 |
<command>restore</command>. A new jail can be created from |
| 1417 |
the archive, providing a convenient way to clone existing |
1417 |
the archive, providing a convenient way to clone existing |
| 1418 |
jails.</para> |
1418 |
jails.</para> |
| 1419 |
|
1419 |
|
| 1420 |
<para>Stop and archive a jail named |
1420 |
<para>Stop and archive a jail named |
| 1421 |
<literal>wwwserver</literal>:</para> |
1421 |
<literal>wwwserver</literal>:</para> |
| 1422 |
|
1422 |
|
| 1423 |
<screen>&prompt.root; <userinput>ezjail-admin stop <replaceable>wwwserver</replaceable></userinput> |
1423 |
<screen>&prompt.root; <userinput>ezjail-admin stop <replaceable>wwwserver</replaceable></userinput> |
| 1424 |
Stopping jails: wwwserver. |
1424 |
Stopping jails: wwwserver. |
| 1425 |
&prompt.root; <userinput>ezjail-admin archive <replaceable>wwwserver</replaceable></userinput> |
1425 |
&prompt.root; <userinput>ezjail-admin archive <replaceable>wwwserver</replaceable></userinput> |
| 1426 |
&prompt.root; <userinput>ls /usr/jails/ezjail-archives/</userinput> |
1426 |
&prompt.root; <userinput>ls /usr/jails/ezjail-archives/</userinput> |
| 1427 |
wwwserver-201407271153.13.tar.gz</screen> |
1427 |
wwwserver-201407271153.13.tar.gz</screen> |
| 1428 |
|
1428 |
|
| 1429 |
<para>Create a new jail named |
1429 |
<para>Create a new jail named |
| 1430 |
<literal>wwwserver-clone</literal> from the archive created |
1430 |
<literal>wwwserver-clone</literal> from the archive created |
| 1431 |
in the previous step. Use the <filename>em1</filename> |
1431 |
in the previous step. Use the <filename>em1</filename> |
| 1432 |
interface and assign a new <acronym>IP</acronym> address to |
1432 |
interface and assign a new <acronym>IP</acronym> address to |
| 1433 |
avoid conflict with the original:</para> |
1433 |
avoid conflict with the original:</para> |
| 1434 |
|
1434 |
|
| 1435 |
<screen>&prompt.root; <userinput>ezjail-admin create -a /usr/jails/ezjail_archives/wwwserver-201407271153.13.tar.gz <replaceable>wwwserver-clone</replaceable> 'lo1|127.0.3.1,em1|192.168.1.51'</userinput></screen> |
1435 |
<screen>&prompt.root; <userinput>ezjail-admin create -a /usr/jails/ezjail_archives/wwwserver-201407271153.13.tar.gz <replaceable>wwwserver-clone</replaceable> 'lo1|127.0.3.1,em1|192.168.1.51'</userinput></screen> |
| 1436 |
</sect3> |
1436 |
</sect3> |
| 1437 |
</sect2> |
1437 |
</sect2> |
| 1438 |
|
1438 |
|
| 1439 |
<sect2 xml:id="jails-ezjail-example-bind"> |
1439 |
<sect2 xml:id="jails-ezjail-example-bind"> |
| 1440 |
<title>Full Example: <application>BIND</application> in a |
1440 |
<title>Full Example: <application>BIND</application> in a |
| 1441 |
Jail</title> |
1441 |
Jail</title> |
| 1442 |
|
1442 |
|
| 1443 |
<para>Putting the <application>BIND</application> |
1443 |
<para>Putting the <application>BIND</application> |
| 1444 |
<acronym>DNS</acronym> server in a jail improves security by |
1444 |
<acronym>DNS</acronym> server in a jail improves security by |
| 1445 |
isolating it. This example creates a simple caching-only name |
1445 |
isolating it. This example creates a simple caching-only name |
| 1446 |
server.</para> |
1446 |
server.</para> |
| 1447 |
|
1447 |
|
| 1448 |
<itemizedlist xml:id="jails-ezjail-example-bind-assumptions"> |
1448 |
<itemizedlist xml:id="jails-ezjail-example-bind-assumptions"> |
| 1449 |
<listitem> |
1449 |
<listitem> |
| 1450 |
<para>The jail will be called |
1450 |
<para>The jail will be called |
| 1451 |
<literal>dns1</literal>.</para> |
1451 |
<literal>dns1</literal>.</para> |
| 1452 |
</listitem> |
1452 |
</listitem> |
| 1453 |
|
1453 |
|
| 1454 |
<listitem> |
1454 |
<listitem> |
| 1455 |
<para>The jail will use <acronym>IP</acronym> address |
1455 |
<para>The jail will use <acronym>IP</acronym> address |
| 1456 |
<literal>192.168.1.240</literal> on the host's |
1456 |
<literal>192.168.1.240</literal> on the host's |
| 1457 |
<literal>re0</literal> interface.</para> |
1457 |
<literal>re0</literal> interface.</para> |
| 1458 |
</listitem> |
1458 |
</listitem> |
| 1459 |
|
1459 |
|
| 1460 |
<listitem> |
1460 |
<listitem> |
| 1461 |
<para>The upstream <acronym>ISP</acronym>'s DNS servers are |
1461 |
<para>The upstream <acronym>ISP</acronym>'s DNS servers are |
| 1462 |
at <literal>10.0.0.62</literal> and |
1462 |
at <literal>10.0.0.62</literal> and |
| 1463 |
<literal>10.0.0.61</literal>.</para> |
1463 |
<literal>10.0.0.61</literal>.</para> |
| 1464 |
</listitem> |
1464 |
</listitem> |
| 1465 |
|
1465 |
|
| 1466 |
<listitem> |
1466 |
<listitem> |
| 1467 |
<para>The basejail has already been created and a ports tree |
1467 |
<para>The basejail has already been created and a ports tree |
| 1468 |
installed.</para> |
1468 |
installed.</para> |
| 1469 |
</listitem> |
1469 |
</listitem> |
| 1470 |
</itemizedlist> |
1470 |
</itemizedlist> |
| 1471 |
|
1471 |
|
| 1472 |
<example xml:id="jails-ezjail-example-bind-steps"> |
1472 |
<example xml:id="jails-ezjail-example-bind-steps"> |
| 1473 |
<title>Running BIND in a Jail</title> |
1473 |
<title>Running BIND in a Jail</title> |
| 1474 |
|
1474 |
|
| 1475 |
<para>Create a cloned loopback interface by adding a line to |
1475 |
<para>Create a cloned loopback interface by adding a line to |
| 1476 |
<filename>/etc/rc.conf</filename>:</para> |
1476 |
<filename>/etc/rc.conf</filename>:</para> |
| 1477 |
|
1477 |
|
| 1478 |
<programlisting>cloned_interfaces="lo1"</programlisting> |
1478 |
<programlisting>cloned_interfaces="lo1"</programlisting> |
| 1479 |
|
1479 |
|
| 1480 |
<para>Immediately create the new loopback interface:</para> |
1480 |
<para>Immediately create the new loopback interface:</para> |
| 1481 |
|
1481 |
|
| 1482 |
<screen>&prompt.root; <userinput>service netif cloneup</userinput> |
1482 |
<screen>&prompt.root; <userinput>service netif cloneup</userinput> |
| 1483 |
Created clone interfaces: lo1.</screen> |
1483 |
Created clone interfaces: lo1.</screen> |
| 1484 |
|
1484 |
|
| 1485 |
<para>Create the jail:</para> |
1485 |
<para>Create the jail:</para> |
| 1486 |
|
1486 |
|
| 1487 |
<screen>&prompt.root; <userinput>ezjail-admin create dns1 'lo1|127.0.2.1,re0|192.168.1.240'</userinput></screen> |
1487 |
<screen>&prompt.root; <userinput>ezjail-admin create dns1 'lo1|127.0.2.1,re0|192.168.1.240'</userinput></screen> |
| 1488 |
|
1488 |
|
| 1489 |
<para>Start the jail, connect to a console running on it, and |
1489 |
<para>Start the jail, connect to a console running on it, and |
| 1490 |
perform some basic configuration:</para> |
1490 |
perform some basic configuration:</para> |
| 1491 |
|
1491 |
|
| 1492 |
<screen>&prompt.root; <userinput>ezjail-admin start dns1</userinput> |
1492 |
<screen>&prompt.root; <userinput>ezjail-admin start dns1</userinput> |
| 1493 |
&prompt.root; <userinput>ezjail-admin console dns1</userinput> |
1493 |
&prompt.root; <userinput>ezjail-admin console dns1</userinput> |
| 1494 |
&prompt.root; <userinput>passwd</userinput> |
1494 |
&prompt.root; <userinput>passwd</userinput> |
| 1495 |
Changing local password for root |
1495 |
Changing local password for root |
| 1496 |
New Password: |
1496 |
New Password: |
| 1497 |
Retype New Password: |
1497 |
Retype New Password: |
| 1498 |
&prompt.root; <userinput>tzsetup</userinput> |
1498 |
&prompt.root; <userinput>tzsetup</userinput> |
| 1499 |
&prompt.root; <userinput>sed -i .bak -e '/adjkerntz/ s/^/#/' /etc/crontab</userinput> |
1499 |
&prompt.root; <userinput>sed -i .bak -e '/adjkerntz/ s/^/#/' /etc/crontab</userinput> |
| 1500 |
&prompt.root; <userinput>sed -i .bak -e 's/127.0.0.1/127.0.2.1/g; s/localhost.my.domain/dns1.my.domain dns1/' /etc/hosts</userinput></screen> |
1500 |
&prompt.root; <userinput>sed -i .bak -e 's/127.0.0.1/127.0.2.1/g; s/localhost.my.domain/dns1.my.domain dns1/' /etc/hosts</userinput></screen> |
| 1501 |
|
1501 |
|
| 1502 |
<para>Temporarily set the upstream <acronym>DNS</acronym> |
1502 |
<para>Temporarily set the upstream <acronym>DNS</acronym> |
| 1503 |
servers in <filename>/etc/resolv.conf</filename> so ports |
1503 |
servers in <filename>/etc/resolv.conf</filename> so ports |
| 1504 |
can be downloaded:</para> |
1504 |
can be downloaded:</para> |
| 1505 |
|
1505 |
|
| 1506 |
<programlisting>nameserver 10.0.0.62 |
1506 |
<programlisting>nameserver 10.0.0.62 |
| 1507 |
nameserver 10.0.0.61</programlisting> |
1507 |
nameserver 10.0.0.61</programlisting> |
| 1508 |
|
1508 |
|
| 1509 |
<para>Still using the jail console, install |
1509 |
<para>Still using the jail console, install |
| 1510 |
<package role="port">dns/bind99</package>.</para> |
1510 |
<package role="port">dns/bind99</package>.</para> |
| 1511 |
|
1511 |
|
| 1512 |
<screen>&prompt.root; <userinput>make -C /usr/ports/dns/bind99 install clean</userinput></screen> |
1512 |
<screen>&prompt.root; <userinput>make -C /usr/ports/dns/bind99 install clean</userinput></screen> |
| 1513 |
|
1513 |
|
| 1514 |
<para>Configure the name server by editing |
1514 |
<para>Configure the name server by editing |
| 1515 |
<filename>/usr/local/etc/namedb/named.conf</filename>.</para> |
1515 |
<filename>/usr/local/etc/namedb/named.conf</filename>.</para> |
| 1516 |
|
1516 |
|
| 1517 |
<para>Create an Access Control List (<acronym>ACL</acronym>) |
1517 |
<para>Create an Access Control List (<acronym>ACL</acronym>) |
| 1518 |
of addresses and networks that are permitted to send |
1518 |
of addresses and networks that are permitted to send |
| 1519 |
<acronym>DNS</acronym> queries to this name server. This |
1519 |
<acronym>DNS</acronym> queries to this name server. This |
| 1520 |
section is added just before the <literal>options</literal> |
1520 |
section is added just before the <literal>options</literal> |
| 1521 |
section already in the file:</para> |
1521 |
section already in the file:</para> |
| 1522 |
|
1522 |
|
| 1523 |
<programlisting>... |
1523 |
<programlisting>... |
| 1524 |
// or cause huge amounts of useless Internet traffic. |
1524 |
// or cause huge amounts of useless Internet traffic. |
| 1525 |
|
1525 |
|
| 1526 |
acl "trusted" { |
1526 |
acl "trusted" { |
| 1527 |
192.168.1.0/24; |
1527 |
192.168.1.0/24; |
| 1528 |
localhost; |
1528 |
localhost; |
| 1529 |
localnets; |
1529 |
localnets; |
| 1530 |
}; |
1530 |
}; |
| 1531 |
|
1531 |
|
| 1532 |
options { |
1532 |
options { |
| 1533 |
...</programlisting> |
1533 |
...</programlisting> |
| 1534 |
|
1534 |
|
| 1535 |
<para>Use the jail <acronym>IP</acronym> address in the |
1535 |
<para>Use the jail <acronym>IP</acronym> address in the |
| 1536 |
<literal>listen-on</literal> setting to accept |
1536 |
<literal>listen-on</literal> setting to accept |
| 1537 |
<acronym>DNS</acronym> queries from other computers on the |
1537 |
<acronym>DNS</acronym> queries from other computers on the |
| 1538 |
network:</para> |
1538 |
network:</para> |
| 1539 |
|
1539 |
|
| 1540 |
<programlisting> listen-on { 192.168.1.240; };</programlisting> |
1540 |
<programlisting> listen-on { 192.168.1.240; };</programlisting> |
| 1541 |
|
1541 |
|
| 1542 |
<para>A simple caching-only <acronym>DNS</acronym> name server |
1542 |
<para>A simple caching-only <acronym>DNS</acronym> name server |
| 1543 |
is created by changing the <literal>forwarders</literal> |
1543 |
is created by changing the <literal>forwarders</literal> |
| 1544 |
section. The original file contains:</para> |
1544 |
section. The original file contains:</para> |
| 1545 |
|
1545 |
|
| 1546 |
<programlisting>/* |
1546 |
<programlisting>/* |
| 1547 |
forwarders { |
1547 |
forwarders { |
| 1548 |
127.0.0.1; |
1548 |
127.0.0.1; |
| 1549 |
}; |
1549 |
}; |
| 1550 |
*/</programlisting> |
1550 |
*/</programlisting> |
| 1551 |
|
1551 |
|
| 1552 |
<para>Uncomment the section by removing the |
1552 |
<para>Uncomment the section by removing the |
| 1553 |
<literal>/*</literal> and <literal>*/</literal> lines. |
1553 |
<literal>/*</literal> and <literal>*/</literal> lines. |
| 1554 |
Enter the <acronym>IP</acronym> addresses of the upstream |
1554 |
Enter the <acronym>IP</acronym> addresses of the upstream |
| 1555 |
<acronym>DNS</acronym> servers. Immediately after the |
1555 |
<acronym>DNS</acronym> servers. Immediately after the |
| 1556 |
<literal>forwarders</literal> section, add references to the |
1556 |
<literal>forwarders</literal> section, add references to the |
| 1557 |
<literal>trusted</literal> <acronym>ACL</acronym> defined |
1557 |
<literal>trusted</literal> <acronym>ACL</acronym> defined |
| 1558 |
earlier:</para> |
1558 |
earlier:</para> |
| 1559 |
|
1559 |
|
| 1560 |
<programlisting> forwarders { |
1560 |
<programlisting> forwarders { |
| 1561 |
10.0.0.62; |
1561 |
10.0.0.62; |
| 1562 |
10.0.0.61; |
1562 |
10.0.0.61; |
| 1563 |
}; |
1563 |
}; |
| 1564 |
|
1564 |
|
| 1565 |
allow-query { any; }; |
1565 |
allow-query { any; }; |
| 1566 |
allow-recursion { trusted; }; |
1566 |
allow-recursion { trusted; }; |
| 1567 |
allow-query-cache { trusted; };</programlisting> |
1567 |
allow-query-cache { trusted; };</programlisting> |
| 1568 |
|
1568 |
|
| 1569 |
<para>Enable the service in |
1569 |
<para>Enable the service in |
| 1570 |
<filename>/etc/rc.conf</filename>:</para> |
1570 |
<filename>/etc/rc.conf</filename>:</para> |
| 1571 |
|
1571 |
|
| 1572 |
<programlisting>named_enable="YES"</programlisting> |
1572 |
<programlisting>named_enable="YES"</programlisting> |
| 1573 |
|
1573 |
|
| 1574 |
<para>Start and test the name server:</para> |
1574 |
<para>Start and test the name server:</para> |
| 1575 |
|
1575 |
|
| 1576 |
<screen>&prompt.root; <userinput>service named start</userinput> |
1576 |
<screen>&prompt.root; <userinput>service named start</userinput> |
| 1577 |
wrote key file "/usr/local/etc/namedb/rndc.key" |
1577 |
wrote key file "/usr/local/etc/namedb/rndc.key" |
| 1578 |
Starting named. |
1578 |
Starting named. |
| 1579 |
&prompt.root; <userinput>/usr/local/bin/dig @192.168.1.240 freebsd.org</userinput></screen> |
1579 |
&prompt.root; <userinput>/usr/local/bin/dig @192.168.1.240 freebsd.org</userinput></screen> |
| 1580 |
|
1580 |
|
| 1581 |
<para>A response that includes</para> |
1581 |
<para>A response that includes</para> |
| 1582 |
|
1582 |
|
| 1583 |
<screen>;; Got answer;</screen> |
1583 |
<screen>;; Got answer;</screen> |
| 1584 |
|
1584 |
|
| 1585 |
<para>shows that the new <acronym>DNS</acronym> server is |
1585 |
<para>shows that the new <acronym>DNS</acronym> server is |
| 1586 |
working. A long delay followed by a response |
1586 |
working. A long delay followed by a response |
| 1587 |
including</para> |
1587 |
including</para> |
| 1588 |
|
1588 |
|
| 1589 |
<screen>;; connection timed out; no servers could be reached</screen> |
1589 |
<screen>;; connection timed out; no servers could be reached</screen> |
| 1590 |
|
1590 |
|
| 1591 |
<para>shows a problem. Check the configuration settings and |
1591 |
<para>shows a problem. Check the configuration settings and |
| 1592 |
make sure any local firewalls allow the new |
1592 |
make sure any local firewalls allow the new |
| 1593 |
<acronym>DNS</acronym> access to the upstream |
1593 |
<acronym>DNS</acronym> access to the upstream |
| 1594 |
<acronym>DNS</acronym> servers.</para> |
1594 |
<acronym>DNS</acronym> servers.</para> |
| 1595 |
|
1595 |
|
| 1596 |
<para>The new <acronym>DNS</acronym> server can use itself for |
1596 |
<para>The new <acronym>DNS</acronym> server can use itself for |
| 1597 |
local name resolution, just like other local computers. Set |
1597 |
local name resolution, just like other local computers. Set |
| 1598 |
the address of the <acronym>DNS</acronym> server in the |
1598 |
the address of the <acronym>DNS</acronym> server in the |
| 1599 |
client computer's |
1599 |
client computer's |
| 1600 |
<filename>/etc/resolv.conf</filename>:</para> |
1600 |
<filename>/etc/resolv.conf</filename>:</para> |
| 1601 |
|
1601 |
|
| 1602 |
<programlisting>nameserver 192.168.1.240</programlisting> |
1602 |
<programlisting>nameserver 192.168.1.240</programlisting> |
| 1603 |
|
1603 |
|
| 1604 |
<para>A local <acronym>DHCP</acronym> server can be configured |
1604 |
<para>A local <acronym>DHCP</acronym> server can be configured |
| 1605 |
to provide this address for a local <acronym>DNS</acronym> |
1605 |
to provide this address for a local <acronym>DNS</acronym> |
| 1606 |
server, providing automatic configuration on |
1606 |
server, providing automatic configuration on |
| 1607 |
<acronym>DHCP</acronym> clients.</para> |
1607 |
<acronym>DHCP</acronym> clients.</para> |
| 1608 |
</example> |
1608 |
</example> |
| 1609 |
</sect2> |
1609 |
</sect2> |
| 1610 |
</sect1> |
1610 |
</sect1> |
| 1611 |
</chapter> |
1611 |
</chapter> |