Tải bản đầy đủ (.pdf) (838 trang)

IT training wiley ubuntu linux secrets apr 2009

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (29.92 MB, 838 trang )



Ubuntu Linux
Secrets
®

®



Ubuntu Linux
Secrets
®

Richard Blum

®


Ubuntu® Linux® Secrets
Published by
Wiley Publishing, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com
Copyright © 2009 by Wiley Publishing, Inc., Indianapolis, Indiana
Published simultaneously in Canada
ISBN: 978-0-470-39508-0
Manufactured in the United States of America
10 9 8 7 6 5 4 3 2 1
Library of Congress Cataloging-in-Publication Data


Blum, Richard, 1962–
Ubuntu Linux secrets / Richard Blum.
p. cm.
Includes index.
ISBN 978-0-470-39508-0 (paper/website)
1. Ubuntu (Electronic resource) 2. Linux. 3. Operating systems (Computers) I. Title.
QA76.76.O63B5984 2009
005.4'32—dc22
2009005635
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means,
electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108
of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization
through payment of the appropriate per-copy fee to the Copyright 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) 7486008, or online at />Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with
respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including
without limitation, warranties of fitness for a particular purpose. No warranty may be created or extended by sales or
promotional materials. The advice and strategies contained herein may not be suitable for every situation. This work is
sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services. If professional assistance is required, the services of a competent professional person should be sought. Neither the
publisher nor the author shall be liable for damages arising herefrom. The fact that an organization or web site is referred
to in this work as a citation and/or a potential source of further information does not mean that the author or the publisher
endorses the information the organization or web site may provide or recommendations it may make. Further, readers
should be aware that Internet web sites listed in this work may have 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 Department within the
United States at (877) 762-2974 or outside the United States at (317) 572-3993 or fax (317) 572-4002.
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 written permission. Ubuntu is a registered trademark of Canonical Limited. Linux is a registered trademark of Linus Torvalds. All other trademarks are the
property of their respective owners. Wiley Publishing, Inc. is not associated with any product or vendor mentioned in this
book.

Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available
in electronic books.


To my family. “By wisdom a house is built, and through
­understanding it is established; through knowledge its
rooms are filled with rare and beautiful treasures.”
—Proverbs 24:3–4 (NIV)


About the Author
Richard Blum has worked in the IT industry for over 20 years as both a systems and
network administrator. During that time he has administered UNIX, Linux, Novell, and
Microsoft servers, as well as helped manage desktop workstations on a 3,500-user network. He has used Linux since the days of loading the system from floppy disks and has
utilized Ubuntu workstations and servers in his environment.
Rich has a bachelor of science degree in electrical engineering and a master of science
degree in management, specializing in management information systems, from Purdue
University. He is the author of several Linux books, including Linux Command Line and
Shell Script Bible, Professional Assembly Language Programming, Network Performance
Open Source Toolkit, sendmail for Linux, Running qmail, Postfix, and Open Source E‑mail
Security. He’s also a coauthor of Professional Linux Programming, and Linux for Dummies,
8th Edition. When he’s not being a computer nerd, Rich plays bass guitar for his church
worship band and enjoys spending time with his wife, Barbara, and their two daughters,
Katie Jane and Jessica.


Credits
Acquisitions Editor
Jenny Watson
Senior Development Editor

Tom Dinse
Technical Editor
Warren Wyrostek
Production Editor
Rebecca Coleman
Copy Editor
Publication Services, Inc.
Editorial Manager
Mary Beth Wakefield
Production Manager
Tim Tate
Vice President and Executive
Group Publisher
Richard Swadley

Vice President and Executive
Publisher
Barry Pruett
Associate Publisher
Jim Minatel
Project Coordinator, Cover
Lynsey Stanford
Compositor
Maureen Forys,
Happenstance Type-O-Rama
Proofreader
Word One
Indexer
Robert Swanson
Cover Designer

Ryan Sneed


