Tuesday, May 17, 2011

Linux Filesystem Management

badblocks                Used to search a disk or partition for badblocks.
cfdisk                         Similar to fdisk but with a nicer interface.
debugfs                    Allows direct access to filesystems data structure.
df                                Shows the disk free space on one or more filesystems.
dosfsck                    Check and repair MS-Dos filesystems.
du                             Shows how much disk space a directory and all its files contain.
dump                     Used to back up an ext2 filesystem. Complement is restore.
dumpe2fs             Dump filesystem superblock and blocks group information. Ex: dumpe2fs /dev/hda2
e2fsck                   Check a Linux second extended filesystem.
e2label                 Change the label on an ext2 filesystem.
exportfs              Used to set up filesystems to export for nfs (network file sharing).
fdisk                     Used to fix or create partitions on a hard drive.
fdformat            Formats a floppy disk.
fsck                      Used to add new blocks to a filesystem. Must not be run on a mounted file system.
hdparm             Get/set hard disk geometry parameters, cylinders, heads, sectors.
mkfs                  Initializes a Linux filesystem. This is a front end that runs a separate program depending on the filesystem’s type.
mke2fs             Create a Linux second extended filesystem.
mkswap          Sets up a Linux swap area on a device or file.
mount            Used to mount a filesystem. Complement is umount.
rdev               Query/set image root device, swap device, RAM disk size of video mode. What this does is code the device containing the root filesystem into the kernel image specified.
rdump           Same as dump.
rmt                  Remote magtape protocol module.
restore          Used to restore an ext2 filesystem.
setfdprm        Set floppy drive parameters.
swapoff(8)    Used to de-activate a swap partition.
swapon(8)    Used to activate a swap partition.
sync                Forces all unwritten blocks in the buffer cache to be written to disk.
tune2fs          Adjust tunable filesystem parameters on second extended filesystems.
umount          Unmounts a filesystem. Complement is mount.

Network Analysis Tools


* netstat – Displays information about the systems network connections, including port connections, routing tables, and more. The command “netstar -r” will display the routing table.
* traceroute – This command can be used to determine the network route from your computer to some other computer on your network or the internet. To use it you can type “route IPaddress” of the computer you want to see the route to.
* nslookup – Used to query DNS servers for information about hosts.
* arp – This program lets the user read or modify their arp cache.
* tcpdump – This program allows the user to see TCP traffic on their network.
* dig(1) – Send domain name query packets to name servers for debugging or testing.

Pluggable Authentication Modules


PAM stands for Pluggable Authentication Modules. PAM is a library, used to control the function of various applications that have the capability to use the PAM libraries. PAM is based on a series of library modules, some of which depend on configuration files. Locations of PAM configuration files and library modules are:
* All PAM applications are configured in the directory “/etc/pam.d” or in a file “/etc/pam.conf”.
* The library modules are normally stored in the directory “/lib/security”.
* The configuration files are located in the directory “/etc/security”.
To configure PAM, on systems already set up for it, you would need to edit the files for the service you want to modify in the “/etc/pam.d” directory, and modify the appropriate configuration file in the directory “/etc/security”. This page will explain how to set up the configuration files and how to configure the modules so applications can use them.
The PAM configuration files
PAM is controlled a main configuration file( /etc/pam.conf) or control directory (/etc/pam.d). Some PAM module’s behavior is controlled with configuration files (in /etc/security)as listed below:
* access.conf – Login access control. Used for the pam_access.so library.
* group.conf – Group membership control. Used for the pam_group.so library.
* limits.conf – Set system resource limits. Used for the pam_limits.so library.
* pam_env – Control ability to change environment variables. Used for the pam_env.so library.
* time – Allows time restrictions to be applied to services and user privileges. Used for the pam_time.so library.

DHCP server configuration explained


The configuration file is /etc/dhcpd.conf. Its options are:
* option broadcast-address – Broadcast address in my case would be “option broadcast-address 192.168.199.255;”.
* option dhcp-client-identifier – String rather than hardware address used to identify DHCP clients.
* option domain-name – The name of the domain the DHCP server is serving.
* option domain-name-servers – The address(es) of the DNS servers on the domain. Ex: “option domain-name-servers 192.168.199.1, 192.168.199.5;” The names are separated by a comma and whitespace with a semicolon ending the line.
* option host-name – The client’s host name.
* option lpr-servers – Lists print server addresses.
* option nntp-server – Network News Transfer Protocol (NNTP) server address
* option pop-server – Mail server address.
* option routers – The default router address.
* option smtp-server – The SMTP e-mail server address(es).
* option subnet-mask – The subnet mask is not necessary since the subnet statement (see example file) contains a netmask value.
* option time-offset – The difference between your time zone and the Coordinated Universal Time.
* option netbios-name-servers – Define the address of the NBNS name server for samba services.

