FreeBSD Tutorial
Joel Jaeggli and Hervey Allen


Why FreeBSD
Accounts information
Creating a user account for yourself
Some basic FreeBSD commands
Command line editing
Using vi as an editor
Post-installation configuration
Short example using FreeBSD commands
Getting FreeBSD 4.2 files and others
pkg_add: Adding packages or ports by hand
Network Information
Stopping and starting the network
Stopping and starting services
Installation Notes
Slices and partitions
Distribution sets
Quick installation guide (using CD-ROM)
A few differences from Linux


Many of the topics covered in this short session will be discussed in more detail in the Monday evening FreeBSD session.

Why did we choose FreeBSD rather than Linux?

We are using FreeBSD 4.2. It has a number of features which make it more appropriate than Linux for use in an ISP environment: Linux users will find some annoyances: for example, that 'bash' is not installed as standard, and new package management tools to learn. However, we feel that the robustness of FreeBSD is the most overriding factor for ISP's, and it's worth you getting to know and use FreeBSD. The FreeBSD Website is located at


Accounts information

ACCOUNT:         root
PASSWORD:      Given in class

PLEASE! Do not change the root password. This will cause numerous problems throughout the workshop. The machine in front of you is yours for the duration of the workshop.



Creating a user account for yourself

Some basic FreeBSD commands

man Help pages for commands
Change Directory
LiSt files/directories
CoPy files/directories
ReMove files/directories
MoVe files/directories
MaKe a DIRectory
See currently running ProceSses
ConCATenate a file to the screen (by default)
Display a file to the screen with editing functionality
more Display a file to the screen and pause
See the end (tail) of a a file
gzip ZIP (compress) a file, or set of files
gunzip UNZIP (decompress) a zip archive
bunzip2 ZIP/UNZIP alternate compression format
tar Archive/unarchive files/directories to file or tape
grep Look for pattern(s) in file(s)

Back to Top

Command line editing

FreeBSD by default uses sh or csh, which provide very rudimentary editing capabilities. Bash has much better editiing features so that's what the t1 accounts use. We do not recommend changing the default shell of root; rather, use 'su -m' rather than 'su' to get root access
# bash

If you change the default shell for root it is possible to create a situation where you 
cannot get a a shell if your machine's environment becomes damaged. 

Using 'vi' as an editor

If you are unfamiliar with the 'vi' text editor, here is the absolute minimum set of commands you need to know. Beware: when you start 'vi' it is in command mode, so anything you type is interpreted as a command, not text to be entered!
# vi <filename>            -- edit a file

i  ....   [ESC]          -- insert text before cursor position
A  ....   [ESC]          -- append text to end of current line
x                        -- delete character under cursor
dd                       -- delete whole line
:wq                      -- save and exit
:q!                      -- exit without saving
ESC Shift-ZZ			 -- save and exit
o						 -- insert a line after cursor position
dd						 -- delete the current line
h j k l                  -- left|down|up|right (preferred)

Post-installation configuration

There is a menu-based system you can use for configuring the system - setting IP address, configuring hostname, adding further distribution sets and packages, adding users etc:
# /stand/sysinstall

However, you may find that some of this is quicker to do from the command line, some of which is explained below.

Short example using some FreeBSD commands

We will be placing source for programs during the workshop in a directory called /u/src. The /u partition contains enough space for us to use this for this purpose. The /u partition, also, contains your home directories. See the Installation Notes section below for more information on partition slices.

To create /u/src do the following:

Take a look at what's in /u/src (which is nothing):

Getting FreeBSD 4.2 files and others

The FreeBSD 4.2 CD-ROM contents have been made available to you locally. Additional files may be placed in /pub (see below) as needed.

pkg_add: Adding packages or ports by hand

A lot of third-party software is supplied in ready-to-use form, but is not in the base system. This is (a) to keep the base system smaller, and (b) because of different licensing terms. (The FreeBSD license is actually less restrictive than the GNU/GPL license under which a lot of open-source software is distributed)

All this third-party software installs under /usr/local.

You can use /stand/sysinstall to add packages, but it is quicker to use 'pkg_add' from the command line. The example below assumes that you have the FreeBSD mounted to the mount point /cdrom. For example, to add the editor 'joe':

# cd /cdrom/packages/All
# ls
# pkg_add joe-2.8.tgz

[For the workshop you can simply enter in the command below]

# pkg_add
Note that the configuration files for third-party software are in /usr/local/etc, and scripts to start daemons are installed under /usr/local/etc/rc.d

You can also compile packages directly from the source code, if you have the "ports" distribution installed. The ports system automatically fetches the source file via FTP or anonCVS, applies any FreeBSD-specific patches, and compiles and installs the code. A "package" is really just a "port" which has been compiled.

# cd /usr/ports/shells/bash
# make
# make install
# make clean
Sometimes you will find that a "port" exists, but no corresponding binary "package". This is usually because of licensing or export restrictions. The "port" is always able to be distributed because it does not include any software, only instructions on how to fetch and compile the software from somewhere else.