Acknowledgments
First, all glory and praise go to God, who through His Son makes all things possible and
gives us the gift of eternal life.
Many thanks go to the great team of people at Wiley Publishing for their outstanding
work on this project. Thanks to Jenny Watson, the acquisitions editor, for offering me the
opportunity to work on this book. Also, thanks to Tom Dinse, the development editor, for
keeping things on track and making this book more presentable. The technical editor,
Warren Wyrostek, did an amazing job of double-checking all the work in this book, plus
making suggestions to improve the content. Thanks, Warren, for your hard work and
diligence. I would also like to thank Carole McClendon at Waterside Productions, Inc. for
arranging this opportunity for me and for helping out in my writing career.
Finally, I would like to thank my parents, Mike and Joyce Blum, for their dedication and
support while raising me, and my wife, Barbara and daughters, Katie Jane and Jessica,
for their love, patience, and understanding, especially while I was writing this book.


Contents at a Glance
Introduction............................................................................................................................................. xxv

Part 1: Starting Out with Ubuntu....................................................................... 1
Chapter 1: What is Ubuntu?....................................................................................................................... 3
Chapter 2: Playing with the LiveCD....................................................................................................... 25
Chapter 3: Installing Ubuntu....................................................................................................................47
Chapter 4: Exploring the Desktop............................................................................................................79

Part 2: Starting Out with Ubuntu.................................................................. 107
Chapter 5: File Management..................................................................................................................109

Chapter 6: Working With Text............................................................................................................... 135
Chapter 7: The OpenOffice Suite...........................................................................................................161
Chapter 8: Network Applications...........................................................................................................197
Chapter 9: Evolution............................................................................................................................... 227
Chapter 10: Image Manipulation.......................................................................................................... 255
Chapter 11: Using Audio........................................................................................................................ 277
Chapter 12: Using Video........................................................................................................................ 295

PART 3: Managing Your Workstation...........................................................313
Chapter 13: Software Installs and Updates...........................................................................................315
Chapter 14: Networking......................................................................................................................... 337
Chapter 15: External Devices................................................................................................................ 367
Chapter 16: The Display......................................................................................................................... 387
Chapter 17: Users and Groups............................................................................................................... 407
Chapter 18: Basic Administration......................................................................................................... 425
Chapter 19: The Ubuntu Command Line..............................................................................................441

PART 4: Using the Ubuntu Server................................................................. 467
Chapter 20: DNS Server......................................................................................................................... 469
Chapter 21: Web Server.......................................................................................................................... 493
Chapter 22: Samba and Print Server.....................................................................................................521
Chapter 23: Email Server....................................................................................................................... 547
Chapter 24: Database Server................................................................................................................. 579


x

Contents at a Glance

Part 5: Programming in Ubuntu.................................................................... 605

Chapter 25: Shell Scripts........................................................................................................................ 607
Chapter 26: Perl and Python.................................................................................................................. 637
Chapter 27: C Programming.................................................................................................................. 661
Chapter 28: Java...................................................................................................................................... 687
Chapter 29: Ruby......................................................................................................................................713
Chapter 30: PHP.......................................................................................................................................741
Index..........................................................................................................................................................771


Contents
Introduction............................................................................................................................................. xxv

Part 1: Starting Out with Ubuntu....................................................................... 1
Chapter 1: What is Ubuntu?............................................................................................................ 3
What Is Linux?............................................................................................................................................. 4
The Linux Kernel.................................................................................................................................... 4
The GNU Utilities................................................................................................................................. 11
The Linux Desktop Environment........................................................................................................ 13
Linux Distributions....................................................................................................................................19
Core Linux Distributions...................................................................................................................... 19
Specialized Linux Distributions........................................................................................................... 20
The Linux LiveCD................................................................................................................................ 21
What Is Ubuntu?........................................................................................................................................ 22
Ubuntu Versions................................................................................................................................... 22
Ubuntu Release Schedule.................................................................................................................... 23
Ubuntu Cousins.................................................................................................................................... 24
Summary.................................................................................................................................................... 24

Chapter 2: Playing with the LiveCD........................................................................................... 25
The Ubuntu LiveCD................................................................................................................................. 26

Downloading Ubuntu............................................................................................................................... 26
Downloading from the Web................................................................................................................. 27
Using BitTorrent to Download............................................................................................................. 29
Verifying the File.................................................................................................................................. 32
Creating the LiveCD................................................................................................................................. 34
Burning CDs in Linux........................................................................................................................... 34
Burning CDs in Mac OS X................................................................................................................... 34
Burning CDs in Windows..................................................................................................................... 36
Booting the LiveCD.................................................................................................................................. 36
The Boot Process................................................................................................................................... 37
Using Ubuntu........................................................................................................................................ 37
The LiveCD Desktop............................................................................................................................ 39
Storing Files.......................................................................................................................................... 40
Running Ubuntu in Windows.................................................................................................................. 42
The Wubi Project.................................................................................................................................. 43
Installing in Windows........................................................................................................................... 43
Running Ubuntu in Windows.............................................................................................................. 44
Summary.................................................................................................................................................... 45