File searching Commands in Linux


alias l=’ls -l –color=auto’          quick dir listing
ls -lrt           List files by date. See also newest and find_mm_yyyy
ls /usr/bin | pr -T9 -W$COLUMNS    Print in 9 columns to width of terminal
find -name ‘*.[ch]‘ | xargs grep -E ‘expr’    Search ‘expr’ in this dir and below.
find -type f -print0 | xargs -r0 grep -F ‘example’    Search all regular files for ‘example’ in this dir
find -maxdepth 1 -type f | xargs grep -F ‘example’    Search all regular files for ‘example’ in this dir
find -maxdepth 1 -type d | while read dir; do echo $dir; echo cmd2; done    Process each item with multiple commands (in while loop)
find -type f ! -perm -444    Find files not readable by all (useful for web site)
find -type d ! -perm -111    Find dirs not accessible by all (useful for web site)
locate -r ‘file[^/]*\.txt’    Search cached index for names. This re is like glob *file*.txt
look reference    Quickly search (sorted) dictionary for prefix
grep –color reference /usr/share/dict/words    Highlight occurances of regular expression in dictionary

CRON Jobs


To edit cron jobs
$ crontab -e
You may want to put in the following header
#MINUTE(0-59) HOUR(0-23) DAYOFMONTH(1-31) MONTHOFYEAR(1-12) DAYOFWEEK(0-6) Note 0=Sun and 7=Sun
#
#14,15 10 * * 0   /usr/bin/somecommmand  >/dev/null 2>&1
The sample “commented out command” will run at 10:14 and 10:15 every Sunday.  There will
be no “mail” sent to the user because of the “>/dev/null 2>&1″ entry.
$ crontab -l
The above will list all cron jobs. Or if you’re root
$ crontab -l -u
$ crontab -e -u
Reference “man 5 crontab”:
The time and date fields are:
field          allowed values
—–          ————–
minute         0-59
hour           0-23
day of month   1-31
month          1-12 (or names, see below)
day of week    0-7 (0 or 7 is Sun, or use names)
A field may be an asterisk (*), which always stands for “first-last”.
Ranges of numbers are allowed.  Ranges are two numbers separated with a
hyphen.   The  specified  range is inclusive.  For example, 8-11 for an
“hours” entry specifies execution at hours 8, 9, 10 and 11.
Lists are allowed.  A list is a set of numbers (or ranges) separated by
commas.  Examples: “1,2,5,9”, “0-4,8-12”.
Ranges can include “steps”, so “1-9/2″ is the same as “1,3,5,7,9″.
Note, you can run just every 5 minutes as follows:
*/5 * * * * /etc/mrtg/domrtg  >/dev/null 2>&1
To run jobs hourly,daily,weekly or monthly you can add shell scripts into the
appropriate directory:
/etc/cron.hourly/
/etc/cron.daily/
/etc/cron.weekly/
/etc/cron.monthly/
Note that the above are pre-configured schedules set in “/etc/crontab”, so
if you want, you can change the schedule. Below is my /etc/crontab:
$ cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly

Networking Commands

.dhclient eth0       active interface ‘eth0′ in dhcp mode
.ethtool eth0     show network statistics of eth0
.host www.example.com     lookup hostname to resolve name to ip address and viceversa
.hostname     show hostname of system
.ifconfig eth0     show configuration of an ethernet network card
.ifconfig eth0 192.168.1.1 netmask 255.255.255.0     configure IP Address
.ifconfig eth0 promisc     configure ‘eth0′ in promiscuous mode to gather packets (sniffing)
.ifdown eth0     disable an interface ‘eth0′
.ifup eth0     activate an interface ‘eth0′
.ip link show     show link status of all network interfaces
.iwconfig eth1     show wireless networks
.iwlist scan     wifi scanning to display the wireless connections available
.mii-tool eth0     show link status of ‘eth0′
.netstat -tup     show all active network connections and their PID
.netstat -tupl     show all network services listening on the system and their PID
.netstat -rn     show routing table alike “route -n”
.nslookup www.example.com     lookup hostname to resolve name to ip address and viceversa
.route -n     show routing table
.route add -net 0/0 gw IP_Gateway     configure default gateway
.route add -net 192.168.0.0 netmask 255.255.0.0 gw 192.168.1.1     configure static route to reach network ’192.168.0.0/16′
.route del 0/0 gw IP_gateway     remove static route
.echo “1″ > /proc/sys/net/ipv4/ip_forward     activate ip routing temporarily
.tcpdump tcp port 80     show all HTTP traffic
.whois www.example.com     lookup on Whois databas

