Showing posts with label redhat linux. Show all posts
Showing posts with label redhat linux. Show all posts

Thursday, December 31, 2009

TELNET IN REDHAT LINUX

TELNET:

Features:
1. Great for basic TCP port diagnosis

Task:
1. Connect to TCP ports on various hosts
•telnet 192.168.75.100 22
•telnet www.linuxcbt.com 80

Netstat:

Features:

1. Provides network connection information from /proc/net/*

Task:
1. Return useful information for various protocols
•netstat
•netstat -a - returns all protocols/sockets
•netstat -ntlp - returns all TCP LISTENERS without name resolution
•netstat -nulp - returns all UDP lISTENERS without name resolution

Note:
•netstat uses /etc/services to translate ports to names
•0.0.0.0:514 - this means that Syslog will accept traffic to any of the defined IP
addresses/interfaces on the system

• netstat -ntp - returns established connections (sockets)
• netstat -rn - returns the routing table

LOG ROTATION IN REDHAT LINUX

Log Rotation

Features:

1. Rotation of logs based on criteria
•size
•age (daily, weekly, monthly)

2. Compression

3. Maintain logs for a defined period

•/etc/logrotate.conf - primary (global) config file for all logs
•-can be overriden by context-sensitive files. i.e. apache
•run 'man logrotate'
•/etc/logrotate.d - directory for logs to be rotated
•-httpd - used to rotate Apache logs

/var/log/httpd/*log
{
missingok
notifempty
sharedscripts
postrotate
/bin/kill -HUP `cat /var/run/httpd.pid 2>/dev/null` 2> /dev/null || true
endscript
}

Task:

Setup rotation rule for Cisco log

1. Create entry in: /etc/logrotate.d based on /etc/logrotate.d/syslog

2. Modified the entry to rotate based on new criteria

3. Rotated using: 'logrotate /etc/logrotate.conf'

•Note: Force using: 'logrotatate -f /etc/logrotate.conf'

SYSLOGD IN REDHAT LINUX

SYSLOGD

Features:

1. Handles logging

2. Unix Domain Sockets (/dev/log)

3. Internet Sockets (UDP:514)

4. Ability to log to local and remote targets

5.Implented as 'sysklogd' package

6.Primary configuration file: /etc/syslog.conf

Standard syslog.conf file contains:

1. Rules

•a.facilities -> applications/daemons/network device/etc.

•b. levels -> Importance of message

Range: 0-7
•7 = emergency (less information)
•6 = alert
•5 = critical
•4 = error
•3 = warning
•2 = notice
•1 = info
•0 = debug (more information)

2. Targets

•file - /var/log/messages

•b. tty - /dev/console

•c. remote hosts - @IP_ADDR_of_REMOTE_HOST

•'*' = catchall/wildcard to mean any facility or level

•'.none' = exclusion rule
'man syslog.conf' to learn about the support facilities.levels

Task:

1. Enable UDP logging for remote Cisco gateway (192.168.75.1)

•netstat -nul | grep 514 - reveals UDP:514 listener

•nano /etc/sysconfig/syslog
'SYSLOGD_OPTIONS="-r"'

•restart syslog and confirm UDP:514 listener
confirm using 'netstat -nul | grep 514'

•Configure the router using facility 'local0' and level 'info'

•configure /etc/syslog.conf to accept 'local0.info'

•restart or reload 'syslog'

YUM CONFIGURATION IN REDHAT LINUX

YUM CONFIGURATION

Features:

1. The ability to centralize packages (updates)

Installation & Setup:

1. Install 'createrepo*rpm'

2. Setup directory structure
• /srv/www/linuxcbt.com/RH5/yum

3. Run 'createrepo /srv/www/linuxcbt.com/RH5/yum'

4. Publish the yum repository using HTTP

5. Configure yum client to use HTTP to fetch the RPMs

• /etc/yum.conf
• a1. ###Included as our first repository on the SUSE box###
[0001]
• name=linuxcbtsuse1
• baseurl=http://192.168.75.100/RH5/yum

Note: Ensure that about 3GBs are available for the yum respository
tar -cjvf yum_metadata.bz2 repodata

Yum Usage:

1. Search for packages
a. 'yum search gftp'

2. Install packages - Requires RedHat GPG Key for RPMs
rpm --import http://192.168.75.100/RH5/i386/RPM-GPG-KEY-redhat-release
• 'yum -y install gftp'
• 'yum -y install gftp dhcp' installs 2 packages'

3. Remove Package
• 'yum -y remove gftp'

RPM IN REDHAT LINUX

RPM

Features:

1. Provides package management
• Query
• Install
• Uninstall
• Upgrade
• Verify

2. Auto-verifies packages using GPG, MD5, SHA1SUMs

3. Automatically reports on unresolved dependencies
'rpm'

Query:

1. rpm -qa - dumps all installed packages

2. rpm -qa | wc -l - this dumps all packages and provides a count

3. rpm -qa | grep -i nano

4. rpm -qi nano - dumps info. about the 'nano' package as it's recorded in the
local RPM database

5. rpm -qf /usr/bin/nano - dumps package membership info. for the 'nano' file

6. rpm -qpi http://192.168.75.100/RH5/i386/Server/dhcp-3.0.5-7.el5.i386.rpm -
dumps info. about the uninstalled 'dhcp' package, which resides on the
repository

7. rpm -ql package_name - returns all included files

Verify:

1. rpm -Va - verifies ALL packages on the system, returning info. only if there
are discrepancies from the original installation

2. rpm -Vf /usr/bin/nano

3. rpm -Vp nano

Install (Does NOT overwrite previous package):

Note: Use this method to install a new version of the kernel

1. rpm -ivh *.rpm

2. rpm -ivh http://192.168.75.100/RH5/i386/Server/dhcp-3.0.5-7.el5.i386.rpm

Task:

Change '/usr/bin/nano' then verify

SM5....T /usr/bin/nano

S(file size), M(mode or permissions), 5(MD5), T(mod time)

Upgrade (Installs or overwrites existing package):

1. rpm -Uvh *.rpm

2. rpm -Uvh http://192.168.75.100/RH5/i386/Server/dhcp-3.0.5-7.el5.i386.rpm

Freshen (Updates an existing package):

Note: Will NOT install the package, if it doesn't exist locally

1. rpm -Fvh *.rpm - freshens the current version of a package

Removal:
1. rpm -ev *.rpm - removes a pacakge

Note: removal process considers dependencies and will complain if the removal will break 1 or more packages. To get around this, use '--nodeps' option with 'rpm -ev --nodeps *.rpm'

2. rpm -ev gftp

Package Management GUI:

1. Add/Remove Software
2. system-config-packages

SYMLINKS IN REDHAT LINUX

SYMLINKS

Features:

1. Provides shortcuts to files (including directories)

2. Provides hard links to inode (file system) locations

Soft Links:

1. ln -s source_file target

a. ln -s ./regextest.pl lastscript.pl

Note:
• Soft links may span multiple file systems/hard drives
• Symlink count is NOT increased when using soft links

2. ln -s /home/linuxcbt/testRH5/regextest.pl . - this will symlink (soft) to
the /boot file system

Note: With soft links, if you change the name or location of the source file, you will break ALL of the symlinks (soft)

Hard Links:

Features:

1. The ability to reference the same inode/hard drive location from multiple
places within the same file system
• ln source target
• ln regextest.pl ./testhardregextest.pl - creates a hard link

SED-STREAM EDITOR

SED-STREAM EDITOR

Features:

1. Faciliates automated text editing

2. Supports RegExes (POSIX)

3. Like Awk, supports scripting using '-F' option

4. Supports input via: STDIN, pipe, file

Usage:

1. sed [options] 'instruction[s]' file[s]

2. sed -n '1p' grep1.txt - prints the first line of the file

3. sed -n '1,5p' grep1.txt - prints the first 5 lines of the file

4. sed -n '$p' grep1.txt - prints the last line of the file

5. sed -n '1,3!p' grep1.txt - prints ALL but lines 1-3

6. sed -n '/linux/p' grep1.txt - prints lines with 'linux'

7. sed -e '/^$/d' grep1.txt - deletes blank lines from the document

8. sed -e '/^$/d' grep1.txt > sed1.txt - deletes blank lines from the document
'grep1.txt' and creates 'sed1.txt'

9. sed -ne 's/search/replace/p' sed1.txt

10. sed -ne 's/linux/unix/p' sed1.txt

11. sed -i.bak -e 's/3/4' sed1.txt - this backs up the original file and creates
a new 'sed1.txt' with the modifications indicated in the command

Note:
1)Generally, to create new files, use output redirection, instead of
allowing sed to write to STDOUT
2)Sed applies each instruction to each line

AWK

AWK
Features:

1. Field/Column processor

2. Supports egrep-compatible (POSIX) RegExes

3. Can return full lines like grep

4. Awk runs 3 steps:

BEGIN - optional

Body, where the main action(s) take place

END - optional

5. Multiple body actions can be executed by separating them using semicolons. e.g. '{ print $1; print $2 }'

6. Awk, auto-loops through input stream, regardless of the source of the stream. e.g. STDIN, Pipe, File

Usage:

1. awk '/optional_match/ { action }' file_name | Pipe

2. awk '{ print $1 }' grep1.txt

Note: Use single quotes with awk, to avoid shell interpolation of awk's variables

3. awk '{ print $1,$2 }' grep1.txt

Note: Default input and output field separators is whitespace

4. awk '/linux/ { print } ' grep1.txt - this will print ALL lines containing 'linux'

5. awk '{ if ($2 ~ /Linux/) print}' grep1.txt

6. awk '{ if ($2 ~ /8/) print }' /var/log/messages - this will print the entire line for log items for the 8th

7. awk '{ print $3 }' /var/log/messages | awk -F: '{ print $1}'

BASIC LINUX COMMANDS

BASIC LINUX COMMANDS

1. tty - reveals the current terminal
2. whoami - reveals the currently logged-in user
3. which - reveals where in the search path a program is located
4. echo - prints to the screen
1.echo $PATH - dumps the current path to STDOUT
2.echo $PWD - dumps ths contents of the $PWD variable
3.echo $OLDPWD - dumps the most recently visited directory
5. set - prints and optionally sets shell variables
6. clear - clears the screen or terminal
7. reset - resets the screen buffer
8. history - reveals your command history
!690 - executes the 690th command in our history
command history is maintained on a per-user basis via:
~/.bash_history
~ = users's $HOME directory in the BASH shell
9. pwd - prints the working directory
10. cd - changes directory to desired directory
'cd ' with no options changes to the $HOME directory
'cd ~' changes to the $HOME directory
'cd /' changes to the root of the file system
'cd Desktop/' changes us to the relative directory 'Desktop'
'cd ..' changes us one-level up in the directory tree
'cd ../..' changes us two-levels up in the directory tree
11. Arrow keys (up and down) navigates through your command history
12. BASH supports tab completion:
type unique characters in the command and press 'Tab' key


13. You can copy and paste in GNOME terminal windows using:
left button to block
right button to paste OR Ctrl-Shift-v to paste
14. ls - lists files and directories
ls / - lists the contents of the '/' mount point
ls -l - lists the contents of a directory in long format:
Includes: permissions, links, ownership, size, date, name
ls -ld /etc - lists properties of the directory '/etc', NOT the contents
of '/etc'
ls -ltr - sorts chronologically from older to newer (bottom)
ls --help - returns possible usage information
ls -a - reveals hidden files. e.g. '.bash_history'
Note: files/directories prefixed with '.' are hidden. e.g. '.bash_history'
15. cat - catenates files
cat 123.txt - dumps the contents of '123.txt' to STDOUT
cat 123.txt 456.txt dumps both files to STDOUT
cat 123.txt 456.txt > 123456.txt - creates new catenated file
16. mkdir - creates a new directory
mkdir testRH5 - creates a 'testRH5' directory
17. cp - copies files
cp 123.txt testRH5/
By default, 'cp' does NOT preserve the original modification time
cp -v 456.txt testRH5/
18. mv - moves files
mv 123456.txt testRH5/ - moves the file, preserving timestamp
19. rm - removes files/directories
rm 123.txt
rm -rf 456.txt - removes recursively and enforces
20. touch - creates blank file/updates timestamp
touch test.txt - will create a zero-byte file, if it doesn't exist
touch 123456.txt - will update the timestamp
touch -t 200801091530 123456.txt - changes timestamp

21. stat - reveals statistics of files
stat 123456.txt - reveals full attributes of the file
22. find - finds files using search patterns
find / -name 'fstab'
Note: 'find' can search for fields returned by the 'stat' command
23. alias - returns/sets aliases for commands
alias - dumps current aliases
alias copy='cp -v'
FTP INSTALLATION

Steps:
1. Create FTP user account on FTP server
'useradd -s /bin/false -d /srv/wwwlinuxcbt.com linuxinstall'
'passwd linuxinstall'
2. Confirm FTP connectivity as the user 'linuxinstall'
3. Reboot server with 'boot.iso' CD and type 'linux askmethod'