xii

Contents

Chapter 3: Installing Ubuntu........................................................................................................ 47
Preparing Your PC.................................................................................................................................... 48
System Requirements........................................................................................................................... 48
Creating a Place for Ubuntu................................................................................................................ 51
Installing from the LiveCD...................................................................................................................... 57
Select a Language................................................................................................................................ 58

Select a Time Zone............................................................................................................................... 58
Select a Keyboard................................................................................................................................. 58
Prepare the Disk Space........................................................................................................................ 60
Create a Login ID................................................................................................................................. 63
Migrate Documents and Settings........................................................................................................ 64
Review Options..................................................................................................................................... 66
Installing from the Alternate Install CD................................................................................................. 67
Guided Partitions.................................................................................................................................. 68
Manual Partitions................................................................................................................................. 69
Server Installation..................................................................................................................................... 70
Main Installation................................................................................................................................... 70
Server Programs................................................................................................................................... 71
Upgrading Ubuntu.....................................................................................................................................75
Summary.................................................................................................................................................... 77

Chapter 4: Exploring the Desktop.............................................................................................. 79
Desktop Features...................................................................................................................................... 80
The Top Panel....................................................................................................................................... 81
The Desktop Workspace...................................................................................................................... 86
The Bottom Panel................................................................................................................................. 87
Modifying the Desktop............................................................................................................................ 89
Adding to the Panel Menus................................................................................................................. 89
Adding Panel Applets.......................................................................................................................... 92
Adding Desktop Icons.......................................................................................................................... 96
Desktop Appearance................................................................................................................................ 97
The Desktop Theme............................................................................................................................. 98
The Background................................................................................................................................... 99
Fonts.................................................................................................................................................... 100
Interface.............................................................................................................................................. 100
Visual Effects...................................................................................................................................... 101

Accessibility Features..............................................................................................................................101
Preferred Applications....................................................................................................................... 102
Keyboard Features............................................................................................................................. 104
Mouse Features.................................................................................................................................. 104
Summary.................................................................................................................................................. 106

Part 2: Starting Out with Ubuntu.................................................................. 107
Chapter 5: File Management......................................................................................................109
The Linux Filesystem..............................................................................................................................110
Filepaths.............................................................................................................................................. 110
Filenames............................................................................................................................................ 113




Contents

xiii

Nautilus.....................................................................................................................................................113
Nautilus Window Components.......................................................................................................... 113
Browser Versus Spatial Mode........................................................................................................... 119
Modifying Nautilus Windows............................................................................................................ 120
Handling Files......................................................................................................................................... 125
Creating New Files and Folders........................................................................................................ 125
Copying and Moving Files................................................................................................................. 126
Running Programs.............................................................................................................................. 126
Deleting Files...................................................................................................................................... 128
File Properties......................................................................................................................................... 128
Basic Properties.................................................................................................................................. 128

Emblems.............................................................................................................................................. 129
Permissions......................................................................................................................................... 130
Open With........................................................................................................................................... 132
Notes.................................................................................................................................................... 133
Summary...................................................................................................................................................133

Chapter 6: Working With Text...................................................................................................135
The gedit Editor...................................................................................................................................... 136
Starting gedit...................................................................................................................................... 136
Basic gedit Features........................................................................................................................... 137
Setting Preferences............................................................................................................................ 138
The Character Map..................................................................................................................................141
The vim Editor..........................................................................................................................................143
The Basics of vim................................................................................................................................ 143
Editing Data........................................................................................................................................ 145
Copy and Paste................................................................................................................................... 146
Search and Substitute........................................................................................................................ 146
The emacs Editor.....................................................................................................................................147
Using emacs on the Console.............................................................................................................. 148
Using emacs in GNOME.................................................................................................................... 152
The Tomboy Notes Application............................................................................................................. 154
Starting Tomboy Notes...................................................................................................................... 154
Creating Notes.................................................................................................................................... 155
Editing Notes...................................................................................................................................... 156
Organizing Notes............................................................................................................................... 157
Changing Preferences........................................................................................................................ 157
Tomboy Add-ins................................................................................................................................. 159
Summary...................................................................................................................................................159