Basic file compression utilities


Basic file compression utilities: (and file extensions)
· gzip (.gz): Also see zcat, gunzip, gznew, gzmore
compress: gzip file-name
decompress: gzip -d file-name.gz
· bzip2 (.bz2): Also see: bunzip2, bzcat, bzip2recover
compress: bzip2 file-name
decompress: bunzip2 file-name.bz2
· compress (.Z): (Adaptive Lempel-Ziv compression) Also see:
uncompress, zcat
compress: compress file-name
decompress: uncompress file-name.Z
(Provided by the RPM package ncompress)
· pack (.z): Also see: unpack
compress: pack file-name
decompress: unpack file-name.z
· zip (.zip): Compress files or groups of files. (R.P.Byrne
compression) Compatable with PC PKZIP files. Also see: unzip
compress: zip file-name
decompress: unzip file-name.zip

Booting a Windows OS using GRUB


Booting a MS Windows OS using GRUB is a quite simple process. However, we must follow some rules in order to succeed. The first and foremost rule is:
* Windows OS always wants to be installed on a first hard drive and first partition.
* if you have your windows installation on second hard drive you need to use grub’s map command to re-map first hardrive as seccond and vice versa
Grub’s Naming convetion
Grub starts its hard drive and partition numbering system from 0. This means that (hd0,0) refers to a first hard drive and first primary partition. Whereas, (hd2,2) refers to third hard drive and third primary partition. All extended partitions starts from number 4. Therefore, (hd1,5) refers to a second hardrive and second extended partition.
Booting a Windows OS with grub
In case you have indeed installed your MS Windows on a first hard drive and first partition the whole process is rather simple. Open up a Grub’s menu config file:
vi  /boot/grub/menu.lst
and add a following code into appropriate boot menu section :
title           Microsoft Windows XP Professional
root    (hd0,0)
makeactive
chainloader     +1
save file and run command:
# update-grub
and you are done.
* root: the root partition of your MS Windows installation
* title: title name as it will be displayed on grub’s boot menu
* makeactive: make this entry bootable
* chainloader: do not boot but let partition’s boot loader to boot instead
In case you have a MS Windows installation on a third hard drive, things are little bit more complicated. Here is a /boot/grub/menu.lst code for booting a MS Windows from a third hard drive and first partition.
title           Microsoft Windows XP Professional
rootnoverify    (hd2,0)
map             (hd0) (hd2)
map             (hd2) (hd0)
savedefault
makeactive
chainloader     +1
* rootnoverify: do not mount but execute another command
* map: this makes a third hard drive a first and first hard drive third
After you have updated /boot/grub/menu.lst run:
# update-grub

Red Hat Enterprise Linux 6


