You are on page 1of 106

Linux System Administration

ITEC4611 Network Management

Pongsuree Limmaneewichid Faculty of Information Science and Technology

What is a system administrator? System Admin Tasks and Duties: install systems (including clients/servers): hardware, software and o.s. upgrade systems: hardware, software and o.s. backups start/stop system (reboot)

ITEC4611 Network Management

Other Duties create accounts (add/delete), passwords, account management job scheduling security performance monitoring and tuning

ITEC4611 Network Management

Some More Duties documentation and testing communication and help (with user community and internal) networking (client/server) handling printers, tape drives, modems, disks, UPS, and other peripherals Memory Management

ITEC4611 Network Management

Almost The Last Duties disk space management (formatting, partitions, quotas) writing/modifying scripts (perl, shell, C, etc..) running specialized services/servers (email server, web server, DNS etc..) problem resolution

ITEC4611 Network Management

Last Duties
Training (others and oneself) Fixing Bugs Automate Tasks Maintain system files Analysis of logs/systems, collect stats, reports Planning and Recommendations Work with vendors, customers Research New Technologies

ITEC4611 Network Management

Network Interface

ITEC4611 Network Management

Initializing Network Interfaces

Basic actions taken by Linux at boot time


Recognize network interface hardware Install appropriate drivers Configure interfaces for use

How to determine if Linux recognized interface


Search directory for interface names
Kernel < 2.6: enter command cat /proc/net/dev Kernel >= 2.6: enter command dir /sys/class/net

Examples of search objects that will likely be present


eth0: physical Ethernet interface lo: local loopback interface
ITEC4611 Network Management 8

Interface Names
Default names for network interfaces
Ethernet interface: eth prefix and numerical suffix
Examples: eth0, eth1, eth2

Token-Ring interface: tr prefix and numerical suffix


Examples: tr0, tr1, tr2

How to change interface names using ip program


Take the interface down: ip link set eth0 down Change interface name: ip link set eth0 name inside Rename interface: ip link set inside up

Two commands for displaying interface information


ip link show inside or ifconfig inside

ITEC4611 Network Management

Example Interface name

ITEC4611 Network Management

10

Multiple Interfaces Example: eth0, eth1, eth2, etc. Challenge: match physical connectors to proper name Order of driver loading determines interface naming Two methods for ordering interface detection
Plug and Play logic in the case of PCI interface Hardware settings in case of ISA bus cards

Addition of new interface impacts naming scheme


Existing interface may be renamed at boot time Precaution: verify connectors linked to same interface name

ITEC4611 Network Management

11

Interface Drivers
Implemented as kernel modules Kernel modules appear below /lib/modules directory View modules loaded using lsmod command
Display example: e1000 76956 2 (autoclean)
e1000 refers to Intel Gigabit Ethernet interface

Run lspci program for list of internal interfaces


Drivers may be researched on the Internet
Download driver to system, if necessary

modprobe can be used to load (reload) driver


Does not require absolute path or file extension Example: modprobe sis900 ( loads SiS900 driver)

ITEC4611 Network Management

12

Configuring Networking With CLI

Techniques common to all Linux distributions Two traditional commands: ifconfig and route ip program is replacing older commands
Part of the new IPROUTE2 package

ITEC4611 Network Management

13

Configuring Networking Examples Example: bringing up eth0 interface


Enter ip and netmask
ifconfig eth0 203.148.144.130 netmask 255.255.255.128

User adds address of gateway


route add default gw 203.148.159.129

ITEC4611 Network Management

14

Using the ip Command


ip designed to replace ifconfig, route, arp Examples of powerful features
Configure an interface using CIDR notation
ip addr add 10.1.1.204/29 dev eth0

Display routing table


ip route

Add default gateway to routing table


ip route add default dev eth0 via 10.1.1.201

Display statistics only upon request


ip statistics link dev eth0

Search ip man page or Internet for more information

ITEC4611 Network Management

15

Adding IP Addresses to Interfaces


IP aliasing: assigning extra IP addresses to interface Method for creating aliases based on ifconfig
Append colon and number to interface name
Example: first alias called eth0:0

Alias names may use letters after interface identifier


Example: eth0:web1

Method for creating aliases based on ip