Chapter 7: The OpenOffice Suite..............................................................................................161

The OpenOffice.org Suite.......................................................................................................................162
Word Processing.......................................................................................................................................163
Writer Features................................................................................................................................... 163
Working with Writer Files.................................................................................................................. 167
Spreadsheets.............................................................................................................................................168
The OpenOffice.org Calc Layout...................................................................................................... 168
Working with Calc Files..................................................................................................................... 173


xiv

Contents

Presentations............................................................................................................................................174
Using the Presentation Wizard.......................................................................................................... 174
Taking a Tour of OpenOffice.org Impress........................................................................................ 176
Working with Impress Files............................................................................................................... 179
Database...................................................................................................................................................180
Getting Help from the Wizard........................................................................................................... 180
Taking a Tour of Base........................................................................................................................ 183
Working with Tables.......................................................................................................................... 184
Drawing....................................................................................................................................................186
Taking a Tour of OpenOffice.org Draw............................................................................................ 186
Working with Draw Files................................................................................................................... 189
Math......................................................................................................................................................... 190
Starting Math...................................................................................................................................... 190
The Math Layout................................................................................................................................ 191
Working with Math............................................................................................................................ 193
Summary...................................................................................................................................................195


Chapter 8: Network Applications.............................................................................................197
The Ubuntu Internet Software Suite..................................................................................................... 198
Ekiga........................................................................................................................................................ 198
Firefox...................................................................................................................................................... 200
Walking Through Firefox................................................................................................................... 201
Configuring Firefox............................................................................................................................ 203
Working with Add-ons....................................................................................................................... 210
Pidgin........................................................................................................................................................212
Using the Pidgin Instant Messenger................................................................................................. 213
Pidgin Preferences.............................................................................................................................. 215
Remote Desktop Viewer..........................................................................................................................216
Terminal Server Client............................................................................................................................218
Transmission............................................................................................................................................ 220
gFTP......................................................................................................................................................... 222
Summary.................................................................................................................................................. 224

Chapter 9: Evolution......................................................................................................................227
The Evolution Suite................................................................................................................................. 228
Starting Evolution................................................................................................................................... 228
Obtain Email Client Info.................................................................................................................... 229
Run the Wizard................................................................................................................................... 229
The Evolution Window........................................................................................................................... 238
The Menu Bar..................................................................................................................................... 238
The Toolbar......................................................................................................................................... 239
The Search Tool.................................................................................................................................. 240
The Message List................................................................................................................................ 240
The Sidebar......................................................................................................................................... 242
The Switcher....................................................................................................................................... 242
The Preview Pane............................................................................................................................... 242





Contents

xv

Using Evolution....................................................................................................................................... 242
Sending Messages.............................................................................................................................. 242
Changing the Configuration.............................................................................................................. 244
Mail Filtering.......................................................................................................................................... 247
Filtering Messages............................................................................................................................. 247
Filtering Spam.................................................................................................................................... 249
Backing Up Evolution............................................................................................................................. 250
Using the Address Book......................................................................................................................... 250
Accessing the Calendar and Tasks....................................................................................................... 252
Calendar.............................................................................................................................................. 252
Tasks.................................................................................................................................................... 253
Summary.................................................................................................................................................. 254

Chapter 10: Image Manipulation..............................................................................................255
Eye of GNOME Image Viewer............................................................................................................... 256
Using the Image Viewer.................................................................................................................... 256
Supported File Types......................................................................................................................... 260
The GIMP Image Editor..........................................................................................................................261
Starting GIMP..................................................................................................................................... 261
GIMP Basic Tools............................................................................................................................... 261
Using GIMP........................................................................................................................................ 263
F-Spot Photo Manager............................................................................................................................ 268
The F-Spot Layout.............................................................................................................................. 268

Using the F-Spot Editor...................................................................................................................... 273
Summary.................................................................................................................................................. 276