Filesystems
* The new default file system, ext4, is faster, more robust, and scales to 16TB.
* The Scalable File System Add-On contains the XFS file system, which scales to 100TB.
* The Resilient Storage Add-On includes the high availability, clustered GFS2 file system.
* NFSv4 is significantly improved over NFSv3, and is backwards compatible.
* Fuse allows filesystems to run in user space allowing testing and development on newer fused-based filesystems (such as cloud filesystems).
Installation, Updates, and Deployment
* Anaconda supports installation of a “minimal platform” as a specific server installation, or as a strategy for reducing the number of software packages to increase security.
* Red Hat Network and Red Hat Network Satellite continue to provide management, provisioning, and monitoring for large deployments.
* Installation options have been reorganized into “workload profiles” so that each system installation will provide the right software for specific tasks.
* Dracut, a replacement for mkinitrd, minimizes the impact of underlying hardware changes, is more maintainable, and makes it easier to support third party drivers.
* The new yum history command provides information about yum transactions, and supports undo and redo of selected operations.
* Yum and RPM offer significantly improved performance.
* RPM signatures use the Secure Hash Algorithm (SHA256) for data verification and authentication, improving security.
* Storage devices can be designated for encryption at installation time, protecting user and system data. Key escrow allows recovery of lost keys.
* Standards Based Linux Instrumentation for Manageability (SBLIM) manages systems using Web-Based Enterprise Management (WBEM).
Microsoft Windows Support
* Windows WHQL-certified drivers enable virtualized Windows systems, and allow Microsoft customers to receive technical support for virtualized instances of Windows Server
Kernel-Based Virtualization
* The KVM hypervisor is fully integrated into the kernel, so all Red Hat Enterprise Linux system improvements benefit the virtualized environment.
* The application environment is consistent for physical and virtual systems.
* Deployment flexibility, provided by the ability to easily move guests between hosts, allows administrators to consolidate resources onto fewer machines during quiet times, or free up hardware for maintenance downtime.
Leverages Kernel Features
* Hardware abstraction enables applications to move from physical to virtualized environments independently of the underlying hardware.
* Increased scalability of CPUs and memory provides more guests per server.
* Block storage benefits from selectable I/O schedulers and support for asynchronous I/O.
* Cgroups and related CPU, memory, and networking resource controls provide the ability to reduce resource contention and improve overall system performance.
* Reliability, Availability, and Serviceability (RAS) features (e.g., hot add of processors and memory, machine check handling, and recovery from previously fatal errors) minimize downtime.
* Multicast bridging includes the first release of IGMP snooping (in IPv4) to build intelligent packet routing and enhance network efficiency.
* CPU affinity assigns guests to specific CPUs.
Java
* OpenJDK 6 is an open source implementation of the Java Platform Standard Edition (SE) 6 specification. It is TCK-certified based on the IcedTea project, and the implementation of a Java Web Browser plugin and Java web start removes the need for proprietary plugins.
* Tight integration of OpenJDK and Red Hat Enterprise Linux includes support for Java probes in SystemTap to enable better debugging for Java.
* Tomcat 6 is an open source and best-of-breed application server running on the Java platform. With support for Java Servlets and Java Server Pages (JSP), Tomcat provides a robust environment for developing and deploying dynamic web applications.
NEW FEATURES
* OpenOffice 3 suite
* Email – (openchange MAPI client capability)
* NetworkManager – mobile network connection management
* Cisco IPSEC client compatibility
* Smart Card support
* Encrypted disk (luks)

DNS cofiguration


Domain Name System (DNS) provides the means by which the name of a website  is converted to an IP address. This is important as it is the IP address of a web site’s server, not the website’s name, that is used in routing traffic over the Internet.
BIND is an acronym for the “Berkeley Internet Name Domain” project which maintains the DNS related software suite that runs under Linux. The most well known program in BIND is “named”, the daemon that responds to DNS queries from remote machines.
A DNS client doesn’t store DNS information; it always has to refer to a DNS server to get it.The only DNS configuration file for a DNS client is the /etc/resolv.conf file which defines the IP address of the DNS server it should use. You shouldn’t need to configure any other files.
DNS servers are the servers that provide the definitive information for your DNS domain such as
the names of servers and websites in it.
There are thirteen “root” (super duper) authoritative DNS servers which all DNS servers query first. These servers know all the authoritative DNS servers for all the main domains such as .com”, “.net” etc. These servers keep track of all the sub domains beneath them. When you register a domain such as “my-site.com” you are actually inserting a record on the “.com” DNS servers that points to the authoritative DNS servers for your domain.
Configuration:
Packages : Bind*  ,  Caching*
Main Configuration file :  /etc/named/named.conf                 This is the main configuration file to be edited to tell where the farward and reverse lookup zones are present.
Other configuration files :       /var/named/localhost.zone     and /var/named/named.local                                                              These are the farward lookup and reverse lookup zones to be edited
Service/Daemon : named
The file /etc/resolv.conf is to be edited by giving the DNS setrver IP’s and Names.
To Check :     # dig
# dig -x < ip address>
ttl  : Time to Live
SOA : State of Authority
NS: Name Server
A : Address
@ : domain
PTR : Pointer
CNAME : Canonical name or Alias Name
MX : Mail Exchange
IN : Internet
Testing the clients:
Using nslookup to test client behaviour is obvious.