Aliases lack names, but Linux knows how to use them Command syntax is more compact and readable
Example: ip addr 10.0.0.3/8 dev eth0

ITEC4611 Network Management

16

Wireless Interfaces
Unique features: radio receiver and transmitter Wireless-specific parameters to display and configure
Frequency, transmit power, data rate, encryption key Selecting between ad hoc or access point mode

Two wireless-specific programs: iwconfig and iwlist


Used after ifconfig or ip configures network interface

iwconfig: main tool for configuring wireless interfaces iwconfig syntax: iwconfig interface option
interface corresponds to interface name option corresponds to wireless-specific parameters
Example: freq number sets transmitter's frequency

ITEC4611 Network Management

17

Using proc proc filesystem: virtual filesystem


Allows you to view and modify kernel settings Settings emulate filesystem's directory structure

View proc filesystem by going to /proc directory


Files and directories do not exist on hard disk Example: enter cat /proc/cpuinfo for CPU information

Network-related settings in two /proc directories


/proc/net: view status information only /proc/sys/net: modify network-related settings
Read/write permissions described in later chapters

ITEC4611 Network Management

18

Using proc (continued)


Test command for modifying network parameters
Enter echo "49152 65535" > /proc/sys/net/ipv4/ip_local_port_range Changes port range to correct value (49152 to 65535)

Verify changes made with test command


Enter cat /proc/sys/net/ipv4/ip_local_port_range New connections use ports in new range

How to make changes permanent


Put echo command in start-up script Example: /etc/rc.d/rclocal script

ITEC4611 Network Management

19

Using proc (continued) Another proc setting: /proc/sys/net/ipv4/ip_forward


Set to 1 on two conditions
You have more than one interface You want to route packets between interfaces

Linux should update setting automatically

Manual way to set /proc/sys/net/ipv4/ip_forward


Enter echo "1" > /proc/sys/net/ipv4/ip_forward

Other proc settings presented in later chapters

ITEC4611 Network Management

20

Using ARP
Address Resolution Protocol
Obtains hardware address of host given its IP address Available through arp command

ARP cache: table maintained by ARP protocol


Map of IP addresses to interface hardware addresses

View ARP table using arp a (the a is for all)


Displays host name, IP and MAC addresses

Other characteristics of ARP table entries


Entries may be updated (not frequently exercised) Entries are dynamic, will be discarded if not used

ITEC4611 Network Management

21

System Networking Scripts


Intelligent tools for handling network interfaces Follow model used in UNIX-based systems High-level controlling script: /etc/init.d/network
Example: start up networking
Enter /etc/rc.d/init.d/network start

/etc/init.d/network based on other scripts and files


Location: /etc/sysconfig/network-scripts subdirectory
Relevant file in subdirectory is called networking

Two main interface control scripts: ifup and ifdown

Actual configuration data stored separately


Example: /etc/sysconfig/network-scripts/ifcfg-eth0

ITEC4611 Network Management

22

System Networking Scripts (continued)


Fedora Core scripts built around aliases with names
ifconfig command suitable for use in scripts

Adding IP alias through scripting


Create new file in /etc/sysconfig/network-scripts
File: ifcfg-eth0:0 (may be copy of existing file ifcfg-eth0)

Change DEVICE and IPADDR lines in new file


Should refer to eth0:0 and the new IP address

Restart networking to activate additional IP address

Additional IP address started every time Linux started


Halt process in future by deleting additional file

ITEC4611 Network Management

23

Using ping for System Testing


ping: utility used to send ICMP echo packets ICMP echo packet verifies connection with host Using ping: ping + host IP address or host name Actions following entry of ping 203.148.144.129
Reachable host affirms connection System displays message showing connection valid Packets continue to be sent until program halted Press Ctrl + C to end program and generate summary

Using ping to identify source of problem


Ping 127.0.0.1 checks internal networking stacks

ITEC4611 Network Management

24

Using traceroute Using traceroute to Examine Routing traceroute provides greater detail than ping Basic traceroute functions
Relies on TTL field and ICMP packet timed out data Identifies each router (each hop) between you and host Attempts to reach host within 30 hops (may be reset)

Example: enter traceroute 198.60.22.77


Successful route makes 14 hops
Hop corresponds to line number in display

IP address and host name shown for each router Probe packets supply three timing values for each hop