Chapter 11: Using Audio..............................................................................................................277
Audio File Basics......................................................................................................................................278
Controlling Sound in Ubuntu................................................................................................................ 279
Sound Preferences.............................................................................................................................. 280
The Sound Applet.............................................................................................................................. 282
Rhythmbox.............................................................................................................................................. 284
Playing Audio CDs............................................................................................................................. 284
Playing Audio Files............................................................................................................................ 286
Listening to Internet Audio................................................................................................................ 288
Ripping Audio CDs............................................................................................................................. 289
Brasero..................................................................................................................................................... 290
Sound Recorder....................................................................................................................................... 291
Playing Audio Files from Nautilus........................................................................................................ 292
Summary.................................................................................................................................................. 294

Chapter 12: Using Video..............................................................................................................295
Video Formats......................................................................................................................................... 296
The Totem Movie Player......................................................................................................................... 297
The Totem Interface........................................................................................................................... 298
The Totem Preferences Settings....................................................................................................... 301


xvi

Contents

Watching Web Clips............................................................................................................................... 302

Checking Your Plug-ins..................................................................................................................... 303
Adding Plug-ins.................................................................................................................................. 304
More Video Support........................................................................................................................... 306
Editing Videos......................................................................................................................................... 307
Installing Kino..................................................................................................................................... 308
The Kino Interface.............................................................................................................................. 309
The Kino Preferences Settings.......................................................................................................... 310
Summary...................................................................................................................................................311

PART 3: Managing Your Workstation...........................................................313
Chapter 13: Software Installs and Updates............................................................................ 315
Software Management in Ubuntu..........................................................................................................316
Software Packages............................................................................................................................. 316
Software Repositories......................................................................................................................... 316
Configuring Software Repositories................................................................................................... 317
Installing Updates....................................................................................................................................319
The Update Manager......................................................................................................................... 319
Using the Update Manager Applet................................................................................................... 321
Installing New Applications.................................................................................................................. 322
The Add/Remove Applications Window.......................................................................................... 322
Adding a New Application................................................................................................................ 324
Removing an Application................................................................................................................... 326
Installing New Packages........................................................................................................................ 327
The Synaptic Layout.......................................................................................................................... 328
Installing Packages............................................................................................................................. 331
Removing Packages........................................................................................................................... 333
Command-Line Package Management................................................................................................ 333
Setting Repositories............................................................................................................................ 333
Apt-get Commands............................................................................................................................ 334
Summary.................................................................................................................................................. 336


Chapter 14: Networking..............................................................................................................337
Networking Basics.................................................................................................................................. 338
Internet Connection Types................................................................................................................ 338
Ethernet Connections......................................................................................................................... 341
Connecting to the Network.................................................................................................................... 343
GNOME PPP....................................................................................................................................... 343
Network Manager.............................................................................................................................. 345
Network Tools.......................................................................................................................................... 349
Devices................................................................................................................................................ 350
Ping...................................................................................................................................................... 351
Netstat................................................................................................................................................. 352
Traceroute........................................................................................................................................... 354
Port Scan............................................................................................................................................. 355




Contents

xvii

Lookup................................................................................................................................................. 355
Finger.................................................................................................................................................. 357
Whois................................................................................................................................................... 357
Firewalls.................................................................................................................................................. 358
Installing Firestarter........................................................................................................................... 359
Starting Firestarter............................................................................................................................. 360
Using Firestarter................................................................................................................................. 360
Summary.................................................................................................................................................. 364


Chapter 15: External Devices.....................................................................................................367
Printers..................................................................................................................................................... 368
The Printer Configuration Tool......................................................................................................... 368
Printer Server Settings....................................................................................................................... 369
Adding a New Printer........................................................................................................................ 370
Modifying Printer Properties............................................................................................................. 372
Scanners................................................................................................................................................... 376
Detecting the Scanner........................................................................................................................ 376
Scanning a Document........................................................................................................................ 379
The Work Area................................................................................................................................... 380
Digital Cameras...................................................................................................................................... 383
Portable Music Players........................................................................................................................... 385
Summary.................................................................................................................................................. 386

Chapter 16: The Display...............................................................................................................387
The X Windows System.......................................................................................................................... 388
What Is X Windows?.......................................................................................................................... 388
Linux X Windows Software............................................................................................................... 389
The X.Org Configuration................................................................................................................... 390
Ubuntu Video Configuration................................................................................................................. 394
The Screen Resolution Utility............................................................................................................ 394
Setting Compiz Fusion Features....................................................................................................... 396
Monitor and Video Cards.................................................................................................................. 401
Using 3-D Cards...................................................................................................................................... 403
Ubuntu 3-D Support........................................................................................................................... 403
Viewing Restricted Hardware Drivers.............................................................................................. 404
Summary.................................................................................................................................................. 404

