1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
|
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE article PUBLIC "-//FreeBSD//DTD DocBook XML V5.0-Based Extension//EN"
"http://www.FreeBSD.org/XML/share/xml/freebsd50.dtd">
<article xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink" version="5.0"
xml:lang="en"> <info>
<title>FreeBSD Quickstart Guide for &linux; Users</title>
<authorgroup>
<author><personname><firstname>John</firstname><surname>Ferrell</surname></personname></author>
</authorgroup>
<copyright>
<year>2008</year>
<holder>The FreeBSD Documentation Project</holder>
</copyright>
<pubdate>$FreeBSD$</pubdate>
<releaseinfo>$FreeBSD$</releaseinfo>
<legalnotice xml:id="trademarks" role="trademarks">
&tm-attrib.freebsd;
&tm-attrib.linux;
&tm-attrib.intel;
&tm-attrib.redhat;
&tm-attrib.unix;
&tm-attrib.general;
</legalnotice>
<abstract>
<para>This document is intended to quickly familiarize
intermediate to advanced &linux; users with the basics of
&os;.</para>
</abstract>
</info>
<sect1 xml:id="intro">
<title>Introduction</title>
<para>This document highlights some of the technical differences
between &os; and &linux; so that intermediate to advanced
&linux; users can quickly familiarize themselves with the basics
of &os;.</para>
<para>This document assumes that &os; is already installed. Refer
to the <link
xlink:href="&url.base;/doc/en_US.ISO8859-1/books/handbook/bsdinstall.html">
Installing &os;</link> chapter of the &os; Handbook for
help with the installation process.</para>
</sect1>
<sect1 xml:id="shells">
<title>Default Shell</title>
<para>&linux; users are often surprised to find that
<application>Bash</application> is not the default shell in
&os;. In fact, <application>Bash</application> is not included
in the default installation. Instead, &os; uses &man.tcsh.1; as
the default root shell, and the <application>Bourne
shell</application>-compatible &man.sh.1; as the default user
shell. &man.sh.1; is very similar to
<application>Bash</application> but with a much smaller
feature-set. Generally shell scripts written for &man.sh.1;
will run in <application>Bash</application>, but the reverse is
not always true.</para>
<para>However, <application>Bash</application> and other shells
are available for installation using the &os; <link
xlink:href="&url.base;/doc/en_US.ISO8859-1/books/handbook/ports.html">Packages
and Ports Collection</link>.</para>
<para>After installing another shell, use &man.chsh.1; to change a
user's default shell. It is recommended that the <systemitem
class="username">root</systemitem> user's default shell remain
unchanged since shells which are not included in the base
distribution are installed to
<filename>/usr/local/bin</filename>. In the event of a problem,
the file system where <filename>/usr/local/bin</filename> is
located may not be mounted. In this case, <systemitem
class="username">root</systemitem> would not have access to
its default shell, preventing <systemitem
class="username">root</systemitem> from logging in and fixing
the problem.</para>
</sect1>
<sect1 xml:id="software">
<title>Packages and Ports: Adding Software in &os;</title>
<para>&os; provides two methods for installing applications:
binary packages and compiled ports. Each method has its own
benefits:</para>
<itemizedlist>
<title>Binary Packages</title>
<listitem>
<simpara>Faster installation as compared to
compiling large applications.</simpara>
</listitem>
<listitem>
<simpara>Does not require an understanding of how to
compile software.</simpara>
</listitem>
<listitem>
<simpara>No need to install a compiler.</simpara>
</listitem>
</itemizedlist>
<itemizedlist>
<title>Ports</title>
<listitem>
<simpara>Ability to customize installation options.</simpara>
</listitem>
<listitem>
<simpara>Custom patches can be applied.</simpara>
</listitem>
</itemizedlist>
<para>If an application installation does not require any
customization, installing the package is sufficient. Compile
the port instead whenever an application requires customization
of the default options. If needed, a custom package can be
compiled from ports using <command>make</command>
<buildtarget>package</buildtarget>.</para>
<para>A complete list of all available ports and packages can
be found <link
xlink:href="https://www.freebsd.org/ports/master-index.html">here</link>.</para>
<sect2 xml:id="packages">
<title>Packages</title>
<para>Packages are pre-compiled applications, the &os;
equivalents of <filename>.deb</filename> files on
Debian/Ubuntu based systems and <filename>.rpm</filename>
files on Red Hat/Fedora based systems. Packages are
installed using <command>pkg</command>. For example,
the following command installs
<application>Apache 2.4</application>:</para>
<screen>&prompt.root; <userinput>pkg install <replaceable>apache24</replaceable></userinput></screen>
<para>For more information on packages refer to section 5.4 of
the &os; Handbook: <link
xlink:href="&url.base;/doc/en_US.ISO8859-1/books/handbook/pkgng-intro.html">Using
pkgng for Binary Package Management</link>.</para>
</sect2>
<sect2 xml:id="ports">
<title>Ports</title>
<para>The &os; Ports Collection is a framework of
<filename>Makefiles</filename> and patches specifically
customized for installing applications from source on &os;.
When installing a port, the system will fetch the source code,
apply any required patches, compile the code, and install the
application and any required dependencies.</para>
<para>The Ports Collection, sometimes referred to as the ports
tree, can be installed to <filename>/usr/ports</filename>
using &man.portsnap.8;. Detailed instructions for installing
the Ports Collection can be found in <link
xlink:href="&url.base;/doc/en_US.ISO8859-1/books/handbook/ports-using.html">section
5.5</link> of the &os; Handbook.</para>
<para>To compile a port, change to the port's directory and
start the build process. The following example installs
<application>Apache 2.4</application> from the Ports
Collection:</para>
<screen>&prompt.root; <userinput>cd /usr/ports/www/apache24</userinput>
&prompt.root; <userinput>make install clean</userinput></screen>
<para>A benefit of using ports to install software is the
ability to customize the installation options. This example
specifies that the <application>mod_ldap</application> module
should also be installed:</para>
<screen>&prompt.root; <userinput>cd /usr/ports/www/apache24</userinput>
&prompt.root; <userinput>make WITH_LDAP="YES" install clean</userinput></screen>
<para>Refer to <link
xlink:href="&url.base;/doc/en_US.ISO8859-1/books/handbook/ports-using.html">Using
the Ports Collection</link> for more information.</para>
</sect2>
</sect1>
<sect1 xml:id="startup">
<title>System Startup</title>
<para>Many &linux; distributions use the SysV init system, whereas
&os; uses the traditional BSD-style &man.init.8;. Under the
BSD-style &man.init.8;, there are no run-levels and
<filename>/etc/inittab</filename> does not exist. Instead,
startup is controlled by &man.rc.8; scripts. At system boot,
<filename>/etc/rc</filename> reads
<filename>/etc/rc.conf</filename> and
<filename>/etc/defaults/rc.conf</filename>
to determine which services are to be started. The specified
services are then started by running the corresponding service
initialization scripts located in
<filename>/etc/rc.d/</filename> and
<filename>/usr/local/etc/rc.d/</filename>. These scripts are
similar to the scripts located in
<filename>/etc/init.d/</filename> on &linux; systems.</para>
<para>The scripts found in <filename>/etc/rc.d/</filename> are for
applications that are part of the <quote>base</quote> system,
such as &man.cron.8;, &man.sshd.8;, and &man.syslog.3;. The
scripts in <filename>/usr/local/etc/rc.d/</filename> are for
user-installed applications such as
<application>Apache</application> and
<application>Squid</application>.</para>
<para>Since &os; is developed as a complete operating system,
user-installed applications are not considered to be part of
the <quote>base</quote> system. User-installed applications
are generally installed using <link
xlink:href="&url.base;/doc/en_US.ISO8859-1/books/handbook/ports-using.html">Packages
or Ports</link>. In order to keep them separate from the base
system, user-installed applications are installed under
<filename>/usr/local/</filename>. Therefore, user-installed
binaries reside in <filename>/usr/local/bin/</filename>,
configuration files are in <filename>/usr/local/etc/</filename>,
and so on.</para>
<para>Services are enabled by adding an entry for the service in
<filename>/etc/rc.conf</filename> . The system defaults are
found in <filename>/etc/defaults/rc.conf</filename> and these
default settings are overridden by settings in
<filename>/etc/rc.conf</filename>. Refer to &man.rc.conf.5; for
more information about the available entries. When installing
additional applications, review the application's install
message to determine how to enable any associated
services.</para>
<para>The following entries in <filename>/etc/rc.conf</filename>
enable &man.sshd.8;, enable <application>Apache
2.4</application>, and specify that
<application>Apache</application> should be started with
<acronym>SSL</acronym>.</para>
<programlisting># enable SSHD
sshd_enable="YES"
# enable Apache with SSL
apache24_enable="YES"
apache24_flags="-DSSL"</programlisting>
<para>Once a service has been enabled in
<filename>/etc/rc.conf</filename>, it can be started without
rebooting the system:</para>
<screen>&prompt.root; <userinput>service <replaceable>sshd</replaceable> start</userinput>
&prompt.root; <userinput>service <replaceable>apache24</replaceable> start</userinput></screen>
<para>If a service has not been enabled, it can be started from
the command line using <option>onestart</option>:</para>
<screen>&prompt.root; <userinput>service <replaceable>sshd</replaceable> onestart</userinput></screen>
</sect1>
<sect1 xml:id="network">
<title>Network Configuration</title>
<para>Instead of a generic <emphasis>ethX</emphasis> identifier
that &linux; uses to identify a network interface, &os; uses the
driver name followed by a number. The following output from
&man.ifconfig.8; shows two &intel; Pro 1000 network
interfaces (<filename>em0</filename> and
<filename>em1</filename>):</para>
<screen>&prompt.user; <userinput>ifconfig</userinput>
em0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=b<RXCSUM,TXCSUM,VLAN_MTU>
inet 10.10.10.100 netmask 0xffffff00 broadcast 10.10.10.255
ether 00:50:56:a7:70:b2
media: Ethernet autoselect (1000baseTX <full-duplex>)
status: active
em1: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=b<RXCSUM,TXCSUM,VLAN_MTU>
inet 192.168.10.222 netmask 0xffffff00 broadcast 192.168.10.255
ether 00:50:56:a7:03:2b
media: Ethernet autoselect (1000baseTX <full-duplex>)
status: active</screen>
<para>An <acronym>IP</acronym> address can be assigned to an
interface using &man.ifconfig.8;. To remain persistent across
reboots, the <acronym>IP</acronym> configuration must be
included in <filename>/etc/rc.conf</filename>. The following
<filename>/etc/rc.conf</filename> entries specify the hostname,
<acronym>IP</acronym> address, and default gateway:</para>
<programlisting>hostname="server1.example.com"
ifconfig_em0="inet 10.10.10.100 netmask 255.255.255.0"
defaultrouter="10.10.10.1"</programlisting>
<para>Use the following entries to instead configure an interface
for <acronym>DHCP</acronym>:</para>
<programlisting>hostname="server1.example.com"
ifconfig_em0="DHCP"</programlisting>
</sect1>
<sect1 xml:id="firewall">
<title>Firewall</title>
<para>&os; does not use &linux;
<application>IPTABLES</application> for its firewall. Instead,
&os; offers a choice of three kernel level firewalls:</para>
<itemizedlist>
<listitem>
<simpara><link
xlink:href="&url.base;/doc/en_US.ISO8859-1/books/handbook/firewalls-pf.html">PF</link></simpara>
</listitem>
<listitem>
<simpara><link
xlink:href="&url.base;/doc/en_US.ISO8859-1/books/handbook/firewalls-ipf.html">IPFILTER</link></simpara>
</listitem>
<listitem>
<simpara><link
xlink:href="&url.base;/doc/en_US.ISO8859-1/books/handbook/firewalls-ipfw.html">IPFW</link></simpara>
</listitem>
</itemizedlist>
<para><application>PF</application> is developed by the OpenBSD
project and ported to &os;. <application>PF</application> was
created as a replacement for <application>IPFILTER</application>
and its syntax is similar to that of
<application>IPFILTER</application>.
<application>PF</application> can be paired with &man.altq.4; to
provide <acronym>QoS</acronym> features.</para>
<para>This sample <application>PF</application> entry allows
inbound <application>SSH</application>:</para>
<programlisting>pass in on $ext_if inet proto tcp from any to ($ext_if) port 22</programlisting>
<para><application>IPFILTER</application> is the firewall
application developed by Darren Reed. It is not specific to
&os; and has been ported to several operating systems including
NetBSD, OpenBSD, SunOS, HP/UX, and Solaris.</para>
<para>The <application>IPFILTER</application> syntax to allow
inbound <application>SSH</application> is:</para>
<programlisting>pass in on $ext_if proto tcp from any to any port = 22</programlisting>
<para><application>IPFW</application> is the firewall developed
and maintained by &os;. It can be paired with &man.dummynet.4;
to provide traffic shaping capabilities and simulate different
types of network connections.</para>
<para>The <application>IPFW</application> syntax to allow inbound
<application>SSH</application> would be:</para>
<programlisting>ipfw add allow tcp from any to me 22 in via $ext_if</programlisting>
</sect1>
<sect1 xml:id="updates">
<title>Updating &os;</title>
<para>There are two methods for updating a &os; system: from
source or binary updates.</para>
<para>Updating from source is the most involved update method, but
offers the greatest amount of flexibility. The process involves
synchronizing a local copy of the &os; source code with the &os;
<application>Subversion</application> servers. Once the local
source code is up-to-date, a new version of the kernel and
userland can be compiled.</para>
<para>Binary updates are similar to using <command>yum</command>
or <command>apt-get</command> to update a &linux; system. In
&os;, &man.freebsd-update.8; can be used fetch new binary
updates and install them. These updates can be scheduled using
&man.cron.8;.</para>
<note>
<para>When using &man.cron.8; to schedule updates, use
<command>freebsd-update cron</command> in the &man.crontab.1;
to reduce the possibility of a large number of machines all
pulling updates at the same time:</para>
<programlisting>0 3 * * * root /usr/sbin/freebsd-update cron</programlisting>
</note>
<para>For more information on source and binary updates, refer to
<link
xlink:href="&url.base;/doc/en_US.ISO8859-1/books/handbook/updating-upgrading.html">the
chapter on updating</link> in the &os; Handbook.</para>
</sect1>
<sect1 xml:id="procfs">
<title>procfs: Gone But Not Forgotten</title>
<para>In some &linux; distributions, one could look at
<filename>/proc/sys/net/ipv4/ip_forward</filename> to determine
if <acronym>IP</acronym> forwarding is enabled. In &os;,
&man.sysctl.8; is instead used to view this and other system
settings.</para>
<para>For example, use the following to determine if
<acronym>IP</acronym> forwarding is enabled on a &os;
system:</para>
<screen>&prompt.user; <userinput>sysctl net.inet.ip.forwarding</userinput>
net.inet.ip.forwarding: 0</screen>
<para>Use <option>-a</option> to list all the system
settings:</para>
<screen>&prompt.user; <userinput>sysctl -a | more</userinput></screen>
<para>If an application requires procfs, add the following entry
to <filename>/etc/fstab</filename>:</para>
<screen>proc /proc procfs rw,noauto 0 0</screen>
<para>Including <option>noauto</option> will prevent
<filename>/proc</filename> from being automatically mounted at
boot.</para>
<para>To mount the file system without rebooting:</para>
<screen>&prompt.root; <userinput>mount /proc</userinput></screen>
</sect1>
<sect1 xml:id="commands">
<title>Common Commands</title>
<para>Some common command equivalents are as follows:</para>
<para><informaltable frame="none" pgwide="1">
<tgroup cols="3">
<thead>
<row>
<entry>&linux; command (Red Hat/Debian)</entry>
<entry>&os; equivalent</entry>
<entry>Purpose</entry>
</row>
</thead>
<tbody>
<row>
<entry><command>yum install
<replaceable>package</replaceable></command> /
<command>apt-get install
<replaceable>package</replaceable></command></entry>
<entry><command>pkg install
<replaceable>package</replaceable></command></entry>
<entry>Install package from remote repository</entry>
</row>
<row>
<entry><command>rpm -ivh
<replaceable>package</replaceable></command> /
<command>dpkg -i
<replaceable>package</replaceable></command></entry>
<entry><command>pkg add
<replaceable>package</replaceable></command></entry>
<entry>Install local package</entry>
</row>
<row>
<entry><command>rpm -qa</command>
/ <command>dpkg -l</command></entry>
<entry><command>pkg info</command></entry>
<entry>List installed packages</entry>
</row>
<row>
<entry><command>lspci</command></entry>
<entry><command>pciconf</command></entry>
<entry>List <acronym>PCI</acronym> devices</entry>
</row>
<row>
<entry><command>lsmod</command></entry>
<entry><command>kldstat</command></entry>
<entry>List loaded kernel modules</entry>
</row>
<row>
<entry><command>modprobe</command></entry>
<entry><command>kldload</command>
/ <command>kldunload</command></entry>
<entry>Load/Unload kernel modules</entry>
</row>
<row>
<entry><command>strace</command></entry>
<entry><command>truss</command></entry>
<entry>Trace system calls</entry>
</row>
</tbody>
</tgroup>
</informaltable></para>
</sect1>
<sect1 xml:id="conclusion">
<title>Conclusion</title>
<para>This document has provided an overview of &os;. Refer to
the <link
xlink:href="&url.base;/doc/en_US.ISO8859-1/books/handbook/index.html">&os; Handbook</link>
for more in-depth coverage of these topics as well as the many
topics not covered by this document.</para>
</sect1>
</article>
|