Sams Teach Yourself FreeBSD In 24 Hours Oct 2002 ISBN 0672324245 pdf
800 East 96th St., Indianapolis, Indiana, 46240 USA Teach Yourself in
24 Hours Michael Urban Brian Tiemann
FreeBSD
A CQUISITIONS E DITOR Sams Teach Yourself FreeBSDKatie Purdum in 24 Hours D EVELOPMENT E DITOR
Dee-Ann LeBlanc Copyright © 2003 by Sams Publishing M ANAGING E DITOR All rights reserved. No part of this book shall be reproduced, stored in a retrieval system, or transmitted by any means, electronic, mechanical, photo- Charlotte Clapp copying, recording, or otherwise, without written permission from the pub-
P ROJECT E DITOR lisher. No patent liability is assumed with respect to the use of the information Andy Beaster contained herein. Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or
C OPY E DITOR omissions. Nor is any liability assumed for damages resulting from the use of Rhonda Tinch-Mize the information contained herein.
I NDEXER International Standard Book Number: 0672324245 Ken Johnson Library of Congress Catalog Card Number: 2002102902
P ROOFREADER Leslie Joseph Printed in the United States of America
T ECHNICAL E DITOR First Printing: December 2002 Dee-Ann LeBlanc 04 03 02 4 3 2 1
T EAM C OORDINATOR Amy Patton
Trademarks M EDIA D EVELOPER
All terms mentioned in this book that are known to be trademarks or service Dan Scherf marks have been appropriately capitalized. Sams Publishing cannot attest to the accuracy of this information. Use of a term in this book should not be regarded
I NTERIOR D ESIGNER as affecting the validity of any trademark or service mark.
Gary Adair C OVER D ESIGNER Warning and Disclaimer
Alan Clements Every effort has been made to make this book as complete and as accurate as possible, but no warranty or fitness is implied. The information provided is on
P AGE L AYOUT an “as is” basis. The author and the publisher shall have neither liability nor Point ’n Click Publishing, LLC. responsibility to any person or entity with respect to any loss or damages aris- ing from the information contained in this book or from the use of the CD or programs accompanying it.
Contents at a Glance
Introduction
1 Part I Introduction to FreeBSD
3 Hour 1 Planning for and Preparing to Install FreeBSD
5
2 Installing FreeBSD
19
3 A Basic Tour of FreeBSD
33
4 Basic Shell Use
53 Part II Basic FreeBSD Administration
73 Hour 5 Users and Groups
75
6 Adding and Removing Third-Party Software
91
7 System Configuration and Startup Scripts 105
8 Storage Systems and Backup Utilities 123
9 The FreeBSD Printing System 147
10 The FreeBSD Kernel and the Device Tree 165
11 Updating FreeBSD 177
Part III Networking 195
Hour 12 Introduction to Networks 197
13 Connecting FreeBSD to an Existing Network 215
14 Dial-up Network Connections 227
15 Network Security 241
Part IV FreeBSD as a Workstation 255
Hour 16 Command-Line Applications 25717 Configuring the X Window System 271
18 The K Desktop Environment (KDE) 289
19 Window Managers and Desktop Environments 309
20 Productivity in the X Window System 319
21 Multimedia in FreeBSD 335
Part V FreeBSD as a Server 345 Hour 22 Configuring a Basic Web Server 347
23 Basic Email Services 365
24 File Sharing 381
Part VI Appendixes 405
A Resources for FreeBSD Users 407 B FreeBSD Quick Reference 415
Index 419
Contents Introduction
1 What This Book Is ..................................................................................................1 What This Book Is Not ..........................................................................................2 How to Use This Book ..........................................................................................2
Part I Introduction to FreeBSD
3 H OUR
1 Planning for and Preparing to Install FreeBSD
5 What Is FreeBSD? ..................................................................................................5 FreeBSD Is a True UNIX Operating System ....................................................6 FreeBSD Is Open Source ..................................................................................6 FreeBSD Is Free and Has a Very Liberal License Agreement ..........................6 FreeBSD Is Stable and Powerful ......................................................................6
What Is FreeBSD Being Used for? ........................................................................7 Set Up a Powerful Web Server ..........................................................................7 Email Services ..................................................................................................7 DNS and Routing Services ................................................................................7 File and Printer Sharing ....................................................................................7 Database Services ..............................................................................................7 Software Development/Learning Programming ................................................8 Learning UNIX ..................................................................................................8 Inexpensive UNIX Workstations ......................................................................8 FreeBSD Compared to Other Operating Systems ..................................................8 FreeBSD Compared to Linux ............................................................................8 Other BSD Operating Systems ........................................................................10 FreeBSD Compared to Windows 2000 and XP ..............................................11 System Requirements ..........................................................................................13
Deciding How and Where to Install FreeBSD ....................................................13 Backing Up Existing Systems ..............................................................................14 Floppy Disks ....................................................................................................15 Zip Disks ........................................................................................................15 Recordable and Rewritable CD-ROM ............................................................16 DVD-ROM ......................................................................................................16 Tape Drives ......................................................................................................16 Summary ..............................................................................................................17
Q&A ......................................................................................................................17 Workshop ..............................................................................................................18 Exercises ..........................................................................................................18
H OUR
2 Installing FreeBSD
19 Beginning the FreeBSD Installation ....................................................................20 sysinstall ................................................................................................................21 Navigating in sysinstall ..................................................................................21 Hard Disk Partitioning ..........................................................................................22 FreeBSD’s Hard Disk Naming ........................................................................22 Boot Manager ......................................................................................................23 Creating BSD Partitions ......................................................................................23 Choosing the Distribution to Install ....................................................................24 Choosing Installation Media ................................................................................25 Post Installation ....................................................................................................26 Shutting Down the System After Reboot ............................................................29 Summary ..............................................................................................................30 Q&A ......................................................................................................................30 Workshop ..............................................................................................................30 Quiz ................................................................................................................31
Quiz Answers ..................................................................................................31 H OUR
3 A Basic Tour of FreeBSD
33 The Basics of the FreeBSD Startup Process ........................................................34 The POST ........................................................................................................34 The Bootstrap ..................................................................................................34 The Boot Manager ..........................................................................................34 The Kernel ......................................................................................................35 init ....................................................................................................................37 Logging In to FreeBSD ........................................................................................37
Your Home Directory ..........................................................................................39 The Rest of the Directory Structure ....................................................................39 Working with Files and Directories ......................................................................41 Creating and Deleting Directories ..................................................................41
Rules for Directory Names ..............................................................................42 Listing Directory Contents ..............................................................................43 Changing Directories ......................................................................................45 The pwd Command ........................................................................................46 Creating Files ..................................................................................................46 Moving Files ....................................................................................................46 Copying Files ..................................................................................................47 Deleting Files ..................................................................................................48 Wildcard Basics ..............................................................................................48 Logging Out of the System ..................................................................................49
Importance of Proper System Shutdown ..............................................................50 Workshop ..............................................................................................................51 vi Sams Teach Yourself FreeBSD in 24 Hours
Contents vii Quiz ................................................................................................................51 Quiz Answers ..................................................................................................52
H OUR
53 The Role of the Shell ............................................................................................53 Different Shells Available ....................................................................................55 The Bourne Shell ............................................................................................55
4 Basic UNIX Shell Use
The C Shell ......................................................................................................55 The Korn Shell ................................................................................................56 The Bash Shell ................................................................................................56 The Tcsh Shell ................................................................................................56 Which Shell Should You Use? ........................................................................56 Getting Help in the Shell ................................................................................57 Man Page Format ............................................................................................57 Man Page Categories ......................................................................................58 Specifying Which Category to Use ................................................................59 Searching the Man Pages ................................................................................59 Command Summaries ....................................................................................59 The GNU Info System ....................................................................................60 Searching for info Pages ................................................................................61 Special Features of Bash ......................................................................................61 Command Line History ..................................................................................61 Command Line Completion ............................................................................61
File Permissions ....................................................................................................62 Displaying Permissions for a File or Directory ..............................................62 Process Management ............................................................................................64 Terminating a Process ....................................................................................66
Stopping a Process ..........................................................................................67 Restarting a Process ........................................................................................68 Moving a Process into the Background ..........................................................68 Summary ..............................................................................................................69
Q&A ......................................................................................................................69 Workshop ..............................................................................................................70 Quiz ................................................................................................................70 Quiz Answers ..................................................................................................71 Exercises ..........................................................................................................71
Part II Basic FreeBSD Administration
73 H OUR
75 Multiuser Capabilities of FreeBSD ......................................................................76 Adding Users to FreeBSD ....................................................................................77 Removing a User Account ....................................................................................83
5 Users and Groups
viii Sams Teach Yourself FreeBSD in 24 Hours Groups and Their Purpose ....................................................................................84 Creating Groups ..............................................................................................84
Changing the Group Ownership ......................................................................85 Setting the Permissions ..................................................................................86 Primary Versus Secondary Groups ......................................................................88 Summary ..............................................................................................................88 Workshop ..............................................................................................................88 Quiz ................................................................................................................88
Quiz Answers ..................................................................................................89 H OUR
91 FreeBSD’s Software Packaging Systems ............................................................92 The Differences Between Packages and Ports ....................................................92 Discovering What’s Available ..............................................................................93 Installing Software from Prebuilt Packages ........................................................94 Installing the Downloaded Package ................................................................96
6 Adding and Removing Third-Party Software
Obtaining Information on Installed Packages ................................................97 Installing Software from Ports ..............................................................................97 The FreeBSD Ports Tree ................................................................................98 Making Sure That Your Ports Tree Is Up-to-Date ..........................................98 Installing a Port ............................................................................................100 Removing Installed Software ............................................................................100
Updating Installed Software ..............................................................................101 Notes on Ports and Disk Space ..........................................................................101 Working with Linux Applications ......................................................................102 Summary ............................................................................................................102 Workshop ............................................................................................................103 Quiz ..............................................................................................................103
Quiz Answers ................................................................................................104 H OUR
7 System Configuration and Startup Scripts 105 Understanding the FreeBSD Startup Process ....................................................106 Resource Configuration Scripts ..........................................................................109 Modifying System Settings ................................................................................110
The /etc/defaults/rc.conf File ........................................................................110 The /etc/rc.conf File ......................................................................................111 The /usr/local/etc and /usr/local/X11R6/etc Directories ..............................113 The inetd Daemon and the inetd.conf Configuration File ..................................114
The System Logger (syslogd) and the syslog.conf File ................................................................................................117 Summary ............................................................................................................119 Q&A ....................................................................................................................119
Contents ix
Workshop ............................................................................................................121
Quiz ..............................................................................................................121
Quiz Answers ................................................................................................122
Exercises ........................................................................................................122
H OUR8 Storage Systems and Backup Utilities 123
Understanding UNIX Filesystems ......................................................................124
Partitions, Volumes, and Filesystems ............................................................126
The FreeBSD Filesystem ..............................................................................127
Mounting and Unmounting Various Media Formats ..........................................130
Formatting Disks ..........................................................................................132
The mount Command ....................................................................................132
Mounting Non-UFS Filesystems ..................................................................133
About NFS ....................................................................................................134
The umount Command ..................................................................................134
The /etc/fstab File ..............................................................................................135
The FreeBSD Automounter ................................................................................136
System Backup Strategies and Utilities ..............................................................138
Using tar ........................................................................................................138
Using burncd ................................................................................................140
Recovery ........................................................................................................141
Creating “Seed” Files ....................................................................................141
Summary ............................................................................................................142
Q&A ....................................................................................................................143
Workshop ............................................................................................................144
Quiz ..............................................................................................................144
Quiz Answers ................................................................................................145
Exercises ........................................................................................................145
H OUR9 The FreeBSD Printing System 147
How FreeBSD Handles Printing ........................................................................148
Configuring the Printer ......................................................................................149
Configuring the Parallel Port ........................................................................149
Configuring the Print Spool Directory ..........................................................150
Configuring a Text Filter ..............................................................................151
Formatting Plain Text for Postscript Printers ................................................152
Configuring a Ghostscript Filter ..................................................................153
The /etc/printcap File ....................................................................................155
Starting lpd ..........................................................................................................156
Command Line Printing ....................................................................................156
Checking the Status of Jobs ................................................................................157
Removing Jobs from the Queue ........................................................................158
x Sams Teach Yourself FreeBSD in 24 Hours Controlling the Printers ......................................................................................159 Queue Status ..................................................................................................160
Disabling the Queue ......................................................................................160 Enabling the Queue and Restarting the Printer ............................................161 Restarting the Daemon ..................................................................................161 Cleaning the Queue ......................................................................................161 Changing the Priority of Print Jobs ..............................................................161 Abbreviating Commands ..............................................................................162
Summary ............................................................................................................162 Q&A ....................................................................................................................162 Workshop ............................................................................................................162 Quiz ..............................................................................................................163
Answers ........................................................................................................164 H OUR
10 The FreeBSD Kernel and Device Tree 165 The Kernel and Its Purpose ................................................................................166 Why Build a Custom Kernel? ............................................................................166 The Kernel Configuration File ............................................................................167
Editing the Configuration File ......................................................................167 The NOTES File ............................................................................................170 Building the New Kernel ....................................................................................170 Installing the New Kernel ..................................................................................171 Recovering from Botched Kernel Builds ..........................................................172 ”Kernel panic!” Message After Reboot ........................................................172
System Hangs After Reboot ..........................................................................172 Kernel Build Fails with “* Error code” Message ........................................173 Certain System Utilities Stop Working ........................................................173 Summary ............................................................................................................173
Workshop ............................................................................................................174 Quiz ..............................................................................................................174 Quiz Answers ................................................................................................175 H OUR
11 Updating FreeBSD 177
The Two FreeBSD Source Trees ........................................................................178 What Is a Source Tree? ................................................................................178 The Difference Between STABLE and CURRENT ....................................178 RELEASE Versions of FreeBSD ..................................................................179 SNAPSHOT Versions of FreeBSD ................................................................180 Updating Your Source Tree ................................................................................180 What Is cvsup? ..............................................................................................181 Using CVSup ................................................................................................181 Editing the CVSup Configuration File ..........................................................181 Running CVSup ............................................................................................184
Contents xi The UPDATING File ..........................................................................................184 The /etc/make.conf File ......................................................................................185 Updating Important Files ....................................................................................185 Rebuilding the System ........................................................................................187
Removing the Old Object Files ....................................................................187 Building the World ........................................................................................187 Installing the New World ....................................................................................188 Building the New Kernel ....................................................................................189 Troubleshooting ..................................................................................................190 Summary ............................................................................................................191 Q&A ....................................................................................................................191 Workshop ............................................................................................................192
Quiz ..............................................................................................................192 Quiz Answers ................................................................................................192 Exercises ........................................................................................................193
Part III Networking 195
H OUR
12 Introduction to Networks 197 The OSI Networking Model ..............................................................................198 Basic Networking Components ..........................................................................201 Cables ............................................................................................................201
Straight-through and Crossover Cables ........................................................201 Hubs ..............................................................................................................204 Switches ........................................................................................................205 Bridges ..........................................................................................................206 Routers ..........................................................................................................206 The IP Address System and Subnets ..................................................................207
Subnets and the Network Mask ..........................................................................209 Summary ............................................................................................................211 Q&A ....................................................................................................................211 Workshop ............................................................................................................212
Quiz ..............................................................................................................212 Quiz Answers ................................................................................................213 Exercises ........................................................................................................213 H OUR
13 Connecting FreeBSD to an Existing Network 215 The Network Interface Device ............................................................................216 Configuring Network Settings with sysinstall ..........................................................................................................219
Testing Network Connectivity with ping ......................................................221 Summary ............................................................................................................222 Q&A ....................................................................................................................222
xii Sams Teach Yourself FreeBSD in 24 Hours Workshop ............................................................................................................224 Quiz ..............................................................................................................224
Quiz Answers ................................................................................................225 Exercises ........................................................................................................225 H OUR
14 Dial-Up Network Connections 227 Selecting an Internet Service Provider ..............................................................228 Modem Information ............................................................................................229 Configuring the Dial-up Internet Connection ....................................................230
Setting Up the DNS Servers ..........................................................................230 Configuring the Options File for Kernel PPP ..............................................231 Creating the Chat Script ................................................................................232 pap-secrets and chap-secrets ........................................................................233 Starting the Internet Connection ..................................................................234 Dial-on-Demand ............................................................................................234 Persistent Connections ..................................................................................234 Automatically Running Commands on Connect and Disconnect ................235
Troubleshooting the Connection ........................................................................235 The Modem Never Dials ..............................................................................235 The Modem Dials But Never Establishes a Connection ..............................236 The Modem Establishes a Connection, But You Can’t Access
Any Web Sites, and So on After the Connection Has Been Made ............236 Dial-on-demand Sometimes Dials the Modem Even When You Aren’t Trying to Use the Internet ..............................................237 The Internet Connection Never Drops Even Though You Have an Idle Value Set in the options File and You Are Not Using the Internet ............................237 Summary ............................................................................................................237
Q&A ....................................................................................................................238 Workshop ............................................................................................................238 Quiz ..............................................................................................................238 Quiz Answers ................................................................................................239 Exercises ........................................................................................................239 H OUR
15 Network Security 241
Ensuring Password Integrity ..............................................................................242 Weak Passwords ............................................................................................242 Writing Down Passwords ..............................................................................243 What Makes a Good Password? ....................................................................243 Be Aware of Suspicious Activity ..................................................................244 Remote Login Issues ..........................................................................................244 Telnet ............................................................................................................244 rlogin ..............................................................................................................245 SSH ................................................................................................................245
Contents xiii Configuring a Basic Firewall ..............................................................................246 Creating Firewall Rules ................................................................................246
Enabling the Firewall ....................................................................................248 Securing the Console ..........................................................................................249 Security Holes in FreeBSD ................................................................................250 Summary ............................................................................................................250 Q&A ....................................................................................................................251 Workshop ............................................................................................................251
Quiz .............................................................................................................. 251 Quiz Answers ................................................................................................253 Exercises ........................................................................................................253
Part IV FreeBSD as a Workstation 255 H OUR
16 Command-Line Applications 257 Working with Text ..............................................................................................258 The ee Editor ................................................................................................258 Configuring ee ..............................................................................................260 The vi Editor ..................................................................................................262 Email Applications ..............................................................................................264
The Lynx Web Browser ......................................................................................266 Summary ............................................................................................................267 Q&A ....................................................................................................................267 Workshop ............................................................................................................268
Quiz ..............................................................................................................268 Quiz Answers ................................................................................................269 Exercises ........................................................................................................269 Exercise Answers ..........................................................................................269
H OUR
17 Configuring the X Window System 271 More About X ....................................................................................................273 Configuring X ....................................................................................................274 Required Information ....................................................................................275
Using xf86config ..........................................................................................276 Starting X ............................................................................................................285 Summary ............................................................................................................286 Q&A ....................................................................................................................286 Workshop ............................................................................................................287 Quiz ..............................................................................................................287
Quiz Answers ................................................................................................288 Exercises ........................................................................................................288
H OUR
18 The K Desktop Environment (KDE) 289 What Is a Desktop Environment? ......................................................................290 Installing KDE ....................................................................................................290 Making KDE Your Default Window Manager ..................................................290 Starting KDE ......................................................................................................291 Navigating the KDE Desktop ............................................................................292
Virtual Desktops ............................................................................................293 Window Controls ..........................................................................................294 The Window Menu ........................................................................................295 Moving and Resizing Windows ....................................................................296 Restoring Windows ......................................................................................296 The Desktop Menu ........................................................................................297
KDE Applets ......................................................................................................298 The Address Book ........................................................................................298 Text Editors ..................................................................................................300 File Management in KDE ..................................................................................301 Moving and Copying Files and Folders ........................................................302 Deleting Files or Folders ..............................................................................302 Changing File Attributes ..............................................................................302 Searching for Files ........................................................................................303
Customizing Your KDE Desktop ........................................................................304 Changing the Desktop Background ..............................................................304 Adding Desktop Icons ..................................................................................305 Customizing the Menu Bar ..........................................................................305 Customizing the Clock ..................................................................................306 Summary ............................................................................................................306
Q&A ....................................................................................................................306 Workshop ............................................................................................................307 Quiz ..............................................................................................................307 Quiz Answers ................................................................................................308
H OUR