Chapter 17: Users and Groups.................................................................................................. 407

The User Administration Tool............................................................................................................... 408
Adding Users...................................................................................................................................... 408
Modifying Users................................................................................................................................. 412
Deleting Users.................................................................................................................................... 413
Ubuntu Groups.........................................................................................................................................414
Adding Groups................................................................................................................................... 416
Modifying Groups.............................................................................................................................. 417
Deleting Groups................................................................................................................................. 418
User and Group Files...............................................................................................................................418
The Users File..................................................................................................................................... 418


xviii

Contents

The Groups File.................................................................................................................................. 419
Using the Command Line.................................................................................................................. 420
Understanding File Permissions.............................................................................................................421
File Properties..................................................................................................................................... 421
Changing File Permissions................................................................................................................ 422
Summary.................................................................................................................................................. 423

Chapter 18: Basic Administration.............................................................................................425
Monitoring the System........................................................................................................................... 426
System................................................................................................................................................. 426
Processes............................................................................................................................................. 427
Resources............................................................................................................................................ 429
File Systems........................................................................................................................................ 430
Log Files....................................................................................................................................................431

Ubuntu Log Files................................................................................................................................ 431
The System Log Viewer..................................................................................................................... 432
Starting Services..................................................................................................................................... 433
Starting and Stopping Services......................................................................................................... 433
Service Properties............................................................................................................................... 435
Sessions.................................................................................................................................................... 436
Startup Programs................................................................................................................................ 437
Options................................................................................................................................................ 437
Disk Usage Analyzer.............................................................................................................................. 438
Summary.................................................................................................................................................. 440

Chapter 19: The Ubuntu Command Line................................................................................441
The GNOME Terminal Program........................................................................................................... 442
Session Tabs....................................................................................................................................... 442
The Menu Bar..................................................................................................................................... 443
The Command-Line Parameters....................................................................................................... 446
Command-Line Basics.............................................................................................................................447
Setting the Command Prompt........................................................................................................... 447
The bash Manual................................................................................................................................ 449
Traversing Directories........................................................................................................................ 451
File and Directory Listing.................................................................................................................. 452
File Handling...................................................................................................................................... 458
Directory Handling............................................................................................................................. 464
Summary.................................................................................................................................................. 466

PART 4: Using the Ubuntu Server................................................................. 467
Chapter 20: DNS Server.............................................................................................................. 469
History of Computer Names...................................................................................................................470
Domain Names.........................................................................................................................................470
DNS Structure..................................................................................................................................... 470

Finding Domains................................................................................................................................ 472




Contents

xix

DNS Database Records...................................................................................................................... 473
DNS Protocol....................................................................................................................................... 478
Ubuntu as a DNS Client..........................................................................................................................478
Configuring DNS Client Files............................................................................................................ 479
Ubuntu Client DNS Programs........................................................................................................... 480
Ubuntu as a DNS Server........................................................................................................................ 486
The named Files................................................................................................................................. 486
Using named as a Local Cache Server............................................................................................. 488
Using named as a Master DNS Server.............................................................................................. 489
Summary.................................................................................................................................................. 492

Chapter 21: Web Server.............................................................................................................. 493
Ubuntu Web Servers............................................................................................................................... 494
Web Scripting Languages.................................................................................................................. 494
The LAMP Platform............................................................................................................................ 498
The Tomcat Platform.......................................................................................................................... 498
The Apache Web Server......................................................................................................................... 499
Apache Configuration Files............................................................................................................... 500
Apache Modules................................................................................................................................. 500
Creating Virtual Hosts....................................................................................................................... 502
Testing the Apache Server................................................................................................................ 503

The MySQL Software............................................................................................................................. 506
Accessing the Server.......................................................................................................................... 506
Changing the Root Password............................................................................................................. 507
The phpMyAdmin Tool...................................................................................................................... 508
The PHP Software....................................................................................................................................510
The PHP Configuration Files............................................................................................................. 510
PHP Extensions................................................................................................................................... 511
Using PHP........................................................................................................................................... 513
Tomcat.......................................................................................................................................................514
Tomcat Configuration........................................................................................................................ 515
Testing Tomcat................................................................................................................................... 515
Managing Tomcat.............................................................................................................................. 518
Summary.................................................................................................................................................. 520

