old linux course modules

Upload: vasan-nanguneri

Post on 05-Apr-2018

221 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/2/2019 Old Linux Course Modules

    1/561

    Linux Training Materials Project

    GBdirect Limited27 Park Drive

    Bradford, BD9 4DSWest Yorkshire

    tel: +44 (0)1274 [email protected]

    November 7, 2001

  • 8/2/2019 Old Linux Course Modules

    2/561

    Contents

    1 Apache Basics 1Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

    1.1 What is

    ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.2 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.3 How Apache Listens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.4 Configuration File(s) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51.5 Key Configuration Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . 61.6 ServerRoot, DocumentRoot . . . . . . . . . . . . . . . . . . . . . . . . . . . 71.7 ServerAdmin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81.8 BindAddress, and Port . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91.9 Listen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101.10 Userand Group . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111.11 Apache Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121.12 Logging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131.13 Customizable Logging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141.14 CustomLogexamples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151.15 Example Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161.16 Basic Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171.17 Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181.18 Two sites and more ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

    1.19 Virtual Hosting Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211.20 Name-based hosting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221.21 Name-based hosting (continued) . . . . . . . . . . . . . . . . . . . . . . . . 231.22 Block Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241.23 Block Directives (continued) . . . . . . . . . . . . . . . . . . . . . . . . . . . 251.24 DirectoryMatch, et al. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261.25 Access Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271.26 Access Control (continued) . . . . . . . . . . . . . . . . . . . . . . . . . . . 281.27 Authorisation Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291.28 Authorisation Files (continued) . . . . . . . . . . . . . . . . . . . . . . . . . 301.29 Other useful directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311.30 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321.31 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

    1.32 Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

    2 Key Configuration Files 36Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36

    2.1

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372.2

    (continued) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382.3 Editing

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 392.4 Other Changes To

    . . . . . . . . . . . . . . . . . . . . . . . . . 402.5

    " # $

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

    i

  • 8/2/2019 Old Linux Course Modules

    3/561

    CONTENTS ii

    2.6 Editing

    " # $

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 422.7 Important Note . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 432.8 Shadow Passwords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 442.9

    #

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 452.10 Scheduling Jobs ( & " # ' ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 462.11

    " # '

    (

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 472.12

    " $ ' )

    "

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 482.13

    1 # " #

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 492.14 Module Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 502.15 Modules Configuration - Options . . . . . . . . . . . . . . . . . . . . . . . . 512.16 Mounting Filesystems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 522.17 Runlevels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 532.18 Single User Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 542.19 Multi User Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 552.20 Starting up and Shutting down . . . . . . . . . . . . . . . . . . . . . . . . . 562.21 Changing runlevel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 572.22 Initscripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 582.23

    "

    ' 2

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 592.24 Initscripts - An example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60

    2.25 Restar ting Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 612.26 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 622.27 Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63

    3 Dial Up and Remote Access 65Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65

    3.1 Dial-In/Out . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 663.2 The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 673.3 Authentication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 683.4 Setting-up dial-out . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 693.5 One Dial-Out Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 703.6 Dial-Out Setup contd. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 713.7 Dial-In Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72

    3.8 Other options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 733.9 Preferred Installation Architectures . . . . . . . . . . . . . . . . . . . . . . . 743.10 Preferred Setup 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 753.11 Preferred Setup 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 763.12 Appendix - sendmail configuration for non dial-on-demand . . . . . . . . . . 77

    4 Email 78Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78

    4.1 How email works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 794.2 Where does an email go? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 804.3 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 814.4 Email Protocols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 824.5 Where the protocols go . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83

    4.6 Basic Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 844.7 Sendmail behaviour . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 854.8 Linuxconf & sendmail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 864.9 Configuration files (

    '

    4 6

    1 2

    9

    ) . . . . . . . . . . . . . . . . . . . . . . . . 874.10 Configuration files (

    '

    4 6

    1 2

    and

    4 6

    1 ) . . . . . . . . . . . . . . 88

    4.11 Explanation of examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 894.12 Monitoring sendmail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 904.13 Monitoring sendmail (cont.) . . . . . . . . . . . . . . . . . . . . . . . . . . . 914.14 Example of

    4 6

    1 @. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92

    cA

    GBdirect Ltd, 2000 www.linuxtraining.co.uk

  • 8/2/2019 Old Linux Course Modules

    4/561

    CONTENTS iii

    4.15 Talking the talk ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 934.16 Talking SMTP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 944.17 Talking POP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 954.18 Managing Users under sendmail . . . . . . . . . . . . . . . . . . . . . . . . 964.19

    1

    6

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 974.20 Aliases - other uses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 984.21 Sendmail Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99

    5 Basic Filesystem 100Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100

    5.1 Filesystem Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1015.2 Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1025.3 Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1035.4 Directory Hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1045.5 Pathnames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1055.6 Current Directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1065.7 Dot (.) and DotDot(..) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1075.8 Moving and Copying Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1085.9 Removing Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1095.10 Operations on Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1105.11 Inodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1115.12 Inodes (continued) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1125.13 Links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1135.14 Hard links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1145.15 Soft links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1155.16 Access Control and UID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1165.17 Categories of Access Control . . . . . . . . . . . . . . . . . . . . . . . . . . 1175.18 Access Control - Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1185.19 Changing Access Permission:

    4

    #

    . . . . . . . . . . . . . . . . . . . . . . 1195.20

    4

    #

    symbolically . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1205.21

    4

    #

    numerically . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1215.22

    $

    4 B

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122

    5.23 Special Files -

    D

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1235.24 Special Files -

    " #

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1245.25 Filesystem Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1255.26

    9 (

    - Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1265.27 Mounting Additional Volumes . . . . . . . . . . . . . . . . . . . . . . . . . . 1275.28 Mounting shared filesystems . . . . . . . . . . . . . . . . . . . . . . . . . . 1285.29 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1295.30 Filesystem Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1305.31 Filesystem Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131

    6 More on the Filesystem 133Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133

    6.1 Inodes in Depth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134

    6.2 Inodes (continued) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1356.3 Links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1366.4 Hard links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1376.5 Soft links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1386.6 Non-native Filesystems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1396.7 Disk Checking and Recovery (

    9 B

    ) . . . . . . . . . . . . . . . . . . . . . . 1406.8 Check a Linux Ext2 filesystem (

    E 9 B

    ) . . . . . . . . . . . . . . . . . . . . 1416.9 Disk Free Space (

    9

    ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1426.10 Disk Usage (

    $) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143

    cA

    GBdirect Ltd, 2000 www.linuxtraining.co.uk

  • 8/2/2019 Old Linux Course Modules

    5/561

    CONTENTS iv

    6.11 Disk Partitioning Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1446.12 A Par titioned Disk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1456.13 Making and Changing Partitions . . . . . . . . . . . . . . . . . . . . . . . . 1466.14 How Many Par titions? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1476.15 What Size Par titions? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1486.16 BIOS Problems With LILO and Partitions . . . . . . . . . . . . . . . . . . . . 1496.17 Disk Partitioning Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1506.18 Using

    9 6 B

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1516.19 The

    9 6 B

    Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1526.20 Interactive Commands in

    9 6 B

    . . . . . . . . . . . . . . . . . . . . . . . . 1536.21 Making Linux Filesystems (

    4 B E 9

    ) . . . . . . . . . . . . . . . . . . . . . . . 1546.22 Block Devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1556.23 Character Devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1566.24 More Filesystem Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . 1576.25 More Filesytem Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159

    7 Shared File Systems 162

    Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1627.1 NFS (Network File System) . . . . . . . . . . . . . . . . . . . . . . . . . . . 1637.2 NFS Basics . . . c ontinued . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1647.3 Expor ting File Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1657.4 Viewing expor ts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1667.5 Importing File Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1677.6 Samba . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1687.7 Samba Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1697.8 Samba Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1707.9 Access to Files and Printers . . . . . . . . . . . . . . . . . . . . . . . . . . . 1717.10 Testing Samba . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1727.11 Smbclient . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1737.12 Samba configuration File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1747.13 Testing Samba . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175

    Notes on Testing Samba . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175

    7.14 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1767.15 Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177

    8 Firewalling and Network Security 179

    Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1798.1 Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1808.2 What is Packet Filtering? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1818.3 Controlling Access to Daemons . . . . . . . . . . . . . . . . . . . . . . . . . 1828.4 TCP Wrappers (

    $

    "

    ( 6

    '

    ) . . . . . . . . . . . . . . . . . . . . . . . . 1838.5 TCP Wrapper Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1848.6 Introduction to Packet Filtering . . . . . . . . . . . . . . . . . . . . . . . . . 1858.7 Basic Packet Filtering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1868.8

    6 6

    '

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187

    8.9

    6 6

    '

    Details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1888.106 6

    '

    schematic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1898.11

    6 6

    '

    Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1908.12 Options For Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1918.13

    6 6

    '

    - Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1928.14 Removing Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1938.15 Implementing ipchains . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1948.16 Save and restore . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1958.17

    6 6

    '

    setup script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196

    cA

    GBdirect Ltd, 2000 www.linuxtraining.co.uk

  • 8/2/2019 Old Linux Course Modules

    6/561

    CONTENTS v

    8.18 Real World6 6

    '

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1978.19 Port Scanning with

    '

    4

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1988.20 '

    4

    Performance and Reliability Features . . . . . . . . . . . . . . . . . . . 1998.21

    '

    4

    Target and Port Specification . . . . . . . . . . . . . . . . . . . . . . . 2008.22 Running '

    4

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2018.23 Reporting the State of Ports . . . . . . . . . . . . . . . . . . . . . . . . . . . 2028.24 Reporting Other Details with

    '

    4

    . . . . . . . . . . . . . . . . . . . . . . . . 2038.25 Scanning Modes: Vanilla TCP & SYN . . . . . . . . . . . . . . . . . . . . . 2048.26 Scanning Modes: IP Fragments & Reverse ident . . . . . . . . . . . . . . . 2058.27 Scanning Modes: TCP ftp proxy . . . . . . . . . . . . . . . . . . . . . . . . . 2068.28 Scanning Modes: UDP raw ICMP port unreachable . . . . . . . . . . . . . . 2078.29 Some other

    '

    4

    Scanning Modes . . . . . . . . . . . . . . . . . . . . . . . 2088.30 '

    4

    Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2098.31 Basic '

    4

    Howto . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2108.32

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2148.33

    principles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2158.34 Use of

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2168.35 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2178.36 Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218

    9 Job Control Tools 219Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219

    9.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2209.2 Background Jobs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2219.3

    B 6

    1 1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222

    9.4 The '6

    Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2239.5 Hang Up (

    ' #

    $

    ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2249.6 Execute programs at specified times (

    ) . . . . . . . . . . . . . . . . . . . . 2259.7 Options and commands related to

    . . . . . . . . . . . . . . . . . . . . . . 2269.8 Running commands regularly (

    " # '

    (

    ) . . . . . . . . . . . . . . . . . . . . 2279.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2289.10 Job Control Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229

    9.11 Job Control Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230

    10 Overview 231Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231

    10.1 Generic Features of Unix . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23210.2 Linux The Kernel of a System . . . . . . . . . . . . . . . . . . . . . . . . 23310.3 Fundamental Characteristics of Linux . . . . . . . . . . . . . . . . . . . . . . 23410.4 Multiuser Multitasking and Time-sharing . . . . . . . . . . . . . . . . . . . . 23510.5 Protected memory mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23610.6 Multiple Filesystem Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23710.7 The Many Faces of a GNU/Linux System . . . . . . . . . . . . . . . . . . . 23810.8 The Filesystem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23910.9 Filenames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240

    10.10 Filename Extensions and File Types . . . . . . . . . . . . . . . . . . . . . . 24110.11 Hidden Filenames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24210.12 The Shell (

    (

    ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24310.13 Key Features of the Bash Shell . . . . . . . . . . . . . . . . . . . . . . . . . 24410.14 Interacting with a Linux Terminal . . . . . . . . . . . . . . . . . . . . . . . . 24510.15 Software Tools: The UNIX Philosophy . . . . . . . . . . . . . . . . . . . . . 24610.16 Tasks/Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24710.17 Process Communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24810.18 Re-directing I/O to and from Files . . . . . . . . . . . . . . . . . . . . . . . . 249

    cA

    GBdirect Ltd, 2000 www.linuxtraining.co.uk

  • 8/2/2019 Old Linux Course Modules

    7/561

    CONTENTS vi

    10.19 Re-directing I/O to and from Files (continued) . . . . . . . . . . . . . . . . . 25010.20 Pipes & Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25110.21 Linux as a Programming Environment . . . . . . . . . . . . . . . . . . . . . 25210.22 N etworking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25310.23 T CP/IP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25410.24 Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25510.25 Using the man pages(On-Line Manual) . . . . . . . . . . . . . . . . . . . . 25610.26 Overview Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25710.27 Overview Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260

    11 Printing Services 263Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263

    11.1 Linux Printing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26411.2 Printing documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26511.3 Main Printing Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26611.4 Using

    1

    ". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267

    11.5 Using1

    @. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268

    11.6 Using1

    "

    4

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26911.7 Samba Printing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27011.8 Printing to a Windows Printer via Samba . . . . . . . . . . . . . . . . . . . . 271

    12 Basic Shell 272Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272

    12.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27312.2 Getting around the command line . . . . . . . . . . . . . . . . . . . . . . . . 27412.3 History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27512.4 Plumbing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27612.5 Plumbing (continued) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27712.6 Output Redirection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27812.7 Input Redirection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27912.8 Combining Redirection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28012.9 Pipelines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28112.10 Background Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28212.11 Background Processes (continued) . . . . . . . . . . . . . . . . . . . . . . . 28312.12 Background Processes and ' #

    $

    . . . . . . . . . . . . . . . . . . . . . . . 28412.13 Command Grouping and Sub-shells . . . . . . . . . . . . . . . . . . . . . . 28512.14 Process Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28612.15 S ignals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28712.16 Signals (continued) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28812.17 Background Processes:

    #

    . . . . . . . . . . . . . . . . . . . . . . . . . . . 28912.18 Filename Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29012.19 Quoting Mechanisms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29112.20 Shell built-in commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29212.21 Basic Shell Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29312.22 Basic Shell Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295

    13 Shell Programming 296Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296

    13.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29713.2 Writing and Running Shell Scripts . . . . . . . . . . . . . . . . . . . . . . . . 29813.3 Subshell or Subroutine? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29913.4 Processing Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30013.5 Command Substitution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30113.6 Shell Variables and Variable Substitution . . . . . . . . . . . . . . . . . . . . 302

    cA

    GBdirect Ltd, 2000 www.linuxtraining.co.uk

  • 8/2/2019 Old Linux Course Modules

    8/561

    CONTENTS vii

    13.7 Shell Environment Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . 30313.8 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30413.9 Examples (continued) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30513.10

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30613.11 Q uoting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30713.12 E xamples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30813.13

    2

    " #

    9 6

    1

    File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30913.14

    2

    " #

    9 6

    1

    (continued) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31013.15 A rguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31113.16 Shell Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31213.17 Blank Interpretation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31313.18 C omments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31413.19 "

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31513.20

    6 9

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31613.21 Exit Status or Return Code . . . . . . . . . . . . . . . . . . . . . . . . . . . 31713.22

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31813.23 File Status Tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31913.24 Relational Tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32013.25

    9

    # "Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321

    13.26

    6 9

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32213.276 9

    (continued) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32313.28

    " $

    and9

    1

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32413.29

    6

    1

    and$ '

    6

    1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325

    13.30(

    "

    B

    and

    # '

    6

    ' $

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32613.31

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32713.32

    (continued) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32813.33

    (continued) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32913.34 Simple Conditionals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33013.35 Here Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33113.36 Use of commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33213.37

    9 6

    '

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33313.38 Evaluate Expressions (

    F

    " ) . . . . . . . . . . . . . . . . . . . . . . . . . . 334

    13.39

    F

    "

    (continued) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33513.40 S ummary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33613.41 Shell Programming Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . 33713.42 Shell Programming Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . 339

    14 Special Topics 343

    Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34314.1 The Linux Bootloader (LILO) . . . . . . . . . . . . . . . . . . . . . . . . . . . 34414.2 LILO configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34514.3 Understanding

    1

    6

    1 # 2

    # '

    9

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34714.4 Red Hat Package Management Tool (

    "

    4

    ) . . . . . . . . . . . . . . . . . . . 34814.5 Install, Upgrade and Uninstall with

    "

    4

    . . . . . . . . . . . . . . . . . . . . . 34914.6 Query Options for "

    4

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 350

    14.7 Verify Options for"

    4

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35114.8 Output From the

    "

    4

    Verification Option . . . . . . . . . . . . . . . . . . . . 35214.9 Building And Installing Applications . . . . . . . . . . . . . . . . . . . . . . . 35314.10

    $

    #

    # '

    9

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35414.11 Using 2

    # '

    9 6

    $ "

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35514.12 Options to configure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35614.13 Location of install . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35714.14 Installation requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35814.15 Compilat ion roundup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359

    cA

    GBdirect Ltd, 2000 www.linuxtraining.co.uk

  • 8/2/2019 Old Linux Course Modules

    9/561

    CONTENTS viii

    14.16 The

    " #

    filesytem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36014.17 Process specific subdirectories . . . . . . . . . . . . . . . . . . . . . . . . . 36114.18 Process Status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36214.19 Process Memory Usage (

    4

    ) . . . . . . . . . . . . . . . . . . . . . . . . 36314.20 Kernel data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36414.21 I nterrupts In Use . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36514.22 IDE Devices (

    " #

    6

    ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36614.23 Networking (

    " #

    '

    ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36714.24 Networking 2 (

    " #

    '

    ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36814.25 SCSI info (

    " #

    6

    ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36914.26 Parallel Port (

    " #

    "

    # "

    ) . . . . . . . . . . . . . . . . . . . . . . . . . . 37014.27 Kernel Parameters (

    " #

    I

    ) . . . . . . . . . . . . . . . . . . . . . . . . . 37114.28 File system data (

    " #

    9

    ) . . . . . . . . . . . . . . . . . . . . . . . . . . . 37214.29 Example: Increase Maximum Filehandles . . . . . . . . . . . . . . . . . . . 37314.30 General Kernel Parameters (

    " #

    I

    B

    " '

    1 ) . . . . . . . . . . . . . . . 37414.31 Virtual Memory Subsystem (

    " #

    I

    D 4

    ) . . . . . . . . . . . . . . . . . . 37514.32 Device Specific Parameters (

    " #

    I

    D

    ) . . . . . . . . . . . . . . . . . 37614.33 Remote Procedure Calls (

    " #

    I

    $ ' "

    ) . . . . . . . . . . . . . . . . . 37714.34 Networking (

    " #

    I

    '

    ) . . . . . . . . . . . . . . . . . . . . . . . . . . 378

    14.35 IPV4 settings (

    " #

    I

    '

    6 D P

    ) . . . . . . . . . . . . . . . . . . . . . . 37914.36 Special Topics Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38014.37 Special Topics Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382

    15 Fundamentals of TCP/IP 384Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384

    15.1 Fundamentals of TCP/IP Networking . . . . . . . . . . . . . . . . . . . . . . 38515.2 History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38615.3 Recap of basic IP Concepts - Components . . . . . . . . . . . . . . . . . . 38715.4 IP versions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38815.5 Packets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38915.6 Addresses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39015.7 Addresses (continued) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391

    15.8 Netmasks and subnetting . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39215.9 Netmasks with F F

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39315.10 Transferring Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39415.11 Hosts & Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39515.12 R outing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3961 5 . 1 3 P o r t s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 9 715.14 Por ts cont.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39815.15 E xercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39915.16 S olutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 400

    16 Practical TCP/IP 402Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402

    16.1 Ping Protocols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403

    16.2 Network Statistics ('

    ) in Practice . . . . . . . . . . . . . . . . . . . . 40416.3 '

    (continued) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40516.4

    '

    - Fur ther Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . 40616.5 Network Traffic (

    $

    4

    ) in Practice . . . . . . . . . . . . . . . . . . . . . . 40716.6

    $

    4

    Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40816.7

    $

    4

    E x a m p l e s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 0 916.8 Firewalling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41016.9 Basic Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41116.10 Basic Theory (continued) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412

    cA

    GBdirect Ltd, 2000 www.linuxtraining.co.uk

  • 8/2/2019 Old Linux Course Modules

    10/561

    CONTENTS ix

    16.116 6

    '

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41316.12

    6 6

    '

    Details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41416.13

    6 6

    '

    Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41516.14 Options For Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41616.15

    6 6

    '

    - Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41716.16 Removing Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41816.17 Implementing ipchains . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41916.18 Save and restore . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42016.19

    6 6

    '

    setup script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42116.20 Real World

    6 6

    '

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42216.21 Interface Configuration and Management . . . . . . . . . . . . . . . . . . . 42316.22 Point-and-Click Interface Administration . . . . . . . . . . . . . . . . . . . . 42416.23

    I

    # '

    9 6

    '

    # "

    B

    )

    "

    6

    . . . . . . . . . . . . . . . . . . . . . . 42516.24

    6 9 9

    )

    F

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42616.25 Altering An Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42716.26 Adding an Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42816.27 The Proper Way . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42916.28 D rivers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43016.29 The Secure Shell in Practice (

    ) . . . . . . . . . . . . . . . . . . . . . . . 431

    16.30 Secure Copying in Practice (

    ) . . . . . . . . . . . . . . . . . . . . . . . . 43216.31 S ummary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43316.32 E xercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43416.33 S olutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435

    17 Basic Tools 436

    Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43617.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43717.2 Using Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43817.3 The On-Line Manual (

    4

    ') . . . . . . . . . . . . . . . . . . . . . . . . . . . . 439

    17.4 Finding Files the Long Way (9 6

    '

    ) . . . . . . . . . . . . . . . . . . . . . . . 44017.5 Locate Files (

    1 #

    ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44117.6 View and Concatenate Files (

    ) . . . . . . . . . . . . . . . . . . . . . . . . 442

    17.7 View Large Files & Output (1

    ) . . . . . . . . . . . . . . . . . . . . . . . . 44317.8 Viewing Parts of Files (

    and 6

    1 ) . . . . . . . . . . . . . . . . . . . . . 44417.9 Listing File Information ( 1

    ) . . . . . . . . . . . . . . . . . . . . . . . . . . . 44517.10 File Classification (

    9 6

    1

    ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44617.11 Count Words, Lines, Characters (

    ) . . . . . . . . . . . . . . . . . . . . . . 44717.12 Differences Between Files (

    6 9 9

    ) . . . . . . . . . . . . . . . . . . . . . . . . 44817.13 Compare Binary Files (

    4

    ) . . . . . . . . . . . . . . . . . . . . . . . . . . . 45017.14 Regular Expression Searches (

    "

    ) . . . . . . . . . . . . . . . . . . . . . . 45117.15 "

    examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45217.16 Sort and Merge Files (

    # "

    ) . . . . . . . . . . . . . . . . . . . . . . . . . . . 45317.17

    # "

    Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45417.18 Display Unique Lines (

    $ '

    6

    @) . . . . . . . . . . . . . . . . . . . . . . . . . . . 455

    17.19 Split Files (

    1

    6

    ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456

    17.20 Splitting Files by Context (

    1

    6

    ) . . . . . . . . . . . . . . . . . . . . . . . 45717.21 Compression Utilities (

    S

    6

    ) . . . . . . . . . . . . . . . . . . . . . . . . . . . 45817.22 Store and Retrieve Archives (

    ") . . . . . . . . . . . . . . . . . . . . . . . . 459

    17.23 Translating Characters (

    " ) . . . . . . . . . . . . . . . . . . . . . . . . . . . 46017.24 Examples of

    " Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46117.25 Execute programs at specified times (

    ) . . . . . . . . . . . . . . . . . . . . 46217.26 Options and commands related to

    . . . . . . . . . . . . . . . . . . . . . . 46317.27 Running commands regularly (

    " # '

    (

    ) . . . . . . . . . . . . . . . . . . . . 46417.28 Evaluate expressions (

    F

    ") . . . . . . . . . . . . . . . . . . . . . . . . . . . 465

    cA

    GBdirect Ltd, 2000 www.linuxtraining.co.uk

  • 8/2/2019 Old Linux Course Modules

    11/561

    CONTENTS x

    17. 29 Linux Pr int ing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46617.30 Print ing documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46717.31 Main Printing Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46817.32 Using

    1

    ". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 469

    17.33 Using 1

    @ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47017.34 Using

    1

    "

    4

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47117.35 Basic Tools Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47217.36 Basic Tools Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 474

    18 More Tools 476Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 476

    18.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47718.2 Displaying System Processes (

    #

    ) . . . . . . . . . . . . . . . . . . . . . . . 47818.3 Options and Interactive Commands for

    #

    . . . . . . . . . . . . . . . . . . 47918.4 Reporting process status (

    ) . . . . . . . . . . . . . . . . . . . . . . . . . . 48018.5 Options for Reporting process status (

    ) . . . . . . . . . . . . . . . . . . . 48118.6 Finding Files using specified criteria (

    9 6

    '

    ) . . . . . . . . . . . . . . . . . . 48318.7 Criteria used in

    9 6

    '

    expr essions . . . . . . . . . . . . . . . . . . . . . . . . 48418.8 Examples of using (

    9 6

    '

    ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48518.9 Reporting virtual memory statistics (

    D 4

    ) . . . . . . . . . . . . . . . . . . 48618.10 Output from

    D 4

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48718.11 f ree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48818.12 l dd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4891 8 . 1 3 u p t i m e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 9 018.14 x args . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49118.15 Options to

    F

    "

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49218.16 Positioning filenames with

    F

    "

    . . . . . . . . . . . . . . . . . . . . . . . . 49318.17 cpio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49418.18

    S

    6

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49518.19 U nzipping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49618.20 tar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49718.21 Raw devices and

    ". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 498

    18.22 E xercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49918.23 S olutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 500

    19 Introduction to Editing WithD 6

    501

    Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50119.1 Text editors under Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50219.2

    D 6

    and your terminal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50319.3

    D 6

    screen layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50419.4 Opening files with

    D 6

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50519.5

    D 6

    Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50619.6 Saving, changing file and quitting . . . . . . . . . . . . . . . . . . . . . . . . 50719.7 Moving around in command mode . . . . . . . . . . . . . . . . . . . . . . . 50819.8 Numeric Prefixes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 509

    19.9 Fur ther Movement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51019.10 Further Movement - Example . . . . . . . . . . . . . . . . . . . . . . . . . . 51119.11 Movement by lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51219.12 Movement by lines - Examples . . . . . . . . . . . . . . . . . . . . . . . . . 51319.13 I nser ting text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51419.14

    6

    command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51519.15 Multiple Inser tion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51619.16 Deleting Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51719.17 Changing Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 518

    cA

    GBdirect Ltd, 2000 www.linuxtraining.co.uk

  • 8/2/2019 Old Linux Course Modules

    12/561

    CONTENTS xi

    19.18 Copy and Paste . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51919.19 Finding your place . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52019.20 Miscellaneous Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52119.21 Search and replace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52219.22 Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52319.23 Regular Expression Conventions . . . . . . . . . . . . . . . . . . . . . . . . 52419.24 Regular Expression Examples . . . . . . . . . . . . . . . . . . . . . . . . . . 52519.25 Regular Expression Replacement . . . . . . . . . . . . . . . . . . . . . . . . 52619.26

    D 6

    Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52719.27

    D 6

    Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 529

    20 Basic X-Windows 531

    Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53120.1 What X-Windows Is . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53220.2 X Needs Window Managers . . . . . . . . . . . . . . . . . . . . . . . . . . . 53320.3 Window Managers Are Applications . . . . . . . . . . . . . . . . . . . . . . 53420.4 Desktop Environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53520.5 Starting X . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53620.6 Stopping X . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53720.7 Running Shells (Xterms) Under X . . . . . . . . . . . . . . . . . . . . . . . . 53820.8 Running Applications from an

    F

    "

    4

    . . . . . . . . . . . . . . . . . . . . . . 53920.9 Running Applications from a window manager . . . . . . . . . . . . . . . . . 54020. 10 Configur ing X . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54120.11 Basic X Hardware Configuration . . . . . . . . . . . . . . . . . . . . . . . . 54220.12 Basic X Software Configuration . . . . . . . . . . . . . . . . . . . . . . . . . 54320.13 Networked X - The Client-Server Relationship . . . . . . . . . . . . . . . . . 54420.14 Principles of Running Remote X Apps . . . . . . . . . . . . . . . . . . . . . 54520.15 How to Run Remote X Apps . . . . . . . . . . . . . . . . . . . . . . . . . . . 54620. 16 Aut hent icat ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54720.17 Better Authentication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54820.18 Basic X Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 549

    cA

    GBdirect Ltd, 2000 www.linuxtraining.co.uk

  • 8/2/2019 Old Linux Course Modules

    13/561

    Module 1

    Apache Basics

    Objectives

    On completion of this module you should be able to:

    Install and configure theU V X ` b d

    webserver

    Set up virtual hosts

    Use access controls

    Set up basic authentication

    1

  • 8/2/2019 Old Linux Course Modules

    14/561

    Apache Basics 2

    1.1 What isU V X ` b d

    ?

    U V X ` b d

    is the most widely-used web-server1

    Listens for requests and hands something backNormally the contents of a file

    Possibly the result of a program

    Designed to be stable and configurable

    Not meant to be fast

    Probably fast enough . . .

    159.99 % of all servers as of February 2001 (Netcraft - www.netcraft.com)

    cA

    GBdirect Ltd, 2000 www.linuxtraining.co.uk

  • 8/2/2019 Old Linux Course Modules

    15/561

    Apache Basics 3

    1.2 Installation

    Basic installation is easy

    You may be able to install from your distributionMost come with

    U V X ` b d

    Otherwise just follow the download instructions

    from the official siteb i i V q s s t t t v X V X ` b d v s

    Then follow the instructions in the

    U

    file

    Normally just

    v s ` d

    X d

    X d i X

    If you have problems check the docs

    Available atb i i V q s s t t t v X V X ` b d v s j `

    cA

    GBdirect Ltd, 2000 www.linuxtraining.co.uk

  • 8/2/2019 Old Linux Course Modules

    16/561

    Apache Basics 4

    1.3 How Apache Listens

    Apache runs several processes at any one time

    Parent and several childrenParent watches overthe children

    Tracks how many are answering requests

    Spawns more if free processes drop below a

    certain point

    Kills spare processes if there are lots free

    Configure child numbers using MinSpareServersand MaxSpareServersdirectives

    Default is reasonable for a small business

    Tune it for busier sites

    cA

    GBdirect Ltd, 2000 www.linuxtraining.co.uk

  • 8/2/2019 Old Linux Course Modules

    17/561

    Apache Basics 5

    1.4 Configuration File(s)

    If compiled from source,U V X ` b d

    installs ins s ` X s X V X ` b d

    Earlier versions installed unders s ` X s d i ` s b i i V j

    Your distribution may differ again . . . 2

    Configuration file is calledb i i V j v `

    Older versions use 3

    b i i V j v `

    v `

    X ` ` d v `

    Controls what requestsU V X ` b d

    answers

    and how . . .

    2Redhat installs config files under

    and the sample web pagesand logs directories under

    z

    3Some pre-packaged versions (Such as the RedHat RPM) also use sepa-rate files

    cA

    GBdirect Ltd, 2000 www.linuxtraining.co.uk

  • 8/2/2019 Old Linux Course Modules

    18/561

    Apache Basics 6

    1.5 Key Configuration Directives

    Wide range of configuration directives

    For a verybasic server you need at least thefollowing:

    ServerRoot

    DocumentRoot

    ServerAdmin

    BindAddress

    PortListen

    User

    Group

    cA

    GBdirect Ltd, 2000 www.linuxtraining.co.uk

  • 8/2/2019 Old Linux Course Modules

    19/561

    Apache Basics 7

    1.6 ServerRoot, DocumentRoot

    TellsU V X ` b d

    where its files live

    ServerRoottells

    U V X ` b d

    where its

    `

    and

    directories live

    Not always necessary

    Good practice to have it

    DocumentRoottellsU V X ` b d

    where to look for

    documents to serve up

    Requested filenames are appended to this

    If you have

    |

    `

    d i } i s t t t s j `

    then a request to

    b i i V q s s t t t v j

    X v ` v s v b i

    points to the files t t t s j ` s v b i

    cA

    GBdirect Ltd, 2000 www.linuxtraining.co.uk

  • 8/2/2019 Old Linux Course Modules

    20/561

    Apache Basics 8

    1.7 ServerAdmin

    U V X ` b d

    sometimes cant complete requests

    In these cases it serves up an error pageServerAdmin is given as a contact address

    Usually set to something like

    t d

    X i d j

    X v ` v

    You should of course ensure that it is a valid

    email address

    Possible to specify a different error page

    Doesnt have to use ServerAdmin

    cA

    GBdirect Ltd, 2000 www.linuxtraining.co.uk

  • 8/2/2019 Old Linux Course Modules

    21/561

    Apache Basics 9

    1.8 BindAddress, and Port

    TellsU V X ` b d

    which requests to answer

    By default

    U V X ` b d

    listens to every IP address onyour machine

    But only to the port given by the Portdirective

    j U j j d v v v

    tellsU V X ` b d

    to ignore

    anything that doesnt come in on v v v

    i

    ignores all but the specified port

    You can use more than one Portdirective, e.g.

    i

    i

    If you dont specify a port then a default is used4

    You can only use one BindAddress!

    4This is usually 80, but if you are using a binary package then bear in mindwhoever compiled your package may have chosen a different value

    cA

    GBdirect Ltd, 2000 www.linuxtraining.co.uk

  • 8/2/2019 Old Linux Course Modules

    22/561

    Apache Basics 10

    1.9 Listen

    Listen is a replacement for BindAddressand Port

    Given IP:port or just port, e.g. i d v v v q

    will answer requests on the IP address v v v

    and port

    and no others

    To answer requests to all valid IP addresses, but

    only a certain port (e.g.

    ) use:

    i d

    Can use more than one Listendirective

    Should be used instead of BindAddressand Port

    in new servers

    cA

    GBdirect Ltd, 2000 www.linuxtraining.co.uk

  • 8/2/2019 Old Linux Course Modules

    23/561

    Apache Basics 11

    1.10 User and Group

    U V X ` b d

    should normally be started as root

    So it can change the user ID of the childrenThese should notrun as root

    User and Groupdirectives say what user/group

    the children should run as

    Important security feature

    Should be set to something that has no real

    power on your system

    Most people use user and group j

    Web documents should be readable by this user

    Nothing should be writeable except log files

    cA

    GBdirect Ltd, 2000 www.linuxtraining.co.uk

  • 8/2/2019 Old Linux Course Modules

    24/561

    Apache Basics 12

    1.11 Apache Processes

    Looking at a process list5 you can see

    The parent" # #

    $ 1

    P

    $

    " 1 #

    1

    ( 6

    '

    )

    The children' #

    (

    #

    I

    $

    " 1 #

    1

    ( 6

    '

    )

    ' #

    (

    #

    I E

    $

    " 1 #

    1

    ( 6

    '

    )

    ' #

    (

    #

    I

    $

    " 1 #

    1

    ( 6

    '

    )

    ' #

    (

    #

    I

    $

    " 1 #

    1

    ( 6

    '

    )

    ' #

    (

    #

    I

    $

    " 1 #

    1

    ( 6

    '

    )

    ' #

    (

    #

    I

    $

    " 1 #

    1

    ( 6

    '

    )

    Spare processes dont use processor time

    They are sleeping

    They douse memory, however

    Negligible for a defaultU V X ` b d

    Watch carefully the more modules you add!

    5Some fields from the

    output have been left out to aid clarity

    cA

    GBdirect Ltd, 2000 www.linuxtraining.co.uk

  • 8/2/2019 Old Linux Course Modules

    25/561

    Apache Basics 13

    1.12 Logging

    U V X ` b d

    can log information about accesses

    Use the TransferLogand ErrorLogdirectives

    X d s X ` ` d

    will log all requests in the file

    d d } i s s X ` ` d

    If the filename starts with as

    then it is treated as

    a proper pathname, not appended to ServerRoot

    ErrorLog is similar but controls where errormessages go

    Useful for debugging CGI scripts and

    misconfigurations

    Check here first ifU V X ` b d

    wont start

    cA

    GBdirect Ltd, 2000 www.linuxtraining.co.uk

  • 8/2/2019 Old Linux Course Modules

    26/561

    Apache Basics 14

    1.13 Customizable Logging

    Customizable logs available with CustomLog i

    d X

    d

    X i i

    X i i

    consists of % directivesand/or

    text

    % directives include:

    Bytes sent, excluding HTTP headers

    Filename

    The contents of headername: header

    in the request

    The process ID of the child that ser-

    viced the request

    First line of request

    Time, in common log format time for-

    mat

    The time taken to serve the request,

    in seconds

    Remote username (may be bogus ifreturn status (%s) is 401)

    The URL path requested

    The ServerName of the server an-

    swering the request

    cA

    GBdirect Ltd, 2000 www.linuxtraining.co.uk

  • 8/2/2019 Old Linux Course Modules

    27/561

    Apache Basics 15

    1.14 CustomLogexamples

    To log the referer information in the file

    d d } i s s d d d

    & $

    #

    4

    # 1 #

    "

    9

    "

    " "

    9

    "

    ( I

    9

    "

    "

    6

    % directivescan be conditional on reply status

    & $

    #

    4

    # 1 #

    "

    9

    "

    " "

    9

    "

    ( I

    E P E

    9

    "

    "

    6

    Logs the refering page only on status

    200,304,302 6

    For full details consult the Apache documentation

    Gives list of all possible % directives

    6For full details consult the Apache documentation

    cA

    GBdirect Ltd, 2000 www.linuxtraining.co.uk

  • 8/2/2019 Old Linux Course Modules

    28/561

    Apache Basics 16

    1.15 Example Configuration

    A sample configuration file could look like this :

    d d } i s s ` X s X V X ` b d

    | `

    d i } i s s ` X s X V X ` b d s b i j `

    d d U j

    t d

    X i d j

    X v ` v

    i d v v v q

    d j

    V j

    s s ` X s X V X ` b d s s d

    We recommend starting with the defaultb i i V j v `

    rather than from scratch

    Correctly configures many things for you

    The default is well annotated

    Everything after a

    character is a comment

    Ignored by

    U V X ` b d

    U V X ` b d

    can check the syntax of its configurationb i i V j i

    X V X ` b d ` i ` i d i

    cA

    GBdirect Ltd, 2000 www.linuxtraining.co.uk

  • 8/2/2019 Old Linux Course Modules

    29/561

    Apache Basics 17

    1.16 Basic Exercises

    1. Apache Installation

    (a) Find out if Apache is installed on your machine . . . if not, install it.

    (b) Check Apache is running on your system.

    i. You should be able to point your web browser at

    E

    2

    2

    2

    tocheck this

    ii. You might have to try

    E

    2

    2

    2

    (c) If Apache is not running, start it

    i. Run $

    " 1 #

    1

    ( 6

    '

    1 ) )

    1

    for information

    (d) If Apache still doesnt appear to be running, find its configuration and log filesand try to fix the error.

    2. Basic configuration

    (a) Familiarise yourself with the

    2

    # '

    9

    file.

    (b) How would you change the directory where the log files are kept?.(c) How would you change the root for documents?

    (d) How would you enable symbolic links to be followed on the cgi-bin directory.

    (e) Make your site only accessible on Port 8080

    (f) Now make it only accessible on the IP address 127.0.0.1, and port 80

    (g) Make the changes and check them.

    (h) Place the following line in your

    #

    file:

    2

    2

    # 2 $

    B

    where

    is the IP address of your machine. You should now be able

    to browse

    2

    2

    # 2 $

    B

    3. Logging

    (a) Take a look at the access logs and familiarise yourself with the information theycontain.

    (b) Set up a custom log to give the time of the request, the request, referer, andnumber of bytes sent, as well as the time taken to serve the request.

    (c) Alter your custom log to show the time taken and bytes sent only if a 200 statusresponse occured.

    cA

    GBdirect Ltd, 2000 www.linuxtraining.co.uk

  • 8/2/2019 Old Linux Course Modules

    30/561

    Apache Basics 18

    1.17 Solutions

    1. Apache Installation

    (a) If Apache is not installed you should be able to install it off a RedHat CD bymounting the CD and typing

    "

    4

    )

    6 D

    4

    '

    " #

    4

    2 "

    4

    (b) There are several ways to check this. One is to

    1 '

    to port 80 of yourmachine and see if you get a response.

    i. This should work for a default RedHat install, though the port number thatApache first listens on changes in various different packaging so you shouldtry both 80 and 8080.

    (c) You can start Apache one of two ways (Which may be the same on somemachines!)

    /etc/rc.d/init.d/httpd start

    somepath/apachectl start 7

    (d) If you cant work out why Apache isnt running ask the tutor for assistance.

    2. Basic configuration(a) You should make sure that you understand everything in the

    2

    # '

    9

    including those sections that are commented out.

    (b) Alter the& $

    #

    4

    # and

    " " # "

    # directives to change where the log files are

    kept, e.g.

    " " # "

    #

    D

    " 1 #

    4 I

    " " # " 1 #

    & $

    #

    4

    #

    D

    " 1 #

    4 I

    1 #

    #

    4 4

    # '

    (c) The root for documents is specified by the

    #

    $

    4

    '

    # #

    directive, e.g.

    #

    $

    4

    '

    # #

    #

    4 I

    (

    #

    $

    4

    '

    (d) You can enable symbolic links by adding

    6

    # '

    F

    &

    to the

    6

    "

    # "

    I

    section for your

    6

    )

    ( 6

    ' , e.g.

    6

    "

    # "

    I

    #

    4 I

    (

    #

    $

    4

    '

    6

    )

    ( 6

    '

    6

    # '

    F

    &

    6

    "

    # "

    I

    (e) Add/Change the

    # "

    directive in your

    2

    # '

    9

    file to read

    # "

    (f) Add the following to your

    2

    # '

    9

    : 6

    '

    E

    2

    2

    2

    (g) Restart the server and try to access it on both port 80 and 8080. Check that itonly works as you expect and fetches documents from the correct place.

    (h) Check that you can browse

    2

    2

    #8 2 $

    B

    7You may have to dig a little to find where this script is

    cA

    GBdirect Ltd, 2000 www.linuxtraining.co.uk

  • 8/2/2019 Old Linux Course Modules

    31/561

    Apache Basics 19

    3. Logging

    (a) Make sure you understand what each of the columns in the access logs is for.Try

    6

    1ing the logs as you browse your webserver

    (b) The following should create a file '

    1 #

    9

    # "

    4

    which holds the desired logformat.

    # # "

    4

    9

    "

    "

    6

    (

    '

    1 #

    & $

    #

    4

    # 1 #

    '

    1 #

    9

    # "

    4

    '

    1 #

    (c) Change your LogFormat line to

    # # "

    4

    9

    "

    "

    6

    E (

    E

    '

    1 #

    & $

    #

    4

    # 1 #

    '

    1 #

    9

    # "

    4

    '

    1 #

    cA

    GBdirect Ltd, 2000 www.linuxtraining.co.uk

  • 8/2/2019 Old Linux Course Modules

    32/561

    Apache Basics 20

    1.18 Two sites and more ...

    U V X ` b d

    can serve multiple sites easily

    Known as Virtual Hosting, e.g.

    to make apache answer requests to address v v v

    froms t t t s t d v i d i s j `

    Your machine must answer to this address8

    U V X ` b d

    must be listening on the address i d

    will makeU V X ` b d

    answer to all

    available addresses on port 80

    This is known as IP-based virtual hosting

    8If you dont know how to set up IP aliases ask the instructor

    cA

    GBdirect Ltd, 2000 www.linuxtraining.co.uk

  • 8/2/2019 Old Linux Course Modules

    33/561

    Apache Basics 21

    1.19 Virtual Hosting Options

    IP-based

    Each site must have a unique, IP addressUses up valuable IP addresses

    Site accessible by all browsers

    Name-based

    Sites share an IP address

    Useful if short of available addresses

    Some browsers may have problems

    Most use IP-based hosting where possible

    Ensures maximum accessibility

    cA

    GBdirect Ltd, 2000 www.linuxtraining.co.uk

  • 8/2/2019 Old Linux Course Modules

    34/561

    Apache Basics 22

    1.20 Name-based hosting

    Name-based hosting looks like:

    cA

    GBdirect Ltd, 2000 www.linuxtraining.co.uk

  • 8/2/2019 Old Linux Course Modules

    35/561

    Apache Basics 23

    1.21 Name-based hosting (continued)

    X

    d i X i

    tellsU V X ` b d

    that an IP address

    can serve multiple hosts i X i

    sections describe how documents

    for each site are servedU V X ` b d

    must be able to resolve the names in

    the directives to the IP addressU V X ` b d

    looks at the i q

    header to decide

    which documents to serve

    Not sent by all browsers

    Requests on other IP addresses will be

    processed as normal

    Can use both IP-based and name-based hosting

    cA

    GBdirect Ltd, 2000 www.linuxtraining.co.uk

  • 8/2/2019 Old Linux Course Modules

    36/561

    Apache Basics 24

    1.22 Block Directives

    U V X ` b d

    has several block directives

    Limit enclosed directives to apply to a certainset of things

    i X i

    is a block directive

    Enclosed directives apply only to that virtual

    host

    Others are:

    |

    d ` i v v v

    s

    |

    d ` i

    | d ` i X i ` b v v v

    s|

    d ` i X i ` b

    !

    d v v v

    s

    !

    d

    !

    d X i ` b v v v

    s

    !

    d X i ` b

    ` X i v v v

    s ` X i

    ` X i X i ` b v v v

    s ` X i X i ` b

    cA

    GBdirect Ltd, 2000 www.linuxtraining.co.uk

  • 8/2/2019 Old Linux Course Modules

    37/561

    Apache Basics 25

    1.23 Block Directives (continued)

    | d ` i X

    d

    Limits the enclosed directives

    to apply to everything below the directory X

    d

    X

    d

    can be anywhere on the filesystem

    Independent of DocumentRoot

    ` X i X

    d

    is similar but is a URL path

    rather than a filesystem path !

    d X

    d

    limits directives to files called X

    d

    Path of the file is irrelevantOnly checks the file name, not its location

    cA

    GBdirect Ltd, 2000 www.linuxtraining.co.uk

  • 8/2/2019 Old Linux Course Modules

    38/561

    Apache Basics 26

    1.24 DirectoryMatch, et al.

    | d ` i X i ` b

    ,!

    d X i ` b

    and ` X i X i ` b

    are similar

    Accept regular expressions as arguments,

    e.g. !

    d X i ` b v $ & v `

    v v v

    s

    !

    d X i ` b

    More flexible

    Need more thought to match only intended files

    cA

    GBdirect Ltd, 2000 www.linuxtraining.co.uk

  • 8/2/2019 Old Linux Course Modules

    39/561

    Apache Basics 27

    1.25 Access Control

    Create a file in the directory to be protected

    Usually

    v b i X ` ` d

    or

    v X `

    Can be anything

    Example: ( 0 1

    2 3 5 ( 2

    7

    8 0 7 0

    @ 0 0

    @

    Only the useri d i d

    , or a user in the groupi d i V

    , may access files in this directory

    Validation is done o