Timothy Boronczyk and Christopher NegusForeword by Karanbir Singh, Core Developer on the CentOS Project
BoronczykNegus
The book you need to succeed!
The first comprehensive guide to CentOS
CentOS is a popular Linux distribution that is created
from freely available enterprise-quality source code.
Using CentOS can help you acquire the skills you need
to become anything from a skilled Linux user to a
professional Linux system administrator. With this
thorough, step-by-step guide, you’ll not only learn how
to install, configure, secure, and run CentOS, but also
how to launch multimedia, add third-party software,
use virtualization, set up networks, and more.
• Install CentOS with anaconda and start configuration
• Master Linux® shell commands and file systems
• Learn your way around the GNOME® and KDE® desktop environments
• Add or update software packages with RPM tools, yum, or PackageKit
• Connect to the Internet and set up wired, wireless, and virtual networks
• Configure print, file, mail, FTP, MySQL® database, Web, and other servers
• Put CentOS to work as a router or firewall and protect your system
Includes DVD with CentOS 5.3
Cen
tOS
Shelving Category:COMPUTERS / Operating Systems / Linux
Reader Level:Beginning to Advanced
$54.99 USA $65.99 Canada
Set up CentOS for your home or business
Build enterprise-quality Linux® servers
Configure full-featured Linux desktop systems
www.wiley.com/compbooks
CentOS
DVD Included!• Full version of CentOS 5.3
Reviewed for technical accuracy by a key member of the CentOS development team!
What’s on the DVD?Find a full version of CentOS 5.3, install it today, and start using CentOS.
System Requirements: See the DVD appendix for details and complete system requirements.
Timothy Boronczykis a professional software developer by day, and a freelance programmer and author by night.
Christopher Negusis the author of the bestselling Red Hat Linux Bible, Linux Toys, and Linux Toolbox series. He is an instructor for Red Hat, Inc., training students for RHCT and RHCE certification.
CentOS Bible
Published byWiley Publishing, Inc.10475 Crosspoint BoulevardIndianapolis, IN 46256www.wiley.com
Copyright © 2009 by Wiley Publishing, Inc., Indianapolis, Indiana
Published simultaneously in Canada
ISBN: 978-0-470-48165-3
Manufactured in the United States of America
10 9 8 7 6 5 4 3 2 1
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form orby any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permittedunder Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written per-mission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copy-right Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600.Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley& Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online athttp://www.wiley.com/go/permissions.
Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations orwarranties with respect to the accuracy or completeness of the contents of this work and specifically dis-claim all warranties, including without limitation warranties of fitness for a particular purpose. No war-ranty may be created or extended by sales or promotional materials. The advice and strategies containedherein may not be suitable for every situation. This work is sold with the understanding that the pub-lisher is not engaged in rendering legal, accounting, or other professional services. If professional assis-tance is required, the services of a competent professional person should be sought. Neither the publishernor the author shall be liable for damages arising herefrom. The fact that an organization or Web site isreferred to in this work as a citation and/or a potential source of further information does not mean thatthe author or the publisher endorses the information the organization or Web site may provide or recom-mendations it may make. Further, readers should be aware that Internet Web sites listed in this work mayhave changed or disappeared between when this work was written and when it is read.
For general information on our other products and services please contact our Customer Care Departmentwithin the United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317)572-4002.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print maynot be available in electronic books.
Library of Congress Control Number: 2009926357
Trademarks: Wiley and the Wiley logo are trademarks or registered trademarks of John Wiley & Sons,Inc. and/or its affiliates, in the United States and other countries, and may not be used without writtenpermission. All other trademarks are the property of their respective owners. Wiley Publishing, Inc. is notassociated with any product or vendor mentioned in this book.
About the AuthorsTimothy Boronczyk is a native of Syracuse, NY, where he works as a software developer byday and a freelance developer, writer, and technical editor by night. He has been involved inweb design since 1998, with Linux since 2001, and over the years has written several articlesand tutorials. Timothy holds a degree in software application programming. In his spare time,he enjoys photography, hanging out with his friends, and sleeping with his feet hanging off theend of his bed. He’s easily distracted by shiny objects.
Christopher Negus is the author of the best-selling Red Hat Linux Bible series, as well asthe author of Linux Toys, Linux Toolbox series, Linux Troubleshooting Bible, Linux Bible 2009edition, and dozens of other UNIX and Linux books. Chris is a Red Hat Certified Engineer(RHCE, cert #805008815534875), instructor (RHCI), and examiner (RHCX). Since 2008, Chrishas been employed by Red Hat, Inc. as an instructor, teaching RHCE-track courses. Earlier inhis career, Chris worked for eight years on development teams for the UNIX operating system atAT&T, where UNIX was created and developed.
About the Technical EditorRalph Angenendt has been working as a system and network administrator since 1998. Afterbeing introduced to Linux in 1995, Ralph’s interest in non-UNIX-like operating systems hasdropped dramatically, so his work environment mostly consists of Linux servers.
Besides having a sweet tooth for domesticating wild mail servers, Ralph also has a strong interestin automated system administration. Because of that he set up cfengine at his current employerto ease the pain of administrating a growing site.
Since 2006, Ralph has been a member of the CentOS development team, where he leads thedocumentation force and does some infrastructure management. He might be met at a few OpenSource conventions in Europe, largely Germany and the Benelux countries.
Credits
Acquisitions EditorJenny Watson
Development EditorTom Dinse
Technical EditorRalph Angenendt
Production EditorDaniel Scribner
Copy EditorCate Caffrey
Editorial ManagerMary Beth Wakefield
Production ManagerTim Tate
Vice President and Executive GroupPublisherRichard Swadley
Vice President and ExecutivePublisherBarry Pruett
Associate PublisherJim Minatel
Project Coordinator, CoverLynsey Stanford
ProofreaderJen Larsen, Word One
IndexerRon Strauss
Cover ImageJoyce Haughey
Cover DesignerMichael E. Trent
Introduction ...................................................................................................................................xxv
Part I Getting StartedChapter 1: An Overview of CentOS .................................................................................................3Chapter 2: Installing CentOS ..........................................................................................................15Chapter 3: Getting Started with the Desktop .................................................................................69Chapter 4: Using Linux Commands .............................................................................................119
Part II Using CentOSChapter 5: Accessing and Running Applications .........................................................................165Chapter 6: Publishing with CentOS .............................................................................................221Chapter 7: Music, Video, and Images in Linux ...........................................................................249Chapter 8: Using the Internet and the Web ................................................................................297
Part III AdminstrationChapter 9: Understanding System Administration .......................................................................345Chapter 10: Setting up and Maintaining User Accounts .............................................................395Chapter 11: Automating System Tasks .........................................................................................427Chapter 12: Creating Backups and Restoring Data ......................................................................467Chapter 13: Security ..................................................................................................................... 505
Part IV NetworkingChapter 14: Setting Up Network Connections and LANs ...........................................................561Chapter 15: Setting Up an Internet Connection ..........................................................................611Chapter 16: Setting Up Printers and Printing ..............................................................................657Chapter 17: Setting Up a File Server ............................................................................................679Chapter 18: Setting Up a Mail Server ...........................................................................................719Chapter 19: Setting Up an FTP Server .........................................................................................751Chapter 20: Setting Up a Web Server ..........................................................................................763Chapter 21: Setting Up an LDAP Address Book Server ...............................................................815Chapter 22: Setting Up a DHCP Boot Server ...............................................................................833Chapter 23: Setting Up a MySQL Database Server ......................................................................845Chapter 24: Making Servers Public with DNS .............................................................................879
Appendix A: About the Media ......................................................................................................907
Index ..............................................................................................................................................911
ix
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv
Part I Getting Started
Chapter 1: An Overview of CentOS . . . . . . . . . . . . . . . . . . . . . 3What You Get with CentOS .........................................................................................5Stepping Stone to Red Hat Enterprise Linux ...............................................................6
What Is Linux? ......................................................................................................................7Linux’s Roots in UNIX .........................................................................................................7Common Linux Features ...................................................................................................10Primary Advantages of Linux ...........................................................................................11Going Forward with CentOS ............................................................................................12
Help from the CentOS Project ....................................................................................12Training and Certification ...........................................................................................13Documentation ............................................................................................................13
Summary ..............................................................................................................................14
Chapter 2: Installing CentOS . . . . . . . . . . . . . . . . . . . . . . . . 15Using the CentOS Live CD ................................................................................................16Quick Installation ..............................................................................................................17Detailed Installation Instructions ...................................................................................18
Installing CentOS 5 .....................................................................................................19Choosing Computer Hardware ...................................................................................21Preparing for Installation Using the Live CD .............................................................22Beginning the Installation ...........................................................................................25Running CentOS Firstboot ..........................................................................................32Going Forward after Installation .................................................................................34
Special Installation Procedures .......................................................................................35Alternatives for Starting Installation ...........................................................................35Installing from Other Media .......................................................................................37Starting a VNC Install .................................................................................................40Performing a Kickstart Installation .............................................................................41
xi
Contents
Special Installation Topics ...............................................................................................46Setting up to Dual-Boot Linux and Windows ............................................................46Partitioning Your Disks ...............................................................................................52Using the GRUB Boot Loader .....................................................................................60
Troubleshooting Installation ............................................................................................65Summary ..............................................................................................................................67
Chapter 3: Getting Started with the Desktop . . . . . . . . . . . . . . . . 69
Logging in to CentOS .........................................................................................................69Getting Familiar with the Desktop .................................................................................72
Touring Your Desktop ................................................................................................72Tips for Configuring Your Desktop ............................................................................79
Using the GNOME Desktop ..............................................................................................80Using the Metacity Window Manager ........................................................................81Using the GNOME Panels ...........................................................................................83Using the Nautilus File Manager ................................................................................88Changing GNOME Preferences ...................................................................................91Managing Removable Media .......................................................................................92Trying Other GNOME Applications ...........................................................................93Exiting GNOME ..........................................................................................................95
Running 3D Accelerated Desktop Effects .......................................................................96Switching Desktop Environments ....................................................................................98Using the KDE Desktop .....................................................................................................98
Starting with KDE .......................................................................................................99KDE Desktop Basics ..................................................................................................100Managing Files with the Konqueror File Manager ...................................................102Using the Konqueror Browser Features ....................................................................107Configuring Konqueror Options ...............................................................................107Managing Windows ...................................................................................................110Configuring the Desktop ...........................................................................................111Adding Widgets .........................................................................................................113
Using the Xfce Desktop Environment ...........................................................................113Troubleshooting Your Desktop ......................................................................................114
GUI Doesn’t Work at Startup ...................................................................................115Tuning Your Video Card and Monitor .....................................................................116Configuring Video Cards for Gaming .......................................................................118Getting More Information .........................................................................................118
Summary ............................................................................................................................118
Chapter 4: Using Linux Commands . . . . . . . . . . . . . . . . . . . . 119
The Shell Interface ...........................................................................................................119Checking Your Login Session ...................................................................................120Checking Directories and Permissions .....................................................................121
xii
Contents
Checking System Activity .........................................................................................123Exiting the Shell ........................................................................................................125
Understanding the Shell ..................................................................................................125Using the Shell in Linux .................................................................................................126
Locating Commands ................................................................................................. 127Rerunning Commands ..............................................................................................129Connecting and Expanding Commands ...................................................................135Using Shell Environment Variables ..........................................................................138Managing Background and Foreground Processes ...................................................141Configuring Your Shell .............................................................................................143
Working with the Linux File System ............................................................................147Creating Files and Directories ...................................................................................149Moving, Copying, and Deleting Files .......................................................................155
Using the vi Text Editor ..................................................................................................155Starting with Vi .........................................................................................................156Moving around the File ............................................................................................159Searching for Text .....................................................................................................159Using Numbers with Commands .............................................................................160
Summary ............................................................................................................................161
Part II Using CentOS
Chapter 5: Accessing and Running Applications . . . . . . . . . . . . . 165
Getting and Installing Software Packages ...................................................................166Downloading and Installing Applications with yum ............................................... 167Getting CentOS Software Updates ............................................................................175
Managing RPM Packages ................................................................................................176Using the Add/Remove Window ..............................................................................176Using the rpm Command .........................................................................................178
Using Software in Different Formats ............................................................................188Understanding Software Package Names and Formats ............................................189Understanding Different Archive Formats ................................................................191Building and Installing from Source Code ...............................................................191
Using CentOS to Run Applications ...............................................................................195Finding Common Desktop Applications in Linux ...................................................196Investigating Your Desktop .......................................................................................196Starting Applications from a Menu ...........................................................................198Starting Applications from a Run Application Window ..........................................198Starting Applications from a Terminal Window ......................................................199Running Remote X Applications ...............................................................................201
Running Microsoft Windows, DOS, and Macintosh Applications ..........................205Running DOS Applications .......................................................................................207Running Microsoft Windows Applications in Linux ............................................... 209
xiii
Contents
Running Applications in Virtual Environments ..........................................................214Running Applications Virtually with Xen .................................................................214Running Applications Virtually with KVM and QEMU ...........................................218
Summary ............................................................................................................................220
Chapter 6: Publishing with CentOS . . . . . . . . . . . . . . . . . . . . 221
Desktop Publishing in Linux ..........................................................................................222Using Text Editors and Notepads .............................................................................222Using Word Processors .............................................................................................222
Using Traditional Linux Publishing Tools ...................................................................226Creating Documents in Groff or LaTeX ...................................................................227Text Processing with Groff ........................................................................................228Text Processing with TeX/LaTeX ..............................................................................231Converting Documents .............................................................................................233Creating DocBook Documents ..................................................................................234Understanding SGML and XML ...............................................................................235
Displaying PDF Files with Evince .................................................................................238Doing Page Layout with Scribus ...................................................................................239Working with Graphics ...................................................................................................241
Manipulating Images with GIMP ..............................................................................241Taking Screen Captures ............................................................................................243Creating Vector Graphic Images with Inkscape .......................................................244
Using Scanners Driven by SANE ...................................................................................246Web Publishing .................................................................................................................247Summary ............................................................................................................................248
Chapter 7: Music, Video, and Images in Linux . . . . . . . . . . . . . . 249
Understanding Multimedia and Legal Issues in Linux ..............................................250Extending Freedom to Codecs ....................................................................................... 251Listening to Music in Linux ...........................................................................................251
Configuring a Sound Card ........................................................................................253Choosing Audio Players ............................................................................................259Automatically Playing CDs ........................................................................................260Playing and Managing Music with Rhythmbox .......................................................261Playing Music with XMMS Audio Player .................................................................264Using ogg123, mpg321, and play Command-Line Players .....................................267Using MIDI Audio Players ........................................................................................268Converting Audio Files with SoX .............................................................................268Extracting and Encoding Music ................................................................................271Creating Your Own Music CDs ................................................................................274Creating CD Labels with cdlabelgen ........................................................................277
Viewing TV and Webcams ..............................................................................................278Watching TV with Tvtime ........................................................................................279Videoconferencing and VOIP with Ekiga .................................................................281
xiv
Contents
Playing Video ....................................................................................................................285Examining Laws Affecting Video and Linux ............................................................285Understanding Video Content Types .......................................................................286Watching Video with Xine ........................................................................................288Using Totem Movie Player ........................................................................................292
Using a Digital Camera ...................................................................................................293Displaying Images in gThumb ..................................................................................293Using Your Camera as a Storage Device .................................................................. 295
Summary ............................................................................................................................296
Chapter 8: Using the Internet and the Web . . . . . . . . . . . . . . . . 297Overview of Internet Applications and Commands ...................................................297Browsing the Web ............................................................................................................300
Understanding Web Browsing ..................................................................................301Browsing the Web with Firefox ................................................................................305Setting Up Firefox .....................................................................................................308Using Text-Based Web Browsers ..............................................................................316
Communicating with E-Mail ..........................................................................................317E-Mail Basics ............................................................................................................. 319Using Evolution E-Mail .............................................................................................320Thunderbird Mail Client ...........................................................................................322Text-Based Mail Programs .........................................................................................324
Participating in Newsgroups ..........................................................................................326Instant Messaging with Pidgin .......................................................................................326Sharing Files with BitTorrent ........................................................................................328Using Remote Login, Copy, and Execution .................................................................329
Using Telnet for Remote Login .................................................................................330Copying Files with FTP ............................................................................................331Getting Files with Wget ............................................................................................337Using ssh for Remote Login/Remote Execution .......................................................339Using scp for Remote File Copy ...............................................................................340Using the ‘‘r’’ Commands: rlogin, rcp, and rsh ........................................................341
Summary ............................................................................................................................341
Part III Adminstration
Chapter 9: Understanding System Administration . . . . . . . . . . . . 345Using the root User Account ..........................................................................................346Becoming Super User (the su Command) ....................................................................346Learning about Administrative GUI Tools, Commands, Configuration
Files, and Log Files .....................................................................................................348Using Graphical Administration Tools .....................................................................348Administrative Commands ........................................................................................353Administrative Configuration Files ...........................................................................354
xv
Contents
Administrative Log Files ...........................................................................................358Using Other Administrative Logins ..........................................................................358
Administering Your Linux System .................................................................................360Configuring Hardware .....................................................................................................361
Checking Your Hardware ..........................................................................................361Managing Hardware with HAL .................................................................................361Reconfiguring Hardware with kudzu .......................................................................362Configuring Modules .................................................................................................364
Managing File Systems and Disk Space .......................................................................366Mounting File Systems ..............................................................................................369Using the mkfs Command to Create a File System .................................................377Adding a Hard Disk ..................................................................................................378Using RAID Disks ......................................................................................................381Checking System Space .............................................................................................382
Monitoring System Performance ...................................................................................385Watch Computer Usage with System Monitor .........................................................385Monitoring CPU Usage with top ..............................................................................386Monitoring Power Usage on Laptop Computers ......................................................387
Using Security Enhanced Linux .....................................................................................388Understanding Security Enhanced Linux .....................................................................389
Types and Roles in SELinux .....................................................................................389Users in SELinux .......................................................................................................390Policies in SELinux ....................................................................................................390Tools in SELinux .......................................................................................................390
Using SELinux in CentOS ...............................................................................................391SELinux .....................................................................................................................391Checking Whether SELinux Is On ...........................................................................392Checking SELinux Status ..........................................................................................393
Summary ............................................................................................................................394
Chapter 10: Setting up and Maintaining User Accounts . . . . . . . . . . 395
Creating User Accounts ...................................................................................................395Adding Users with useradd .......................................................................................396Adding Users with User Manager .............................................................................400
Setting User Defaults .......................................................................................................402Supplying Initial Login Scripts .................................................................................405Supplying Initial .bashrc and .bash_profile Files .....................................................406Supplying an Initial .tcshrc File ................................................................................407Configuring System-Wide Shell Options ..................................................................407Setting System Profiles ..............................................................................................408Adding User Accounts to Servers .............................................................................409
Creating Portable Desktops ............................................................................................410Providing Support to Users ............................................................................................411
xvi
Contents
Creating a Technical Support Mailbox .....................................................................412Resetting a User’s Password ......................................................................................412
Modifying Accounts .........................................................................................................413Modifying User Accounts with usermod ..................................................................413Modifying User Accounts with User Manager ..........................................................415
Deleting User Accounts ...................................................................................................416Deleting User Accounts with userdel .......................................................................417Deleting User Accounts with User Manager .............................................................418
Checking Disk Quotas .....................................................................................................418Using Quota to Check Disk Usage ...........................................................................418Using du to Check Disk Use ....................................................................................423Removing Temp Files Automatically ........................................................................423
Sending Mail to All Users ...............................................................................................424Summary ............................................................................................................................425
Chapter 11: Automating System Tasks . . . . . . . . . . . . . . . . . . 427
Understanding Shell Scripts ...........................................................................................427Executing and Debugging Shell Scripts ....................................................................428Understanding Shell Variables ..................................................................................429Performing Arithmetic in Shell Scripts .....................................................................431Using Programming Constructs in Shell Scripts ......................................................432Some Useful External Programs ................................................................................438Trying Some Simple Shell Scripts .............................................................................439
System Initialization ........................................................................................................441Starting init ................................................................................................................442The inittab File ..........................................................................................................442
System Startup and Shutdown ......................................................................................446Starting Run-Level Scripts .........................................................................................447Understanding Run-Level Scripts .............................................................................447Understanding What Start-Up Scripts Do ................................................................450Changing Run-Level Script Behavior ........................................................................452Reorganizing or Removing Run-Level Scripts ..........................................................453Adding Run-Level Scripts .........................................................................................455Managing xinetd Services ..........................................................................................456Manipulating Run Levels .......................................................................................... 457
Scheduling System Tasks ................................................................................................458Using at.allow and at.deny ....................................................................................... 458Specifying When Jobs Are Run ................................................................................ 458Submitting Scheduled Jobs .......................................................................................459Viewing Scheduled Jobs ............................................................................................460Deleting Scheduled Jobs ...........................................................................................460Using the batch Command .......................................................................................461Using the cron Facility ..............................................................................................461
Summary ............................................................................................................................465
xvii
Contents
Chapter 12: Creating Backups and Restoring Data . . . . . . . . . . . . 467
Making a Simple Backup Archive .................................................................................467Doing a Simple Backup with rsync ...............................................................................469
Backing Up Files Locally ...........................................................................................469Backing Up Files Remotely .......................................................................................470
Choosing Backup Tools ..................................................................................................472Selecting a Backup Strategy ...........................................................................................472
Full Backup ...............................................................................................................473Incremental Backup ...................................................................................................473Disk Mirroring ...........................................................................................................473Network Backup ........................................................................................................474
Selecting a Backup Medium ...........................................................................................474Magnetic Tape ...........................................................................................................474Writable CD Drives ...................................................................................................476Writable DVD Drives ................................................................................................480Writing CDs or DVDs with growisofs ......................................................................481
Backing Up to a Hard Drive ...........................................................................................482Backing Up Files with dump ..........................................................................................483
Creating a Backup with dump ..................................................................................484Understanding Dump Levels ....................................................................................486
Automating Backups with cron .....................................................................................487Restoring Backed-Up Files ..............................................................................................488
Restoring an Entire File System ................................................................................490Recovering Individual Files .......................................................................................491
Configuring Amanda for Network Backups ................................................................493Creating Amanda Directories ....................................................................................494Creating the amanda.conf file ...................................................................................495Creating a disklist File ..............................................................................................497Adding Amanda Network Services ...........................................................................498Performing an Amanda Backup ................................................................................499
Using the pax Archiving Tool ........................................................................................499Summary ............................................................................................................................503
Chapter 13: Security . . . . . . . . . . . . . . . . . . . . . . . . . . . 505
Linux Security Checklist .................................................................................................505Using Password Protection .............................................................................................508
Choosing Good Passwords ........................................................................................508Using a Shadow Password File .................................................................................509
Securing Linux with iptables Firewalls ........................................................................511Using the Security Level Configuration Window .....................................................512Configuring an iptables Firewall ...............................................................................513
Controlling Access to Services with TCP Wrappers ..................................................525Checking Log Files ...........................................................................................................528
xviii
Contents
Replacing the sysklogd Package ................................................................................528Understanding the rsyslogd Service ..........................................................................528Tracking Log Messages with logwatch .....................................................................531
Using the Secure Shell Package .....................................................................................532Starting the SSH Service ........................................................................................... 533Using the ssh, sftp, and scp commands ...................................................................533Using SSH, SCP, and SFTP without Passwords .......................................................535
Securing Linux Servers ....................................................................................................536Understanding Attack Techniques ............................................................................536Protecting against Denial-of-Service Attacks ............................................................537Protecting against Distributed DOS Attacks .............................................................540Protecting against Intrusion Attacks .........................................................................544Securing Servers with SELinux .................................................................................548Protecting Web Servers with Certificates and Encryption .......................................548
Summary ............................................................................................................................558
Part IV Networking
Chapter 14: Setting Up Network Connections and LANs . . . . . . . . . 561
Connecting to the Network with NetworkManager ...................................................561Connecting to a Wireless Network ...........................................................................563Connecting to a Wired Network ..............................................................................563Setting Up a Virtual Private Network Connection ...................................................564
Understanding Local Area Networks ............................................................................565Planning, Getting, and Setting Up LAN Hardware ..................................................566Configuring TCP/IP for Your LAN ...........................................................................571
Setting Up a Wireless LAN .............................................................................................575Understanding Wireless Networks ...........................................................................576Choosing Wireless Hardware ....................................................................................577Getting Wireless Drivers ...........................................................................................582Installing Wireless Linux Software ...........................................................................584Configuring the Wireless LAN ..................................................................................584Testing Distances .......................................................................................................590Setting Wireless Extensions ......................................................................................590
Understanding Internet Protocol Addresses ................................................................591IP Address Classes .....................................................................................................593Understanding Netmasks ..........................................................................................593Classless Inter-Domain Routing ................................................................................594Getting IP Addresses .................................................................................................596
Troubleshooting Your LAN .............................................................................................597Did Linux Find Your Ethernet Driver at Boot Time? ..............................................597Can You Reach Another Computer on the LAN? ....................................................597Is Your Ethernet Connection Up? .............................................................................598
xix
Contents
Troubleshooting a Wireless LAN ..............................................................................600Watching LAN Traffic with Wireshark .....................................................................604
Summary ............................................................................................................................609
Chapter 15: Setting Up an Internet Connection . . . . . . . . . . . . . . 611Understanding How the Internet Is Structured ..........................................................611
Internet Domains .......................................................................................................613Hostnames and IP Addresses ....................................................................................615Routing ......................................................................................................................616Proxies .......................................................................................................................617
Using Dial-Up Connections to the Internet .................................................................617Getting Information ...................................................................................................617Setting Up Dial-Up PPP ............................................................................................618Creating a Dial-Up Connection with the Network Configuration Window ...........619Launching Your PPP Connection .............................................................................621Launching Your PPP Connection on Demand .........................................................621Checking Your PPP Connection ...............................................................................622
Connecting Your LAN to the Internet ...........................................................................629Setting Up Linux as a Router .........................................................................................630
Configuring the Linux Router ...................................................................................630Configuring Network Clients ....................................................................................633
Configuring a Virtual Private Network Connection ...................................................634Understanding IPsec ..................................................................................................635Using IPsec Protocols ................................................................................................635Using IPsec in CentOS ..............................................................................................636Configuring an OpenVPN Server .............................................................................637
Setting Up Linux as a Proxy Server ..............................................................................643Starting the Squid Daemon .......................................................................................644Using a Simple squid.conf File .................................................................................645Modifying the Squid Configuration File ...................................................................648Debugging Squid .......................................................................................................651
Setting Up Proxy Clients .................................................................................................653Configuring Firefox to Use a Proxy ..........................................................................654Configuring Other Browsers to Use a Proxy ............................................................655
Summary ............................................................................................................................655
Chapter 16: Setting Up Printers and Printing . . . . . . . . . . . . . . . 657Common UNIX Printing Service ....................................................................................658Setting Up Printers .......................................................................................................... 658
Using the Printer Configuration Window ................................................................659Using Web-Based CUPS Administration ..................................................................667Configuring the CUPS Server (cupsd.conf) ..............................................................670Configuring CUPS Printer Options ..........................................................................672
Using Printing Commands ..............................................................................................673Using lpr to Print ......................................................................................................673
xx
Contents
Listing Status with lpc ...............................................................................................674Removing Print Jobs with lprm ................................................................................674
Configuring Print Servers ...............................................................................................675Configuring a Shared CUPS Printer .........................................................................675Configuring a Shared Samba Printer ........................................................................676
Summary ............................................................................................................................677
Chapter 17: Setting Up a File Server . . . . . . . . . . . . . . . . . . . 679Goals of Setting Up a File Server ..................................................................................679Setting Up an NFS File Server .......................................................................................680
Sharing NFS File Systems .........................................................................................682Using NFS File Systems ............................................................................................689Unmounting NFS File Systems .................................................................................694Other Cool Things to Do with NFS .........................................................................695
Setting Up a Samba File Server .....................................................................................696Getting and Installing Samba ....................................................................................697Configuring a Simple Samba Server .........................................................................698Configuring Samba with SWAT ............................................................................... 701Working with Samba Files and Commands .............................................................710Setting Up Samba Clients .........................................................................................714Troubleshooting Your Samba Server ........................................................................715
Summary ............................................................................................................................718
Chapter 18: Setting Up a Mail Server . . . . . . . . . . . . . . . . . . . 719Introducing SMTP and Sendmail ..................................................................................719Installing and Running Sendmail ..................................................................................720
Starting Sendmail ......................................................................................................721Other Programs .........................................................................................................722Logging Performed by Sendmail ...............................................................................722
Configuring Sendmail ......................................................................................................724Getting a Domain Name ...........................................................................................725Configuring Basic Sendmail Settings (sendmail.mc) ................................................725Defining Outgoing Mail Access .................................................................................729Configuring Virtual Servers .......................................................................................731Configuring Virtual Users .........................................................................................732Adding User Accounts ..............................................................................................733Starting Sendmail and Generating Database Files ....................................................733Re-Directing Mail ......................................................................................................734
Introducing Postfix ..........................................................................................................737Stopping Spam with SpamAssassin ..............................................................................738
Using SpamAssassin ..................................................................................................738Setting Up SpamAssassin on Your Mail Server ........................................................739Setting E-Mail Readers to Filter Spam ......................................................................741
Getting Mail from the Server (POP3 or IMAPv4) .......................................................741Accessing Mailboxes in Linux ...................................................................................742
xxi
Contents
Configuring IMAPv4 and POP3 with Dovecot .........................................................743Getting Mail from Your Browser with SquirrelMail ..................................................744Administering a Mailing List with Mailman ...............................................................746Summary ............................................................................................................................749
Chapter 19: Setting Up an FTP Server . . . . . . . . . . . . . . . . . . 751Understanding FTP Servers ............................................................................................752
Attributes of FTP Servers ..........................................................................................752FTP User Types .........................................................................................................753
Using the Very Secure FTP Server .................................................................................753Quick-Starting vsFTPd ..............................................................................................754Configuring vsFTPd ..................................................................................................755
Getting More Information about FTP Servers .............................................................761Summary ............................................................................................................................761
Chapter 20: Setting Up a Web Server . . . . . . . . . . . . . . . . . . . 763Introduction to Web Servers ..........................................................................................764
The Apache Web Server ...........................................................................................764Other Web Servers Available for CentOS ................................................................765
Quick-Starting the Apache Web Server ........................................................................766Configuring the Apache Server ......................................................................................768
Configuring the Web Server (httpd.conf) ................................................................769Configuring Modules and Related Services (/etc/httpd/conf.d/*.conf) ....................804
Starting and Stopping the Server ..................................................................................806Monitoring Server Activities ...........................................................................................807
Displaying Server Information ..................................................................................808Displaying Server Status ............................................................................................808Further Security of Server-Info and Server-Status ...................................................810Logging Errors ...........................................................................................................811Logging Hits ..............................................................................................................811Analyzing Web-Server Traffic ...................................................................................812
Summary ............................................................................................................................814
Chapter 21: Setting Up an LDAP Address Book Server . . . . . . . . . . 815Understanding LDAP .......................................................................................................816
Defining Information in Schemas .............................................................................817Structuring Your LDAP Directories ..........................................................................819
Setting Up the OpenLDAP Server ..................................................................................819Installing OpenLDAP Packages .................................................................................819Configuring the OpenLDAP Server (slapd.conf) ......................................................819Starting the OpenLDAP Service ................................................................................822
Setting Up the Address Book .........................................................................................822More Ways to Configure LDAP ..................................................................................... 828Accessing an LDAP Address Book from Thunderbird ...............................................829Summary ............................................................................................................................831
xxii
Contents
Chapter 22: Setting Up a DHCP Boot Server . . . . . . . . . . . . . . . 833Using the Dynamic Host Configuration Protocol .......................................................834Setting Up a DHCP Server ..............................................................................................834
Opening Your Firewall and SELinux for DHCP ......................................................835Configuring the /etc/dhcpd.conf File ........................................................................836Starting the DHCP Server .........................................................................................842
Setting Up a DHCP Client ..............................................................................................843Summary ............................................................................................................................844
Chapter 23: Setting Up a MySQL Database Server . . . . . . . . . . . . 845Finding MySQL Packages ...............................................................................................846Configuring the MySQL Server ......................................................................................848
Using MySQL User/Group Accounts ........................................................................848Adding Administrative Users ....................................................................................848Setting MySQL Options ............................................................................................849Using Sample my.cnf Files ........................................................................................854
Starting the MySQL Server .............................................................................................855Checking That MySQL Server Is Working ...................................................................856Working with MySQL Databases ..................................................................................857
Starting the mysql Command ...................................................................................857Creating a Database with MySQL .............................................................................858Adding Data to a MySQL Database Table ................................................................860
Understanding MySQL Tables .......................................................................................863Displaying MySQL Databases ........................................................................................868
Displaying All or Selected Records ...........................................................................868Displaying Selected Columns ....................................................................................869Sorting Data ...............................................................................................................870
Making Changes to Tables and Records ......................................................................871Altering the Structure of MySQL Tables ..................................................................871Updating and Deleting MySQL Records ...................................................................872
Adding and Removing User Access ...............................................................................873Adding Users and Granting Access ..........................................................................873Revoking Access ........................................................................................................874
Backing Up Databases ....................................................................................................875Checking and Fixing Databases ....................................................................................875Summary ............................................................................................................................877
Chapter 24: Making Servers Public with DNS . . . . . . . . . . . . . . 879Determining Goals for Your Server ...............................................................................880
Using a Hosting Service ............................................................................................880Connecting a Public Server ............................................................................................881
Choosing an ISP ........................................................................................................881Getting a Domain Name ...........................................................................................884
Configuring Your Public Server .....................................................................................886Configuring Networking ...........................................................................................886
xxiii
Contents
Configuring Servers ...................................................................................................887Managing Security .....................................................................................................888
Setting Up a Domain Name System Server .................................................................890Understanding DNS ..................................................................................................890DNS Name Server Example ......................................................................................894Quick-Starting a DNS Server ....................................................................................895Checking That DNS Is Working ...............................................................................903
Getting More Information about BIND ........................................................................905Summary ............................................................................................................................905
Appendix A: About the Media . . . . . . . . . . . . . . . . . . . . . . 907
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 911
xxiv
W ith the CentOS operating system and the instructions provided in this book, you cantransform your computers into free, safe, and powerful enterprise-class systems. Notonly can you configure your server to share files, printers, web pages, or directory
services to other computers, but you can also use CentOS on everyday workstations as well tobenefit from its security and stability.
Because CentOS includes enterprise-class software, the skills you learn by using CentOS can beapplied to work with the largest, most secure, and most diverse Linux systems in the world.Using this book is a great start for becoming a Linux professional.
Who You AreYou don’t need to be a programmer to take advantage of this book. Perhaps you are someonewho just wants to use Linux to run programs, access the Internet, and so on. Or, perhaps youare someone who wants to learn how to administer an enterprise-grade Linux system.
We assume that you are somewhat computer literate but may have little or no experience withLinux (or UNIX). You may be migrating from Microsoft operating systems to Linux because of itsnetworking and multiuser features. You may be looking to start a career as a computer technicianor network administrator and find that spending a few dollars for an entire operating system andbook is more economical than taking those technical classes offered on late-night television. Oryou might just think a ‘‘free’’ enterprise operating system is cool.
This Book’s Learn-Through-Tasks ApproachThe best way to learn a computer system is to get your hands on it. To help you learn Linuxand CentOS, this book takes a task-oriented approach. Where possible, we step you through theprocess of working with a feature, such as setting up a network or configuring your desktop.
When you are done with a task, you should have a good, basic setup of the feature that it covers.After that, we often provide pointers to further information on tweaking and tuning the feature.
Instead of assuming that you already know about cryptic topics such as DNS, NFS, and TCP/IP,we ease you into those features with headings such as ‘‘Making Your Servers Public,’’ ‘‘Setting Up
xxv
Introduction
a File Server,’’ and ‘‘Connecting to the Internet.’’ If you already knew what all those things wereand how to get them working, you wouldn’t need us, would you?
You will find that there are a lot of choices available in the Linux world. When many tools canbe used to achieve the same results, we usually present one or two examples. In other words,we don’t describe six different Web browsers, 12 different text editors, and three different mailservers. We tell you how to get one or two similar tools really working and then note that othersare available.
What You NeedTo follow along with this book, you can install the complete CentOS 5 software found on theaccompanying DVD. If you don’t have a DVD drive, you can use the CD that comes with thisbook to try out CentOS without installing it. Of course, you can also follow along on an existingCentOS system.
To install CentOS with the media that comes with this book, you need a PC with the followgeneral configuration:
■ An Intel Pentium or compatible CPU, 200 MHz Pentium or better (for text mode);400 MHz Pentium II or better (for GUI mode)
■ At least 64 MB of RAM (text-based install) or 128 MB of RAM (graphical install). To runthe GNOME or KDE desktops, 192 MB are needed, although the CentOS Project recom-mends at least 512 MB.
■ At least 3.0 GB of hard disk space for a typical workstation installation, or at least 1.1 GBof space for a server installation
■ A DVD or CD drive. This is recommended for installation (because an installation DVD isprovided along with this book), although you can install CentOS over a network or froma local hard disk instead. Chapter 2 describes methods of launching installations if youdon’t have a bootable DVD drive.
Not every piece of PC hardware works with CentOS. You can see what hardware is supported byvisiting the following site: www.centoslinuxhcl.org.
Conventions Used in This BookThroughout the book, special typography indicates code and commands. Commands and codeare shown in a monospaced font:
This is how code looks
xxvi
Introduction
In the event that an example includes both input and output, the monospaced font is still used,but input is presented in bold type to distinguish the two. Here’s an example:
$ ftp ftp.example.comName (home:timothy): timothyPassword: *****
The following boxes are used to call your attention to points that are particular important.
A Note box provides extra information to which you need to pay special attention.
A Tip box shows a special way of performing a particular task.
A Warning box alerts you to take special care when executing a procedure, or damageto your computer hardware or software could result.
A Cross-Reference box refers you to further information on a subject that you can findoutside the current chapter.
How This Book Is OrganizedThis book is organized into four parts: Getting Started, Using CentOS, Administration, and Net-working.
Part I: Getting StartedPart I consist of Chapters 1 through 4. Chapters 1 and 2 contain brief descriptions of the Linuxtechnology and tell you what you need to get the operating system installed. Chapter 1 servesas an introduction to the Linux OS and to CentOS in particular. Chapter 2 discusses what youneed to install CentOS and how to make the decisions you’ll be faced with during installation. Itincludes procedures for installing from DVD, hard disk, or network connections (NFS, FTP, orHTTP servers).
In Chapter 3, you learn about the GNOME and KDE desktop environments. These GUIs providegraphical means of using CentOS. Chapter 4 describes ways of exploring and understandingCentOS primarily from the Linux shell command interpreter. You learn how to use the bashshell, the vi text editor, and the commands for moving around the Linux file system.
Part II: Using CentOSPart II consists of Chapters 5 through 8, which include information for the average user whowants to use Linux to run applications and access the Internet.
xxvii
Introduction
Chapter 5 contains information on obtaining, installing, and running Linux applications. It alsohelps you run applications from other operating systems in Linux. Chapter 6 describes bothold-time publishing tools and new, graphical word processors that are available with CentOS.Old tools include the troff and TeX text processing tools, whereas newer publishing softwareincludes OpenOffice.org (included on the DVD) and StarOffice (available commercially).
Chapter 7 describes how to use audio and video players, as well as how to configure soundcards and CD burners. Chapter 9 describes tools for browsing the Web (such as the Firefox Webbrowser) and related tools (such as e-mail clients).
Part III: AdministrationPart III consists of Chapters 9 through 13, which cover general set-up and system mainte-nance tasks, including how to set up user accounts, automate system tasks, and back up yourdata. Chapter 9, in which you learn what you need to know about basic system administration,describes the root login, administrative commands, configuration files, SELinux, and log files.Chapter 10 describes how to set up and provide support for multiple users on your CentOSsystem.
In Chapter 11, you learn to create shell scripts and to use the cron facility to automate a varietyof tasks on your CentOS system. Techniques for backing up your system and restoring filesfrom backup are described in Chapter 12. Chapter 13 describes issues related to securing yourcomputing assets in CentOS.
Part IV: NetworkingPart IV consists of Chapters 14 through 24, which describe step-by-step procedures for settingup a variety of server types. Simple configurations for what might otherwise be complex tasksare contained in each chapter. Learn to arrange, address, and connect your Linux computes toa local area network (LAN) in Chapter 14. Chapter 15 describes techniques for connecting yourCentOS computer and LAN to the Internet, using features such as Point-to-Point Protocol (PPP),IP forwarding, IP masquerading, routing, and proxy servers.
Chapter 16 describes how to set up different types of print server interfaces, including Samba (toshare with Windows systems) and native Linux CUPS printing. Chapter 17 describes file servers,such as Network File System (NFS) servers and Samba file servers. Chapter 18 describes how toconfigure Sendmail or Postfix e-mail servers.
Chapter 19 describes how to configure and secure an FTP server, as well as how to access theserver using FTP client programs. Chapter 20 teaches you how to set up CentOS as a Web Server,focusing on the popular Apache server software. Chapter 21 explains how to use LDAP to create ashared address book. Chapter 22 describes how to set up a DHCP server to distribute informationto client workstations on the network.
Chapter 23 describes how to set up and use a MySQL database server in CentOS. Chapter 24takes you through the process of making the servers you configured in the other chapters avail-able on the Internet by setting up a Domain Name System (DNS) server.
xxviii