ITEC4611 Network Management

25

Basic Network troubleshooting

ITEC4611 Network Management

26

Configuring Client Services

ITEC4611 Network Management

27

Name Services
Domain: collection of computers using common name
Examples: yahoo.com or amazon.com

Name services map domains names to IP addresses Name services as an Application-layer program
Returns IP address when name is input Returns name when IP address is input

Name resolution: converts name to IP address Name server: computer providing name services

ITEC4611 Network Management

28

The hosts File /etc/hosts file: simplest name service


Contains table of names and IP addresses Each text line in file corresponds to table row May be modified and copied to other hosts

Sample output
127.0.0.1 192.168.1.35 localhost.msit.com localhost sundance.msit.com

Using the hosts file


Enter www.linux.com in your Web browser Browser sends request to resolver for IP address Resolver searches hosts file, responds with address Browser initiates network connection with address

ITEC4611 Network Management

29

Configuring the DNS Resolver Manually Resolver as the client part of DNS
Makes requests to DNS server on behalf of program Example: Web browser uses Linux resolver

Configuring resolver
Go to /etc/resolv.conf file Enter nameserver plus IP address of DNS server
Include up to three DNS servers in file Advisable to select servers close to network segment

Example: nameserver 198.60.22.2

Resolver tries to reach DNS servers in resolv.conf list


Process ends when server reached or list exhausted

ITEC4611 Network Management

30

Configuring the DNS Resolver Manually One domain statement may be included in resolv.conf
Only one domain name in a domain statement Example: domain course.com
Helps resolver construct fully qualified name Domain string would be added to command ping www

Search statement allows for additional domain names


Example: search abc.com cbs.com nbc.com
Given command ping www, resolver has more choices Appends domain strings as needed, until list exhausted

The resolv.conf file may be revised in any text editor

ITEC4611 Network Management

31

Configuring the DNS Resolver etc/host.conf file specifies order for resolving names
Example: order hosts, bind
Resolver first checks etc/host for name to be resolved If no name present, resolver makes DNS query using resolv.conf The word bind refers to BIND software

/etc/nsswitch.conf file has replaced etc/host.conf


Provides etc/host.conf functionality Includes more options for locating information Also used by other programs, such as NIS

ITEC4611 Network Management

32

Shell Introduction and Command

ITEC4611 Network Management

33

Shells

Interprets and executes commands 4 - 5 different shells are installed by default Each shell has slightly different environment & features Examples
bash - most common, powerful csh - C shell, less features than bash sh - Bourne shell, oldest zsh - new, quite powerful type echo $SHELL should return something like /bin/bash

to find out the particular shell

to change shell use the command chsh


34

ITEC4611 Network Management

Navigating directories

To find out the current directory: pwd - returns the current directory To change to another directory: cd /path/to/dir . is the current directory .. is the parent directory
ITEC4611 Network Management 35

Linux (as Windows) has hierarchical directory structure Each component is seperated by forward slash - / / is the root directory Examples
/usr/bin/ /home/admin

Paths Paths define the location of a file or directory

seperated by slashes: / Could be absolute or relative Absolute


starts with the root directory /home/raheel/paper.txt , /usr/local/bin in relation to the current directory pwd -> /home/admin, cd hw -> /home/admin/hw cd .. -> /home/admin
36

Relative

ITEC4611 Network Management

Important directories

/bin : essential Unix commands, like ls /usr/bin : some extra Unix commands /usr/sbin : for super user, system administration /boot : kernel and other files for booting /etc : system services - networking, mail, disk management /var : administrative files, such as logs /usr/local : locally added programs and files by sys. admin. /dev : device files - interface b/w hardware and filesystem /proc : running processes

ITEC4611 Network Management

37

Navigating directories (contd.)

cd by itself - takes to home directory

cd ~ also Home directory also denoted by ~

mkdir dirname creates new directory under current one mkdir /path/to/dirname creates new directory under the exact path Rmdir, rm r removes a directory
38

cd . doesnt do anything cd .. takes you to parent directory To make a directory:

ITEC4611 Network Management

Listing files

ls - the most popular command lists the directory contents lots of options available with arguments
argument - option given to a command lists current directorys contents lists the contents of /home directory list hidden files with the -a argument long information about contents. Very useful
39