Chapter 22: Samba and Print Server.......................................................................................521
What Is Samba?....................................................................................................................................... 522
The Ubuntu Samba Environment......................................................................................................... 523
Samba Programs................................................................................................................................. 523
Samba Configuration Files................................................................................................................ 524
Creating a Samba Server........................................................................................................................531
Editing the smb.conf File................................................................................................................... 531
Defining Samba Passwords................................................................................................................ 532
Managing Samba............................................................................................................................... 533
The Samba Client................................................................................................................................... 533
The smbclient Program...................................................................................................................... 533
Interacting with a Windows Share.................................................................................................... 534
Connecting from Windows.................................................................................................................... 537


xx


Contents

The CUPS Print Server........................................................................................................................... 539
Printing in Linux................................................................................................................................. 539
The CUPS Software............................................................................................................................ 541
CUPS Configuration........................................................................................................................... 541
Managing CUPS Printers................................................................................................................... 542
Summary.................................................................................................................................................. 546

Chapter 23: Email Server.............................................................................................................547
How Email Works.................................................................................................................................... 548
Mail Transfer Agent........................................................................................................................... 549
Mail Delivery Agent........................................................................................................................... 551
Mail User Agent................................................................................................................................. 553
Postfix Setup............................................................................................................................................ 557
Postfix Core Programs........................................................................................................................ 558
Postfix Message Queues.................................................................................................................... 559
Postfix Utility Programs...................................................................................................................... 560
Postfix Configuration Files................................................................................................................. 561
Postfix Lookup Tables........................................................................................................................ 562
Installing Postfix..................................................................................................................................... 563
Internet Site........................................................................................................................................ 563
Internet with SmartHost..................................................................................................................... 564
Satellite System.................................................................................................................................. 565
Local Only........................................................................................................................................... 566
Configuring Postfix................................................................................................................................. 567
Wizard Windows................................................................................................................................. 566
Modifying Configuration Settings..................................................................................................... 573
procmail....................................................................................................................................................574

The .procmailrc File........................................................................................................................... 574
Using procmail.................................................................................................................................... 576
Summary...................................................................................................................................................578

Chapter 24: Database Server.....................................................................................................579
The MySQL Server................................................................................................................................. 580
The MySQL Server Files.................................................................................................................... 580
The mysql Command......................................................................................................................... 585
Using mysql........................................................................................................................................ 588
The PostgreSQL Server.......................................................................................................................... 590
The PostgreSQL Files......................................................................................................................... 591
The psql Command............................................................................................................................ 594
Using psql........................................................................................................................................... 597
Working with Databases........................................................................................................................ 599
Creating a Database........................................................................................................................... 599
Managing Users................................................................................................................................. 600
Building Tables................................................................................................................................... 602
Adding and Viewing Data................................................................................................................. 603
Summary.................................................................................................................................................. 604




Contents

xxi

Part 5: Programming in Ubuntu.................................................................... 605
Chapter 25: Shell Scripts..............................................................................................................607
Using Multiple Commands.................................................................................................................... 608

Creating a Script File.............................................................................................................................. 608
Displaying Output....................................................................................................................................610
Using Variables........................................................................................................................................612
Environment Variables...................................................................................................................... 612
User Variables.................................................................................................................................... 613
The Backtick.............................................................................................................................................615
Redirecting Input and Output................................................................................................................616
Output Redirection............................................................................................................................. 616
Input Redirection................................................................................................................................ 617
Pipes..........................................................................................................................................................618
Performing Math..................................................................................................................................... 620
The expr Command............................................................................................................................ 620
Using Brackets.................................................................................................................................... 622
A Floating-Point Solution................................................................................................................... 623
Exiting the Script.................................................................................................................................... 626
Checking the Exit Status................................................................................................................... 627
The exit Command............................................................................................................................. 628
Structured Commands........................................................................................................................... 629
The if-then-else Statement................................................................................................................ 629
The test Command............................................................................................................................. 631
Summary.................................................................................................................................................. 636

Chapter 26: Perl and Python......................................................................................................637
What Is Perl?............................................................................................................................................ 638
Working with Perl................................................................................................................................... 638
Command-Line Interpreter................................................................................................................ 639
Creating a Perl Program.................................................................................................................... 640
Perl Programming................................................................................................................................... 640
Using Variables in Perl...................................................................................................................... 641
Structured Commands....................................................................................................................... 644