You can query installed packages, or package .tgz files, using pkg_info.

# pkg_info -aI          -- list all installed packages (one line per package)
# pkg_info joe-2.8      -- description of package
# pkg_info -L joe-2.8   -- list all files in package
# man pkg_info          -- read this more for details
Back to Top

Network information


This is the command you use to interactively start and stop network interfaces and to define how they run. You need root access to use this command.


The main system configuration file is /etc/rc.conf. This file is edited by /stand/sysinstall, but it's perfectly OK to edit this by hand. It is in this file that you configure the hostname, IP address for each interface, and so on. Changes you make in here won't take effect until you reboot.
ifconfig_ed0="inet netmask"

# On hosts where you don't want sendmail to accept incoming port 25
# (but you still want daemons to be able to send outgoing mail):
The full list of options, and their default values, can be found in /etc/defaults/rc.conf - but don't edit this file, edit /etc/rc.conf instead. This makes it easier to upgrade your system to a later version of FreeBSD.

Stopping and starting the network

You may be used to something like "/etc/rc.d/init.d/network stop" under Linux. Under FreeBSD this functionality resides in /etc/rc.conf and is parsed at system startup. So, to stop your currently running network first use ifconfig to figure out what interface you wish to stop.

This displays your network interface status. Notice that "fxp0" (Fast Ethernet) has an IP address assigned (via DHCP). Not that lo0 as an address as well. This is your loopback device. To bring fxp0 down type:

Now to bring it back up just type:

There is quite a bit more to ifconfig and we'll discuss this during the Monday evening FreeBSD session as well, or you can type "man ifconfig" for more information. Review the "rc.conf" section above as well.

Stopping and starting services

By default, system services are configured in /etc/rc.conf and are started at system startup. If you need to start and stop one of these services (perhaps you changed the service's configuration file) you should do the following:

or to find a particular running service, like sendmail, try:

You'll get output that includes the process ID number on the left. If you make a change to the process's configuration, or just need to restart the process, you can do the following:

Note, if the service is a third party package, then you can often find configuration files for the service in /usr/local/etc/. In addition you may find shell scripts that can start and stop the service with command line parameters in /usr/local/etc/rc.d. Use these scripts instead, when available, to start and stop a service.

Back to Top

Installation notes

Slices and partitions

What MS-DOS calls partitions are called "slices" by FreeBSD. FreeBSD almost always sits in a single slice.

The FreeBSD slice is then divided into "partitions". Example:

/dev/ad0     -- first ATA/ATAPI (IDE) hard drive
/dev/ad0s1   -- first slice (MSDOS "partition") on first IDE hard drive
/dev/ad0s1a  -- first partition in this FreeBSD slice
/dev/ad0s1b  -- second partition in this FreeBSD slice
/dev/ad0s1e  -- third (usable) partition
For historical reasons, partitions c and d are not used. We strongly recommend you configure your partitions as:
a:       root filesystem (/)
b:       swap space
e,f...:  other filesystems
All "large" parts of the filesystem should be separate from the root, so that the root itself remains small (less likely to get corrupted). This means at least /usr and /var, and possibly also /home if you have user accounts. The convention we have used is to put all remaining disk space in a partition called /u, and put home directories under that (/u/home/name)

Distribution sets

FreeBSD comes in several parts:

Quick installation guide (using CD-ROM)

For your reference, this is the sequence of operations we followed to install the classroom workstations. Obviously you should adjust this as required to suit your needs (for example, most servers do not need to have X installed)
Insert boot floppy, change to root floppy when prompted
Skip kernel config
Express install
Delete any existing partitions, then select "Entire disk"
Say Yes to standard partition entry
Select BootMgr

Create partition; ctrl-U to delete number presented, enter "100m" instead
  FS   /
Create partition; ctrl-U; 100m
Create partition; ctrl-U; 400m
  FS   /var
Create partition; ctrl-U; 400m
  FS   /usr
Create partition; hit enter to accept number given (i.e. rest of disk)
  FS   /u

X-User  (must hit SPACEBAR, not Enter, to select it)
No crypto
Not US resident
Yes install ports collection

Default answers to remaining questions (i.e. just hit Enter)
WAIT for install to complete
No extra options after install
Exit install
Reboot (remember to remove floppy and CD)
Login as root

Label machine as being successfully installed 

A Few differences from Linux

Other key differences between Linux and FreeBSD center around the naming of devices and some of the configuration files:
Linux:   eth0 = first ethernet device (of any type)
FreeBSD: ed0  = first NE2000 device, ep0 = first 3Com 3c509, etc.

Linux:   COM1 serial port = /dev/ttyS0
FreeBSD: COM1 serial port = /dev/cuaa0 (call out) or /dev/ttyd0 (call in)

Linux:   /etc/inittab configures incoming serial connections
FreeBSD: /etc/ttys configures incoming serial connections

Back to Top

Hervey Allen
Joel Jaeggli
Liberal borrowing from Brian Candler
May 6, 2001