ls ls /home ls -a ls -l

ITEC4611 Network Management

What is a command?

Small (big) program provided by UNIX/Linux Can make your own commands too Command is simply a file
Have to mark it executable Put it somewhere special (in command path)

Path : directories where shell looks for a given command find out path by echo $PATH /usr/local/bin/:/usr/bin:/bin/ Sometime have to specify full (absolute path) to a command
command not in path more than one name for same command
40

ITEC4611 Network Management

Command (contd.)

Add a directory to path export PATH=$PATH:/new/directory/path current directory usually not in path use ./command-name Help for commands Put a command in background ls & -> [1] 23142 Bring it back fg %1 or fg 23142 Commands and shell provided features

type ls type cd
41 ITEC4611 Network Management

man command-name man 2 command-name : for 2nd section apropos edit : displays all commands related to editing

Typing shortcuts

Word Completions

Dont have to type full command or path Type Tab after typing a couple of letters cd /usr/inc - then hit Tab

would complete it as cd /usr/include/ completes the path Type mor and then hit Tab Will complete it as the command more Type cd /usr/l and hit Tab Would display lib and local because they begin with l

Works on commands too

If more than one match, the displays the options

ITEC4611 Network Management

42

Command line editing

Can edit previously typed commands Commands are stored once typed

No. of commands to be stored in history can be set

Can recall previous commands and use them Up arrow - previous command Down arrow - next command Left and right arrow to navigate Ctrl-U to delete whole line if mistyped Ctrl-A : beginning of line Ctrl-E : end of line
43

ITEC4611 Network Management

Command history in detail!

Can view previous commands in one display type history


displays history of commands, numbered displays only N previous commands deletes all commands in history execute previous command execute the Nth command from top

history N history -c !!

!N

ITEC4611 Network Management

44

Exapnding filenames (wildcards)

Specify a group of files/directories with a single word if ls gives


paper1.doc work.ppt paper2.doc paper3.doc papa.doe prayer.doc thesis.doc

Then ls *.doc will give


paper2.doc paper3.doc prayer.doc thesis.doc

paper1.doc

* says match as many characters as possible in place of * ? says match one character in place of ?

ls paper?.doc gives
45

paper1.doc paper2.doc paper3.doc

ITEC4611 Network Management

More wildcards

Can use * in between a word

ls p*.doc will give


paper1.doc paper2.doc paper3.doc

Can specify characters instead of ? and *

ls paper[123].doc will give ls paper[2-3].doc will give

paper1.doc paper2.doc paper3.doc

paper2.doc paper3.doc

Can combine wildcards


ls pap*.do? will give
paper1.doc paper2.doc paper3.doc papa.doe

ITEC4611 Network Management

46

Displaying Content of Text Files Concatenation


Joining of text together to make one larger whole In Linux, words and strings of text are joined together to form a displayed file

cat command
Linux command used to display (or concatenate) the entire contents of a text file to the screen

ITEC4611 Network Management

47

Displaying Content of Text Files Log files


File that contains past system events

tac command
Linux command that displays a file to the screen beginning with the last line of the file and ending with the first line of the file

ITEC4611 Network Management

48

Displaying Content of Text Files head command


By default, displays the first 10 lines (including blank lines) of a text file to the terminal screen Can also take a numeric option specifying a different number of lines to display

tail command
By default, displays the last 10 lines (including blank lines) of a text file to the terminal screen Can also take a numeric option specifying a different number of lines to display

ITEC4611 Network Management

49

Displaying Content of Text Files more command


Linux command used to display a text file page-bypage and line-by-line on the terminal screen Gets its name from the pg command once used on UNIX systems more does more than pg did

ITEC4611 Network Management

50

Displaying Content of Text Files less command


Linux command used to display to display a text file page-by-page on the terminal screen Users may then use the cursor keys to navigate the file

The more and less commands can also be used in conjunction with the output of other commands if that output is too large to fit on the terminal screen

ITEC4611 Network Management

51

Displaying Binary File Contents


It is important to employ text file commands as cat, tac, head, tail, more, and less only on files that contain text
Otherwise you may find yourself with random output on the terminal screen, or even a dysfunctional screen

strings commands
Linux command used to search for and display text characters in a binary file

ITEC4611 Network Management

52

Displaying Binary File Contents od command