Perl Operators..................................................................................................................................... 646
Regular Expressions........................................................................................................................... 648
Perl Command-Line Arguments....................................................................................................... 650
Perl Modules and CPAN..........................................................................................................................651
What Is Python?....................................................................................................................................... 652
Working with Python.............................................................................................................................. 653
Programming in Python......................................................................................................................... 654
Python Variables and Data Structures.............................................................................................. 654
Tuples Variables................................................................................................................................. 655
Indentation in Structured Commands............................................................................................... 656
Object-Oriented Programming.......................................................................................................... 657
Python Command-Line Arguments.................................................................................................. 657
Python Modules...................................................................................................................................... 658
Summary.................................................................................................................................................. 659


xxii

Contents

Chapter 27: C Programming.......................................................................................................661
C Programming in Ubuntu.................................................................................................................... 662
The GNU Compiler............................................................................................................................ 662
The GNU Assembler.......................................................................................................................... 665
The GNU Linker................................................................................................................................. 668
The GNU Debugger Program............................................................................................................ 671
The GNU objdump Program.............................................................................................................. 674
The GNU Profiler Program................................................................................................................ 676
Writing C Programs................................................................................................................................ 681
C Program Format.............................................................................................................................. 681

Sample Program................................................................................................................................. 684
Summary.................................................................................................................................................. 685

Chapter 28: Java.............................................................................................................................687
The Java Development Environment.................................................................................................... 688
Java Programs..................................................................................................................................... 688
Platforms............................................................................................................................................. 689
Ubuntu Java Environments................................................................................................................... 690
Using OpenJDK...................................................................................................................................... 691
Installing OpenJDK............................................................................................................................ 692
OpenJDK Components...................................................................................................................... 692
Java Development Environments.......................................................................................................... 693
Command-Line Tools......................................................................................................................... 694
NetBeans............................................................................................................................................. 703
Eclipse................................................................................................................................................. 707
Summary...................................................................................................................................................711

Chapter 29: Ruby........................................................................................................................... 713
What Is Ruby?...........................................................................................................................................714
Ruby on the Web................................................................................................................................ 714
Ruby on Rails...................................................................................................................................... 715
Installing Ruby.........................................................................................................................................715
Ruby Components.............................................................................................................................. 715
Installing Ruby in Ubuntu.................................................................................................................. 716
Working with Ruby Code........................................................................................................................719
Interactive Ruby................................................................................................................................. 719
Scripting with Ruby............................................................................................................................ 720
Embedded Ruby................................................................................................................................. 721
The Ruby Language................................................................................................................................ 722
Variables............................................................................................................................................. 722

Structured Commands....................................................................................................................... 725
Object-Oriented Programming............................................................................................................. 730
Creating Classes................................................................................................................................. 730
Using Objects...................................................................................................................................... 731
Adding Methods................................................................................................................................. 732




Contents

xxiii

Ruby on Rails............................................................................................................................................732
Creating a Project............................................................................................................................... 733
Testing the Project.............................................................................................................................. 736
Summary.................................................................................................................................................. 739

Chapter 30: PHP.............................................................................................................................741
What Is PHP?............................................................................................................................................742
PHP in Ubuntu.........................................................................................................................................743
Core Installation................................................................................................................................. 743
PHP Extensions................................................................................................................................... 745
Working with PHP...................................................................................................................................747
Defining PHP Code............................................................................................................................ 747
PHP Output......................................................................................................................................... 749
The PHP Language..................................................................................................................................751
PHP Variables..................................................................................................................................... 751
Iterating Through Arrays................................................................................................................... 754
Structured Commands....................................................................................................................... 754

Including External Files..................................................................................................................... 756
Working with MySQL........................................................................................................................ 759
Object-Oriented PHP.............................................................................................................................. 760
Creating a Class in PHP..................................................................................................................... 761
Creating Objects................................................................................................................................. 761
Writing OOP Code in PHP................................................................................................................. 762
Expanding on OOP............................................................................................................................ 763
Class Constructors.............................................................................................................................. 765
PECL and PEAR...................................................................................................................................... 768
Summary.................................................................................................................................................. 768
Index..........................................................................................................................................................771


×