Linux command that is used to display the contents of a file in octal format (numeric base 8 format) Safe to use on binary files and text files

ITEC4611 Network Management

53

Searching for Text within Files Text tools


File that stores information in a readable text format

Regular expressions (regxp)


Special metacharacters used to match patterns of text within text files Commonly used by many text tool commands such as grep

ITEC4611 Network Management

54

Searching for Text within Files Text tools and programming languages that use regular expressions include:
grep awk sed vi emacs

ITEC4611 Network Management

55

Searching for Text within Files Text tools and programming languages that use regular expressions include (continued):
ex ed C++ PERL Tcl

ITEC4611 Network Management

56

Regular Expressions
Differences between regular expressions and wildcard metacharacters include:
Wildcard metacharacters are interpreted by the shell
Regular expressions are interpreted by a text tool program

Wildcard metacharacters match characters in filenames (or directory names) on a Linux filesystem
Regular expressions match characters within text files on a Linux filesystem

ITEC4611 Network Management

57

Regular Expressions
Differences between regular expressions and wildcard metacharacters include (continued):
Wildcard metacharacters typically have different definitions than regular expressions There are more regular expressions than wildcard metacharacters Regular expressions are divided into two different categories:
Common extended

ITEC4611 Network Management

58

Regular Expressions
Regular Description Expression
* Matches 0 or more occurrences of the previous character Matches 0 or 1 occurrences of the previous character Matches 1 or more occurrences of the previous character Matches 1 character of any type

Example
letter* matches lette, letter, letterr, letterrrr, letterrrrrr etc. letter? matches lette, letter letter+ matches letter, letterr, letterrrr, letterrrrrr etc. letter. matches lettera, letterb, letterc, letter1, letter2, letter3, etc. Letter[1238] matches letter1, letter2, letter3, & letter8

Type
Common

? +

Extended Extended

. (period)

Common

[]

Matches 1 character from the range specified within the braces

Common

ITEC4611 Network Management

59

Regular Expressions
Regular Expression [ ] Description Matches 1 character NOT from the range specified within the braces Matches a specific range or number of the previous character Matches the following characters if they are the first characters on the line Matches previous characters if they are the last characters on the line Matches either of the two sets of characters Example letter[1238] matches letter4, letter5, letter6, lettera, letterb, etc. (any character except 1,2,3 or 8) letter{3} matches letterrr letter{2,4} matches letterr, letterrr and letterrrr ^letter matches letter if letter is the first set of characters in the line letter$ matches letter if letter is the last set of characters in the line (mother|father) matches the word mother or father Type Common

{}

Extended

Common

Common

(|)

Extended

ITEC4611 Network Management

60

The grep Command


grep
Stands for Global Regular Expression Print Used to display lines in a text file that match a certain common regular expression

Use the egrep command to display lines of text that match extended regular expressions The fgrep command does not interpret any regular expressions and consequently returns results much faster than the egrep command

ITEC4611 Network Management

61

The vi Editor One of the oldest and most popular visual text editors available for UNIX operating systems
Its Linux equivalent (known as vimvi improved) is standard on almost every Linux distribution as a result

Though not the easiest of the editors to use when editing text files, it has the advantage of portability

ITEC4611 Network Management

62

The vi Editor The vi editor is called a bi-modal editor as it functions in one of two modes:
Command mode
Allows a user to perform any available text editing task that is not related to inserting text into the document

Insert mode
Allows the user to insert text into the document but does not allow any other functionality

ITEC4611 Network Management

63

The vi Editor
Key l A O Shift-I Shift-A Shift-O [Esc] Description Changes to insert mode and places the cursor before the current character for entering text Changes to insert mode and places the cursor after the current character for entering text Changes to insert mode and opens up a new line underneath the current line for entering text Changes to insert mode and places the cursor at the beginning of the current line for entering text Changes to insert mode and places the cursor at the end of the current line for entering text Changes to insert mode and opens up a new line above the current line for entering text Changes back to command mode while in insert mode

ITEC4611 Network Management

64

The vi Editor
Key w, W, e, E b, B 53G G 0,^ $ x 3x dw d3w, 3dw dd d3d, 3dd d$ d^, d0 Description Moves the cursor forward one word Moves the cursor backward one word Moves the cursor to line 53 Moves the cursor to the last line in the document Moves the cursor to the beginning of the line Moves the cursor to the end of the line Deletes the character the cursor is on Deletes three characters starting from the character the cursor is on Deletes one word starting from the character the cursor is on Deletes three words starting from the character the cursor is on Deletes the whole line starting from the line the cursor is on Deletes three whole lines starting from the line the cursor is on Deletes from the cursor character to the end of the current line Deletes from the cursor character to the beginning of the current line

ITEC4611 Network Management

65

The vi Editor
Key gg yw y3w, 3yw yy y3y, 3yy y$ y^, y0 p Description Moves the cursor to the beginning of the document Copies one word (starting from the character the cursor is on) into a temporary buffer in memory for later use Copies three words (starting from the character the cursor is on) into a temporary buffer in memory for later use Copies the current line into a temporary buffer in memory for later use Copies three lines (starting from the current line) into a temporary buffer in memory for later use Copies the current line from the cursor to the end of the line into a temporary buffer in memory for later use Copies the current line from the cursor to the beginning of the line into a temporary buffer in memory for later use Pastes the contents of the temporary memory buffer underneath the current line

ITEC4611 Network Management

66

The vi Editor
Key P J [Ctrl]-g u . /pattern ?pattern n N Description Pastes the contents of the temporary memory buffer above the current line Joins the line underneath the current line to the current line Displays current line statistics Undoes the last function (undo) Repeats the last function (repeat) Searches for the first occurrence of the pattern in the forward direction Searches for the first occurrence of the pattern in the reverse direction Repeats the previous search in the forward direction Repeats the previous search in the reverse direction

ITEC4611 Network Management

67

The vi Editor
Function :q :q! :wq :w filename :!date :r !date :r filename :set all :set :s/the/THE/g :1,$ s/the/THE/g Description Quits from the vi editor if no changes were made Quits from the vi editor and does not save any changes Save any changes to the file and quits from the vi editor Saves the current document to a file called filename Executes the date command using a BASH shell Reads the output of the date command into the document under the current line Reads the contents of the text file called filename into the document under the current line Displays all vi environment settings Sets a vi environment setting to a certain value Searches for the regular expression the and replaces each occurrence globally throughout the current line with the word THE Searches for the regular expression the and replaces each occurrence globally from line 1 to the end of the document with the word THE

ITEC4611 Network Management

68

Other Common Text Editors


pico (PIne COmposer) editor
By far, the easiest alternative to the vi editor Commonly used to create and edit e-mails

joe (Joes Own Editor)


Wordstar-style editor; can be run in pico-compatible mode (jpico) or emacs-compatible mode (jmacs) My preferred editor when run as jpico

mcedit editor (Midnight Commander Editor)


Resembles pico yet has more functionality, support for regular expressions, and ability to use the mouse for highlighting text

ITEC4611 Network Management

69

Startup files

Used to customize environment before starting the shell Every shell has its own startup file; hidden
Bash has .bashrc and .bash_profile

Can contain commands and programs

ITEC4611 Network Management

70

FileSystem

ITEC4611 Network Management

71

Filesystem : Introduction

Filesystem: Device or part of a device (partition) formatted to store files Device: CD, DVD, hard drive, floppies, etc. Type (format) of filesystem is transparent to user

Data is presented as directories To a user, all filesystems look alike

Different formats for different purposes Random access devices only can have filesystems

Tape only allows sequential access


72

ITEC4611 Network Management

Filesystem types

Supports most of the popular ones

and even obscure ones new types are being added experimental drivers available contains list of supported FSs not complete

Can look at /proc/filesystems

Can select filesystems to support if building kernel


73

ITEC4611 Network Management

Some filesystem types Filesystem


Second Extended filesystem Third Extended filesystem Minix filesystem Network filesystem VFAT filesystem NT filesystem .................

Type
ext2 ext3 minix NFS vfat ntfs .....

ITEC4611 Network Management

74

Mounting filesystems

To access a filesystem, it should be mounted Mounting, maps a filesystem to a given directory CDs/DVDs etc. are usually automounted May need to mount/unmount sometimes A filesystem can be mounted

automatically at startup interactively - using a command


75

ITEC4611 Network Management

mount command

Used to mount any filesystem mount - tells all mounted filesystems Need to know
the filesystem type the location of the device where to mount it

The mount point defines the location of a filesystem Flexibility in mounting any device anywhere (in any directory) man mount
ITEC4611 Network Management 76

Hard drive partition /dev/hda1 at /windows/cdrive, windows format


mount -t vfat /dev/hda1 /windows/cdrive mounts the whole partition as folders in /windows/cdrive

Filesystem

Filesystem is also an application

for managing storage and access to files and dirs. used by applications

create files and directories open and modify existing ones delete specify access controls

ITEC4611 Network Management

77

Filesystem

File: single item for storing information Directory: hierarchical collection of files & other directories

root directory: / , topmost, every other dir. or file lives under it sub directories: a directory under root dir. directories help in organization

"On a UNIX system, everything is a file; if something is not a file, it is a process."

ITEC4611 Network Management

78

Filesystem layout

ITEC4611 Network Management

79

Some main subdirectories


/bin /boot /dev /etc /home /initrd /lib /lost+foun d /mnt /net /opt /proc /root /tmp /usr /var
common programs, shared by admins, users startup files and kernel. Also GRUB data references to all hardware as special files important system configuration files. Sort of like Control Panel containes home directories for most users information contained for booting.. Dont mess with it! library files, common files needed by many programs files that were recovered after a system failure mount point for all external devices mount point for remote filesystems extra third party software info about system resources, man proc home dir. for the the admin temporary space program, libraries, docs for most user programs other temporary files, such as logs, downloaded files, mail queue

ITEC4611 Network Management

80

Partitions

Different directories can be on seperate partitions Every filesystem is on a seperate partition Advantage

Higher data security Flexible storage options Seperation of different kinds of data

system data, user data, application data

Two types
swap partitions data partitions

df command for all active non-swap partitions fdisk for partition management
81

ITEC4611 Network Management

Basic Accounting

ITEC4611 Network Management

82

Accounts

Linux is a multiuser operating system Account for a user identified by username password for authentication Password file: used for authentication username:password:uid:gid:gecos:homedir:shell Two types of accounts


Root
Called super user Every Linux system has one Can create other accounts for users Restricted Can be given more permissions

User

Some accounts may not have any actual user


needed by some application
83

ITEC4611 Network Management

Accounts..

Root account created during installation

One or more user accounts as well Potentially dangerous prompt for the users password

Shouldnt login using root account Can change into any user using su user

su changes to root account To run a single command with root previliges


use sudo
84 ITEC4611 Network Management

Accounts

Creating new users only admins can do this adduser command most default options are ok New users should change their password: passwd root can do this for a user: passwd user Deleting users accounts: userdel -r username Disabling a user temporarily Remove the entry from /etc/passwd
ITEC4611 Network Management 85

Permissions

Very critical in multi-user environment Maintain access over files for different users
Other users cannot access your files Critical files can only be accessed by root Similar users can be grouped together Easy to maintain permissions for a group Easy to share files within a group A user can belong to more than one group groups command User Group Others
86

Besides users, there are groups

Permissions are maintained for

ITEC4611 Network Management

Permissions

Permissions under Linux are


Ownership Access rights

Ownership - who owns the file The creator of a file becomes its owner
Creators default group becomes the group owner Ownership can be changed later Can modify ownership Can change access rights

The super user, root, owns everything

ITEC4611 Network Management

87

Access rights (Permissions)

Access rights Who can read, write, view a file Read



File - open it Directory - open it, list its contents File - change its contents Directory - add or remove its contents File - execute it Directory - list using ls -l : extended information

Write

Execute

ITEC4611 Network Management

88

Permissions

ls -l to view the permissions Sample output

ITEC4611 Network Management

89

Changing Ownership

Rre to do this To change ownership: chown chown username file_or_dir To change group ownership: chgrp chgrp groupname file_or_dir combine if username & group name are same

chgrp name.name file_or_dir

ITEC4611 Network Management

90

Changing Permissions

chmod command

standard way to change permissions a : all u : current user (who is using chmod) g : files current group o : other users, not in g + : add an attribute - : remove an attribute = : set (absolutely) a permission r, w, x: read, write, execute

root can change permissions to any file/directory Besides root, only the owner can change permissions
91

ITEC4611 Network Management

Changing Permissions

Simple example: make a file executable

chmod +x filename: gives permission to everyone to only yourself: chmod u+x filename to yourself and group: chmod ug+x filename multiple: chmod ug+rwx filename remove a permission: chmod o-x filename give write permission to all: chmod a+w filename remove all permissions and set file readable by user only

chmod u=r filename

-r option: set permission to every item in a directory


chmod a+rw -r dirname

ITEC4611 Network Management

92

Software Installation and Update

ITEC4611 Network Management

93

Software installation

Numerous software options Several sources


Installation CD Websites

sourceforge.net freshmeat.net

Usually free Open source

Software update
ITEC4611 Network Management 94

Software installation

Installation options
Package system

Easiest to use package system

Download binary file Download source files, compile

apt, rpm, dpkg, etc. depends on the distribution

May need to compile the source to install


Similar to installing/upgrading kernel
ITEC4611 Network Management

not all software will have package file for every distribution same goes for binary files
95

Using RPM

RPM (RedHat Package Manager) Automates install/upgrade/uninstall of software Keeps track of individual software files Maintains dependencies (pre-requisite software) To install
rpm -ivh software-file.rpm Will complain about dependencies if not available To upgrade rpm -Uvh software-file.rpm

To remove rpm -e software To query


rpm
-q software
ITEC4611 Network Management

96

Using apt

Similar to RPM in many ways Much more convenient Repositories



sources of available software Internet CD Local

Software installs with less errors usually Automatically downloads and installs from sources Keeps track of dependencies and installs required ones

Easiest to use apt with Synaptic front-end


ITEC4611 Network Management 97

Using apt

Requires sudo previliges for most tasks To update the list of software from repositories sudo apt-get update To upgrade all available software sudo apt-get upgrade To install a software
repositories

sudo apt-get install software_name apt downloads and installs software and dependencies from

To search for software in repositories sudo apt-cache search gedit To look for information on a particular software
sudo
apt-cache show gedit
98 ITEC4611 Network Management

Using Synaptic

GUI front-end to apt Easy to use and configure apt with Synaptic Install apt first with Synaptic Available under System>Administration Can edit and add repositories
ITEC4611 Network Management 99

Archive and Compression Utilities

Crucial tools for software installation from source Archiving


Pack many files into a single file; easily transferred tar reduce the size of a file or set of files compress gzip
archive several files into one then compress the file
100

Compression

Usually archive and compression used together


ITEC4611 Network Management

gzip

Powerful compression utility Working Amount of compression depends on the kind of file

For eg., JPEG or PNG images are already compressed To find out how much compression was done:

Compress a file, big_file save compressed file as big_file.gz remove original file

To get original file back:


gunzip big_file.gz
101 ITEC4611 Network Management

gzip -l big_file.gz

Using tar

tar is for archiving



packing many files into a single file preserves ownerships, links, directory structure
c x t r f v

Options:

create a new archive extract files from archive list contents of archive append to archive filename of archive verbose

To archive two files a.txt and b.txt into arch.tar: tar cvf arch.tar a.txt b.txt To archive a directory temp into temp.tar
tar
cvf temp.tar temp
102 ITEC4611 Network Management

Using tar

To extract an archive mt.tar tar xvf mt.tar To view the contents of the archive tar tvf mt.tar Using with gzip use the z option when compressing into a gzip file To archive & compress a.txt and b.txt into f.tar.gz tar cvzf f.tar.gz a.txt b.txt To extract the above compressed archive tar xvzf f.tar.gz To view the contents
tar
tvzf f.tar.gz
ITEC4611 Network Management 103

Installing/Upgrading software the hard way

rpm and apt packges of a software may not always be available Use the latest release of the software

Source Binary Available as compressed files Extract the files, which contain the necessary programs Make sure the extracted program is in the PATH Extract the files, compile and install the program

Binary

Source

ITEC4611 Network Management

104

Installing from source

Hardest way to install a program Necessary for installing latest version of the software May require root privileges Usual steps
Download the required tar compressed file Extract the files using tar Run its configuration program (usually ./configure) Run make for compiling Run make install (usually with sudo) for installation Cleaning (optional): make clean shared libraries compiling problems

May run into problems!

ITEC4611 Network Management

105

END

ITEC4611 Network Management

106

You might also like