ABHIONLINUX
Site useful for linux administration and web hosting

2009/08/26

T=remote_smtp defer (-53): retry time not reached for any host

This can be caused by multiple things, however if it happens for each email, it's likely your exim databases are corrupt; to resolve this you should:

/usr/sbin/exim_tidydb -t 1d /var/spool/exim retry > /dev/null
/usr/sbin/exim_tidydb -t 1d /var/spool/exim reject > /dev/null
/usr/sbin/exim_tidydb -t 1d /var/spool/exim wait-remote_smtp > /dev/null

/scripts/courierup -- force
/scripts/eximup --force

2009/08/20

Hard disk monitoring using SMARTD

smartd is SMART Disk Monitoring Daemon for Linux. SMART is acronym for Self-Monitoring, Analysis and Reporting Technology (SMART) system built into many ATA-3 and later ATA, IDE and SCSI-3 hard drives. The purpose of SMART is to monitor the reliability of the hard drive and predict drive failures, and to carry out different types of drive self-tests.

smartd works with following operating systems:

1. Linux
2. *BSD
3. Windows
4. Solaris etc

How do I Install smartd?

However, smartd is not installed by default. Following are distribution specific steps to install smartd:

Debian Linux:

apt-get install smartmontools


Red hat/Fedora Linux:

rpm –ivh kernel-utils
OR
up2date kernel-utils
OR if you are using Fedora Linux
yum kernel-utils


FreeBSD:

pkg_add -r -v smartmontools

Before configuring hard disk for SMART monitoring make sure your hard disk is SMART capable:
smartctl -i /dev/hda

Output:

Code:
smartctl version 5.34 [i686-pc-linux-gnu] Copyright (C) 2002-5 Bruce Allen
Home page is http://smartmontools.sourceforge.net/

=== START OF INFORMATION SECTION ===
Device Model: SAMSUNG SV2002H
Serial Number: 0395J1FR904324
Firmware Version: RA100-04
User Capacity: 20,060,651,520 bytes
Device is: In smartctl database [for details use: -P show]
ATA Version is: 6
ATA Standard is: ATA/ATAPI-6 T13 1410D revision 1
Local Time is: Tue May 2 15:44:09 2006 IST

SMART support is: Available - device has SMART capability.
SMART support is: Enabled


You can configure the smartd daemon by editing the file /etc/smartd.conf.

In above output the lines:
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

Indicates that it is SMART capable and it is enabled.


Configure SMARTD

Debian Linux

* Enable smart by editing /etc/default/smartmontools file.
* Smart Configuration file: /etc/smartd.conf
* Start/Stop smart: /etc/init.d/smartmontools start | stop

Red Hat Linux

* Enable smart by editing /etc/smartd.conf file.
* Smart Configuration file: /etc/smartd.conf
* Start/Stop smart: /etc/init.d/smartd start | stop

FreeBSD

* Enable smart by editing /etc/rc.conf file (add line smartd_enable=”YES”).
* Smart Configuration file: /etc/smartd.conf
* Start/Stop smart: /usr/local/etc/rc.d/smartd.sh start | stop

Example

You can put following directives in Smart Configuration file:
(a) Send an email to alert@anishonweb.com for /dev/sdb:
/dev/sdb -m alert@anishonweb.com
(b) Read error log:
smartctl -l error /dev/hdb
(c) Testing hard disk (short or long test):
smartctl -t short /dev/hdb
smartctl -t long /dev/hdb

Caution smartd is a monitoring tool not a backup solution. Always perform data backup.

How to install CLAMAV

Steps
-----

groupadd clamav
useradd -c "CLAMAV Owner" -m -d /var/lib/clamav -g clamav -u 40 -s /bin/bash clamav


cd /var/lib/clamav
mkdir {bin,db,log,run,template,tmp}
chown -R clamav:clamav /var/lib/clamav
chmod 700 /var/lib/clamav

Download latest version from

http://www.clamav.net/download/sources

wget http://freshmeat.net/redir/clamav/29355/url_tgz/clamav-0.92.tar.gz

tar -xvzf clamav-0.92.tar.gz

./configure --prefix=/usr \
--sysconfdir=/etc \
--libexecdir=/usr/sbin \
--disable-clamuko \
--with-user=clamav \
--with-group=clamav \
--with-dbdir=/var/lib/clamav/db

make

make install

Configuration file

Now we have to create an init script for ClamAV (/etc/init.d/clamd):

--------------------------------------------------------------------------
#!/bin/bash


TMPDIR=/tmp
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/X11R6/bin


case "$1" in
start)
echo "Starting ClamAV..."
if [ -S /tmp/clamd ]; then
echo "ClamAV is already running!"
else
/usr/local/bin/freshclam -d -c 10 --datadir=/usr/local/share/clamav
/usr/local/sbin/clamd
fi
echo "ClamAV is now up and running!"
;;
stop)
echo "Shutting down ClamAV..."
array=(`ps ax | grep -iw '/usr/local/bin/freshclam' | grep -iv 'grep' \
| awk '{print $1}' | cut -f1 -d/ | tr '\n' ' '`)
element_count=${#array[@]}
index=0
while [ "$index" -lt "$element_count" ]
do
kill -9 ${array[$index]}
let "index = $index + 1"
done
array=(`ps ax | grep -iw '/usr/local/sbin/clamd' | grep -iv 'grep' \
| awk '{print $1}' | cut -f1 -d/ | tr '\n' ' '`)
element_count=${#array[@]}
index=0
while [ "$index" -lt "$element_count" ]
do
kill -9 ${array[$index]}
let "index = $index + 1"
done
if [ -S /tmp/clamd ]; then
rm -f /tmp/clamd
fi
echo "ClamAV stopped!"
;;
restart)
$0 stop && sleep 3
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit 0
------------------------------------------------

chmod 755 /etc/init.d/clamd

Now we start ClamAV:

/etc/init.d/clamd start

If you run

ps aux (which use the socket /tmp/clamd) and a freshclam process which is responsible for getting the newest virus signature updates. They are located under /usr/local/share/clamav. The command

/usr/local/bin/freshclam -d -c 10 --datadir=/usr/local/share/clamav

in our clamd init script makes sure that freshclam checks for new signatures 10 times per day.

In order to start ClamAV at boot time do the following:

ln -s /etc/init.d/clamd /etc/rc2.d/S20clamd
ln -s /etc/init.d/clamd /etc/rc3.d/S20clamd
ln -s /etc/init.d/clamd /etc/rc4.d/S20clamd
ln -s /etc/init.d/clamd /etc/rc5.d/S20clamd
ln -s /etc/init.d/clamd /etc/rc0.d/K20clamd
ln -s /etc/init.d/clamd /etc/rc1.d/K20clamd
ln -s /etc/init.d/clamd /etc/rc6.d/K20clamd

/etc/init.d/clamd start

you will now notice some clamd processesRun it using /scripts/restartsrv_clamav

now you will get an error message:

ERROR: Please edit the example config file /etc/clamav.conf.

You must at least remove the Example directive. My /etc/d.conf

Enable and Disble PING

To disable ping

echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all

To enable ping
echo 0 > /proc/sys/net/ipv4/icmp_echo_ignore_all

Awstats

Accessing Awstats from outside the control panel is easy.
Step 1.
Download awstats from http://awstats.sourceforge.net

Step 2.
Uncompress awstats-5.6.tgz

Step 3.
Copy the contents of the uncompressed cgi-bin folder from your hard drive to the user cgi-bin directory (this includes awstats.pl, awstats.model.conf, and the lang, lib and plugins sub-directories).

Step 4.
If necessary (should not be needed with most setups), edit the first (top-most) line of awstats.pl file that is
#!/usr/bin/perl
to reflect the path were your Perl interpreter is installed. Default value works for most of Unix OS, but it also might be #!/usr/local/bin/perl

Step 5.
Move AWStats icon sub-directories and its content into a directory readable by your web server, for example /home/users/public_html/icons

Step 6.
Copy awstats.model.conf file into a new file named awstats.myvirtualhostname.conf. This new file must be stored in /home/user/public_html/cgi-bin.

Step 7.
Edit this new config file with your own setup :
- Change LogFile value with full path of your web server log file (The path is: LogFile="/usr/local/apache/domlogs/domain.com").
- Check if LogFormat has the value "1" (it means "NCSA apache combined/ELF/XLF log format").
- Change DirIcons parameter to reflect relative path of icon directory. (DirIcons="/icons")
- Edit SiteDomain parameter with the main domain name or the intranet web server name used to reach the web site to analyze (Example: www.mydomain.com).
IMPORTANT!
- Change DirData to use the same Statics file than Cpanel Awstats and do not loose any entry.
(DirData="/home/user/tmp/awstats/")

Step 8.
Access AwStats by the URL:
www.domain.com/cgi-bin/awstats.pl?config=domain.com
That's all!!!
The AwStats will refresh the Statics every 24 Hours.

How to block an IP using IPTABLES

To block a range of IPs :

iptables -A INPUT -p tcp --destination-port 80 -m iprange --src-range 192.168.0.0-192.168.0.255 -j DROP

Forcing fsck on reboot

Inorder to force fsck on reboot give the following command

shutdown -rF now

Another way is just touch a file called .autofsck on / and reboot (Usually that file will be there by default.)

.htaccess rule to prevent iframe attack

RewriteCond %{QUERY_STRING} ^.*(;||'|"|\)|%0A|%0D|%22|%27|%3C|%3E|).*(/\*|union|select|insert|cast|set|declare|drop|update|md5|benchmark).* [NC]
RewriteRule .* - [F]

Setting timezone using .htaccess

You may need to show the time in your website, but the server time zone may not match with your time zone. In this case, you can set your time zone by editing .htaccess file.

Open your .htaccess file and add the rule “SetEnv TZ location”

‘location’ is the specific timezone you want to set.

You can select your time zone from the list.
http://www.php.net/manual/en/timezones.php

2009/08/17

Cpanel Scripts

Cpanel Scripts
cPanel has a large number of predefined scripts available in the /scripts folder. The available scripts are as follows:

If you do not know the significance of the script then please check with the seniors for more help.

adddns - Adds a DNS zone.
addfpmail - Add frontpage mail extensions to all domains without them.
addfpmail2 -Add frontpage mail extensions to all domains without them.
addnetmaskips - Add the netmask 255.255.255.0 to all IPs that have no netmask.
addnobodygrp - Adds the gorup nobody and activates security.
addpop - Add a Pop Account.
addservlets - Add JSP support to an account (requires tomcat).
addstatus - (Internal use never called by user).
adduser - Add a user to the system.
admin - Run WHM Lite.
apachelimits - Add rlimits to Apache.
bandwidth - (OLD)
betaexim - Installs the latest version of exim.
biglogcheck - looks for logs nearing 2 gigabytes in size
bitstest -
bsdcryptoinstall - Installs crypto on FreeBSD.
bsdldconfig - Configures the proper lib directories in FreeBSD.
bsdpkgpingtest - Tests the connection speed for downloading FreeBSD packages.
buildbsdexpect - Install expect on FreeBSD.
builddomainaddr - (OLD)
buildeximconf - Rebuilds exim.conf.
buildpostgrebsd-dev - Installs postgresql on FreeBSD.
buildpureftproot -
bupcp - (OLD)
chcpass - (Internal use)
checkallowoverride -
checkbadconf - Checks /usr/local/apache/conf/httpd.conf for bad users.
checkbashshell -
checkbsdgroups - Checks and repairs proftpd ownership on FreeBSD.
checkccompiler - Checks to make sure the C compiler works on your system.
checkdeadperlso -
checkerrorlogsafe -
checkfpkey - Checks for the FrontPage suid key
checkgd - Checks to see if GD is built.
checkgentoousers -
checkhttpd -
checkinterchange - (Internal use).
checklibssl - Checks to make sure the proper libssl symlinks exist.
checklink -
checklog - (OLD)
checkmakeconf -
checkmaxclients - Checks to see if apache has reached the maximum clients allowed.
checkoldperl - Checks to see if the version of Perl on your system is old.
checkoldrpm -
checkrsync - Checks to make sure rsync is up to date.
checksuexecpatch - Checks to see if mailman has been patched for suexec.
checksuspendpages - Checks to see if suspend pages are properly named.
checkswup - (OLD)
checkup2date - Makes sure up2date is set up properly (RedHat)
checkyum - Makes sure yum is set up properly.
chkpaths - Makes sure /usr/sbin/chown has a symlink to /bin/chown
chownpublichtmls - Change ownership of all users web space to them, which is useful for converting to suexec. Files owned by nobody are deleted.
chpass - Change password.
ckillall - Allows you to kill a process (used like killall).
ckillall2 - Allows you to kill a process.
cleanandmailformmaillog -
cleanbw - Cleans up old bandwidth logs.
cleandns - (OLD)
cleandns8 - Clean up named.conf.
cleangd - Cleans up old GD installs and reinstalls GD
cleanmd5 - Fix CPAN md5 problems.
cleanmsglog - cleans exim's msglog
cleanopenwebmail - (OLD)
cleanupcheck -
cleanupmysqlprivs - Cleans up improper mySQL privileges.
compilers - Disables the usage of compilers for unprivileged users.
configips - (OLD)
*.cgi - (INTERNAL)
*.c - (INTERNAL)
convert2maildir - Converts mail from mbox to maildir format and installs courier impap and pop (cpimap is removed).
convertemails -
convertemails2 - (INTERNAL)
convertemails5 - (INTERNAL)
courierup - Updates/Installs Courier
cpanelsync -
cpbackup - Runs backups.
cpbackup2 - (INTERNAL)
cptheme - (NOT USED)
dialog* - (NOT USED)
distupgrade - Upgrades RedHat to the newest version (for testing only)
dnscluster - Enables DNS clustering.
dnsqueuecron - Adds a cron job to dump the DNS queue.
dns_setup - (OLD)
dnstransfer - Only if the server has a DNS master (sync with DNS
master).
doomhttpd -
dotbuffer - (INTERNAL)
downgradefp - Downgrades FrontPage Extensions (to 5.0-0)
dropmysqldb - Drops a mySQL database.
easyapache - Upgrade Apache
editquota - Change a users quota.
enablechkservdwebmail - Enable service checking of webmaild.
enablefileprotect - Protects home directories if file protection is built in apache.
ensurepkg - Installs a FreeBSD package.
ensurerpm - Installs a rpm.
ensurerpm2 - (INTERNAL)
exchangeacctdb - (OLD)
exim3 - Installs exim 3.
exim4 - Installs exim 4.
exim4-rh73test - Installs exim release #260. (RedHat only)
eximcron - Creates a cron job for exim_tidy_db.
eximlocalsend - Enables/Disables exim local sending.
exim_tidydb - Cleans the exim message log.
eximup - Installs/Updates exim.
eximup~ - (INTERNAL)
expectperlinstaller - (INTERNAL)
fetchfile - (INTERNAL)
fetchfpexec -
fetchgd - Includes libg.so.
finddev - (INTERNAL)
findhacks - Search for common Trojan Horses.
findoddrootprocesses - Lists root processes that may need to be checked out.
findphpversion - Check to see if your php version file is up to date.
findtrojans - Exhaustive Trojan Horse search.
fixadmin - (OLD)
fixallcartswithsuexec - Fixes permissions on carts when using suexec.
fixallinterchangeperm - Fixes permissions on all users'
Interchange Shopping Carts.
fixbinpath - Makes sure all bin file paths are correct.
fixbuggynamed - Updates bind to solve any problems with bugs.
fixcartwithsuexec - (INTERNAL) - Can be used to fix a cart with suexec.
fixcgiwrap - (OLD)
fixcommonproblems - Attempt to fix the most common problems.
fixetchosts - Fixes problems with /etc/hosts
fixeverything - Fix common problems and quotas.
fixfpwml - Fix for .wml errors with frontpage.
fixheaders - Run if nothing compiles errors with .h files on compile.
fixhome - (NOT USED) - Unsymlink items.
fixinterchange - Reinstall interchange Perl modules.
fixinterchangeperm - fix permissions on a user's interchange cart.
fixipsnm - Same as addnetmask ips, but Perl though.
fixlibnet - Reinstall Bundle::libnet (Perl).
fixlocalhostwithphp - Change /etc/hosts to work better with PHP 4.2.0 + MySQL.
fixmailandakopia - (NOT USED)
fixmailman - Updates and restarts mailman.
fixmailmanwithsuexec -
fixmuse - Reinstalls muse.
fixmysql - Fixes problems with mySQL.
fixmysqlbsd - Fixes problesm with mySQL on FreeBSD.
fixnamed - Updates bind to handle many DNS zones (more than 512).
fixndc - Repair redhat's broken named.conf on 7.2.
fixndc.new - (INTERNAL)
fixoldlistswithsuexec - Run after enabling suexec on the server to change the URLs that Mailman gives out to ones that don't give a 500 internal server error.
fixperl - Symlink /usr/local/bin/perl /usr/bin/perl.
fixperlscript - Makes sure a perlscript includes all corresponding modules.
fixpop - Fix a POP account and reset password.
fixproftpdconf - Fixes problems with /usr/local/etc/proftpd.conf
fixproftpdconf~ - (INTERNAL)
fixproftpddupes - Updates proftpd.
fixquotas - Fix quotas.
fixrelayd - (OLD)
fixrh72ndckey - (INTERNAL)
fixrndc - Fixes named.conf to prevent rndc staus failed.
fixspamassassinfailedupdate - Reinstalls a failed spamassassin update.
fixsubconf -
fixsubdomainlogs - Run if subdomain logs don't show up in cPanel.
fixsuexeccgiscripts - Fix CGI scripts that are broken after suexec
installed.
fixtrojans - (NOT USED)
fixvaliases - Fix permisions on valiases.
fixwebalizer - Repair a Webalizer that has stopped updating.
fixwebmail - (OLD)
fixwwwdir - (OLD)
fp3 - Updates the fpexe3 patch.
fpanonuserpatch - Updates FrontPage extensions to include the anonymous user patch.
fp-auth -
fpbtr - (OLD)
fpsuexec - (INTERNAL)
fpsuexec2 - (INTERNAL)
fpsuexec3 - (INTERNAL)
fpupgrade - (INTERNAL)
ftpcheck - Checks for FTPSSL.
ftpfetch - (INTERNAL)
ftpput - (INTERNAL)
ftpquaotacheck - Runs quota checking for all ftp users.
ftpsfetch - (INTERNAL)
ftpup - Updates your ftp server.
ftpupdate - (INTERNAL)
fullhordereset - Resets Horde and displays the current Horde password.
futexfix - Fixes problesm with futex.
futexstartup - Starts futex.
gcc3 - Installs gcc-3.3.3
gencrt - Generate a .crt and .csr file.
gencrt2 - (NOT USED)
gentomcatlist - (INTERNAL)
gentooportsup -
gethomedir - (INTERNAL)
getpasswd - (INTERNAL)
getremotecpmove - (INTERNAL)
getrpmfor -
grabemails - (INTERNAL)
grabhttp - (INTERNAL)
grabhttp2 - (INTERNAL)
grabmysqlprivs - (INTERNAL)
grpck - Checks to see if grpck is working properly.
hackcheck - (INTERNAL)
hdparmify - Enable dma/irq/32bit HD access, which speeds up IDE drives.
hdparmon - Turns on hdparm.
HTTPreq.pm - (INTERNAL)
httpspamdetect -
icpanel - (OLD)
initacls - Mounts your file systems with ACL support (make sure your kernel supports ACLs)
initbyteslog - (INTERNAL)
initfpsuexec - Enable FrontPage suexec support.
initquotas - Turn on quota support on new drives.
initsslhttpd - Make sure HTTP starts with SSL.
initsuexec - Turn on suexec support if suexec is installed.
installaimicq - (INTERNAL)
installcgipm - Installs CGI.pm
installcpbsdpkg -
installcpgentoopkg -
installdbi - Install Bundle:BD::mysql.
installfpfreebsd - Installs FrontPage 5 Extensions on FreeBSD.
installfpgentoo - Installs FrontPage on Gentoo.
installgd - Builds GD.
installipc - (INTERNAL)
installpkg - Installs a FreeBSD package.
installpostgres - Installs PostrgeSQL.
installrmmods - (OLD)
installrpm - Installs a rpm.
installrpm2 - (INTERNAL)
installspam - Install SpamAssassin.
installssl - Add a SSL vhost.
installtree -
installzendopt - Install zend optimzer.
installzendopt-freebsd - Install zend optimizer on a freebsd machine.
ipcheck - (INTERNAL)
ipusage - (INTERNAL)
isdedicatedip - Checks an ip to see if it is dedicated.
kernelcheck - (INTERNAL)
killacct - Delete an account.
killbadrpms - Security script that kills insecure RPMs from the server.
killdns - Delete a DNS zone.
killdns-dnsadmin -
killdrrootvhost - Removes the document root for a virtual host.
killndbm - Remove the broken NDBM_File module from 7.2.
killpvhost - Removes a virtual host from proftpd.conf.
killspamkeys - Removes a spam key.
killsslvhost - Removes a SSL entry for a virtual host.
killvhost - Delete a vhost.
listcheck - Checks mailing lists for issues.
listproblems - Lists common problems.
listsubdomains - List subdomains.
mailadmin - (DEAD, OLD)
maildirmenu - (INTERNAL)
mailman212 - (INTERNAL)
mailperm - Fix almost any mail permission problem.
mailscannerupdate - Updates MailScanner
mailtroubleshoot - Guided mail fix.
makecpphp - Installs php.
makesecondary - Part of DNS transfer.
manualupcp - Updates cPanel manually.
md5crypt - Encrypts a password into MD5.
mkquotas - OLD
mkwwwacctconf - (INTERNAL)
mrusersscpcmd -
mseclocal - Sets up Mandrake's msec to allow exim to run as mailnull.
mysqladduserdb - Create a MySQL databse and user.
mysqlconnectioncheck - Attempts to connect to MySQL, restarts SQL if necessary.
mysqldeluserdb - Delete a MySQL databse and user.
mysqlinfo - (OLD)
mysqlpasswd - Change MySQL password.
mysqlrpmpingtest - Checks your connection speed for downloading
mySQL rpms.
mysqlup - Updates mySQL.
mysqlup~ - (INTERNAL)
ndbmcheck - Checks to see if the nbdm module is loaded (kills in RedHat 7.2)
netftpsslpatch - PAtches FTPSSL.pm.
newdomains - (OLD)
newdomains-sendmail - (OLD)
newexim - Installs the latest version of exim.
newftpuser - (NOT USED)
newpop - (NOT USED)
nofsck - Make fsck always use -y
nomodattach - Removes mod_attach from httpd.conf.
nomodauthmysql -Removes mod_auth_mysql from httpd.conf.
nomodbwprotect - Removes mod_bwportect from httpd.conf.
nomodgzipconfmods - Removes mod_gzip from httpd.conf.
nomodperl - Removes mod_perl from httpd.conf.
oldaddoncgi2xaddon - Updates old addons to X addons.
oldaddonconverter-(INTERNAL)
oopcheck - (INTERNAL)
park - Parks a domain.
patcheximconf - Fixes exim.conf.
patchposixtypes -
patchtypes -
patchtypesizes -
pedquota - (INTERNAL) - Part of editquota (for editting quota).
perlinstaller - Installs perl.
phpini - Create a php.ini file.
phpopenbasectl -
pingtest - Checks your download time from cPanel mirrors.
pkgacct - (INTERNAL)
pkgacct~ -(INTERNAL)
pkgacct2 - (INTERNAL)
pkgaccount-ala - backs up an Alab*nza account for transfer.
pkgacct-ciXost - backs up a ci*ost account for transfer.
pkgacct-dXm - backs up a d*m account for transfer.
pkgacct-enXim - backs up an en*im account for transfer.
pkgacct-ng -
pkgacctn-ng.orig -
pkgacct-pXa - backs up a p*a account for transfer.
popftpuse - (OLD)
portsup - (FREEBSD BETA)
postsuexecinstall - (INTERNAL)
proftpd128 - Installs proftpd-1.2.8.
pscan - (OLD)
ptycheck - Fixes permissoins on /dev/ptmx.
pwck -Verifies the integrity of system authentication information.
quickfixmysqlbsd - (NOT USED)
quickkernel - Updates your kernel.
quicksecure - Quickly kill useless services.
quotacheck - (INTERNAL)
rasetup - (OLD)
rawchpass - (INTERNAL)
realadduser - (INTERNAL)
realchpass - (INTERNAL)
realperlinstaller - (INTERNAL)
realrawchpass - (INTERNAL)
rebuildcpanelsslcrt - Rebuilds the cPanel SSL Certificate.
rebuildcpusers - Rebuilds /var/cpanel/users.
rebuildetcpasswd - Rebuilds /etc/passwd.
rebuildeximbsd - Rebuilds exim on FreeBSD.
rebuildhttpdconffromproftpd - Rebuild httpd.conf from the proftpd.conf file.
rebuildinterchangecfg - Used after moving a domain with Interchange to the server.
rebuildippool - (INTERNAL)
rebuildnamedconf - Restore named.conf from files in /var/named.
rebuildproftpd - Restore proftpd.conf from httpd.conf.
reinstallmailman - Reinstalls mailman.
relocatevartousr - Relocates files from /var to /usr in case of disk space issues.
remdefssl - Remove default SSL vhost.
reseteximtodefaults - Resets exim's default settings.
resethorde -
resetimappasswds - Resets all imap passwords.
resetmailmanurls -
resetquotas - Change quotas to what they should be .
restartsrv - Restart a service.
restartsrv_apache - Restart apache.
restartsrv_bind - Restart bind.
restartsrv_clamd - Restart clamd.
restartsrv_courier - Restart courier imap.
restartsrv_cppop - Restart cppop.
restartsrv_entropychat - Restart entropy chat.
restartsrv_exim - Restart exim.
restartsrv_eximstats - Restart exim statistics.
restartsrv_ftpserver - Restart your ftp server.
restartsrv_ftpserver~ - (INTERNAL)
restartsrv_httpd - Restart httpd.
restartsrv_imap - Restart impad.
restartsrv_inetd - Restart inetd.
restartsrv_interchange - Restart Interchange Shopping Cart.
restartsrv_melange - Restart melange chat.
restartsrv_mysql - Restart mysqld.
restartsrv_named - Restart named.
restartsrv_postgres - Restart postgresql.
restartsrv_postgresql - Restart postgresql.
restartsrv_proftpd - Restart proftpd.
restartsrv_pureftpd - Restart pure-ftpd.
restartsrv_spamd - Restart spamd.
restartsrv_sshd - Restart sshd.
restartsrv_syslogd - Restart syslogd.
restartsrv_tomcat - Restart tomcat.
restartsrv_xinetd - Restart xinetd.
restoremail - Restores a user's mail.
restorepkg -
reswhostmgr - Restart whostmgr.
rhlupdate - (OLD)
rpmpreinstall - (INTERNAL)
rpmup - Upgrade redhat/mandrake errata/security.
rpmup2 - (INTERNAL)
rpmup3 - (INTERNAL)
rrdtoolinstall - Installs RRD Tool.
rscpmd -
runlogsnow - (OLD)
runstatsonce - Runs statistics (should be used from the crontab).
runweblogs - Run analog/webalizer/etc. for a user.
ruserssscpcmd - (INTERNAL)
safeperlinstaller - Installs perl safely.
safeup2date - Runs up2date safely.
safeyum - Runs yum safely.
scpcmd - (INTERNAL)
searchbadgroups -
searchreplace - (NOT USED)
secureit - Remove unnecessary suid binaries.
securemysql - Attempts to secure the MySQL configuration.
securetmp - Adds securetmp to system startup.
selinux_custom_contexts -
selinuxsetup -
sendaim - (INTERNAL)
sendicq - (INTERNAL)
setupfp - Install FrontPage 3 on an account.
setupfp4 - Install FrontPage 4 (2000) installer on an account.
setupfp5 - Install FrontPage 5 (2002) installer on an account.
setupfp5.nosueuxec - Install FrontPage 5 (2002) installer on an account when not using suexec.
setupmakeconf -
showexelist - Shows exe processes.
simpleps - Display the process list.
simplesshcmd - (INTERNAL)
smartcheck - Checks hard drive integrity.
smtpmailgdionly - Enables SMTP Mail Protection.
snarf - (INTERNAL)
spamasssassin-cpanel - (NOT USED)
spamboxdisable - Disables SpamAssassin's spambox delivery for all accounts.
sscpcmd - (INTERNAL)
ssh2.expect - (INTERNAL)
sshcmd -
sshcontrol - (INTERNAL)
ssh.expect - (INTERNAL)
stage2fpmail - (INTERNAL)
supportvoidcheck -
suspendacct - Suspends an account.
symlinktodir - (INTERNAL)
sysup - update cPanel RPMs.
telentcrt - (OLD)
testinf - (OLD)
trustme - (INTERNAL)
typocheck -
uf - (OLD)
unlimitnamed - Installs the latest version of bind patched to support greater than 512 ips on the server.
unblockip - Unblocks an IP blocked by portsentry.
unpkgacct - (INTERNAL)
unsetupfp4 - Removes FrontPage 4 or 5 from an account.
unslavenamedconf - If the user accidentally sets a DNS master as local server, this will repair named.conf after the loop.
unsuspendacct - Unsuspends an account.
upcp - Updates cPanel.
updated - Updates /scripts.
updatedomainips - (INTERNAL)
updatefrontpage - Updates FrontPage
updatemysqlquota -
updatenow - Updates /scripts NOW.
updatephpconf - Updates PHP configuration files.
updateuserdomains - (INTERNAL)
updateuserdomains2 - (INTERNAL)
userdirctl -
userps - (OLD)
usersscpcmd - (INTERNAL)
usersscpcmd1 - (INTERNAL)
usersshcmd - (INTERNAL)
verify - (OLD)
verifyzone - (INTERNAL)
whichrpm - (INTERNAL)
whoowns - Finds out who owns a domain.
whostmgrkey - (OLD)
wwwacct - Creates an account.
wwwacct2 - (INTERNAL)
x* - (OLD)
xaddonreport - Reports the current addon scripts installed.
zoneexists - (INTERNAL)

URL redirect

RewriteEngine OnOptions +FollowSymlinksRewriteCond %{HTTP_HOST} domain.com$ RewriteCond %{REQUEST_URI} !folder/RewriteRule ^(.*)$ folder/$1

2009/08/16

How could I know list of the new features available for each kernel?

rpm -qp --changelog kernel-2.6.9-1.860_EL.i686.rpm | more

Disk usage report

To view the disk usage of all directories one level down is

du -hx --max-depth=1

Locating files using the find command

Find is a versatile tool which can be used to locate files and directories satisfying different user criteria. But the sheer number of options for this command line tool makes it at the same time both powerful and encumbering for the user. Here I will list a few combinations which one can use to get useful results using find command.

Find all HTML files starting with letter 'a' in your current directory (Case sensitive)
find . -name a\*.html

Same as above but case insensitive search.
find . -iname a\*.html

Find files which are larger than 5 MB in size.
find . -size +5000k -type f

Here the '+' in '+5000k' indicates greater than and k is kilobytes. And the dot '.' indicates the current directory. The -type option can take any of the following values:

f - file
d - directory
l - symbolic link
c - character
p - named pipe (FIFO)
s - socket
b - block device

Find all empty files in your directory
find . -size 0c -type f

... Which is all files with 0 bytes size. The option -size can take the following:


c - bytes
w - 2 byte words
k - kilo bytes
b - 512 byte blocks


Note: The above command can also take the -empty parameter.

Find is very powerful in that you can combine it with other commands. For example, to find all empty files in the current directory and delete them, do the following:
find . -empty -maxdepth 1 -exec rm {} \;

To search for a html file having the text 'Web sites' in it, you can combine find with grep as follows:
find . -type f -iname \*.html -exec grep -s "Web sites" {} \;

... the -s option in grep suppresses errors about non-existent or unreadable files. And {} is a placeholder for the files found. The semicolon ';' is escaped using backslash so as not to be interpreted by bash shell.

Note: You can use the -exec option to combine any command in Linux with the find command. Some of the useful things you can do with it are as follows:

Compress log files on an individual basis
find /var -iname \*.log -exec bzip {} \;

Find all files which belong to user lal and change its ownership to ravi
find / -user lal -exec chown ravi {} \;

Note: You can also use xargs command instead of the -exec option as follows:
find /var -iname \*.log | xargs bzip -

Find all files which do not belong to any user:
find . -nouser

Find files which have permissions rwx for user and rw for group and others :
find . -perm 766

... and then list them.

find . -perm 766 -exec ls -l {} \;

Find all directories with name music_files
find . -type d -iname \*music_files\*

Suppose you want to find files of size between 700k and 1000k, do the following:
find . \( -size +700k -and -size -1000k \)

And how about getting a formatted output of the above command with the size of each file listed ?
find . \( -size +700k -and -size -1000k \) -exec du -Hs {} \; 2>/dev/null

... here, the '2>/dev/null' means all the error messages are discarded or suppressed.

You can also limit your search by file system type. For example, to restrict search to files residing only in the NTFS and VFAT filesystem, do the following:
find / -maxdepth 2 \( -fstype vfat -or -fstype ntfs \) 2> /dev/null

These are the most common uses of the find command. You can see additional uses by reading the find manual.

File /Folder Permissions

These are the numeric values and its related permissions in a linux system.

4000 - Setuid on execution
2000 - setgid on execution
1000 - set sticky bit
0400 - read by owner
0200 - write by owner
0100 - execute by owner
0040 - read by group
0020 - wrrite by group
0010 - execute by group
0004 - read by others
0002 - write by others
0001 - execute by others

The chmod numeric value varies from 0000 to 7777

You can use these or combination of these numeric values with chmod command or you can specify it with strings. While specifying with strings use the following arguments..
u - user - to add/remove permissions of user or owner of file.
g - group - to add/remove permissions of group members of file.
o - other - to add/remove permissions of other group members or world wide permission of file.

Eg:
The following commands will enable the setuid on the file abc.pl
chmod 4755 abc.pl
chmod u+s abc.pl

Changing permissions recursively

Changing permissions recursively

For changing the permissions of all the sub directories, please use the following

find . -type d -exec chmod 755 {} \;

For changing the permissions of all the sub directories, please use the following

find . -type f -exec chmod 644 {} \;

Kill processes for user

To easily kill all processes running under a user

ps -u USER | awk ‘{print $1}’ | xargs kill -9

or

pkill -u USER

replacing USER with the username.

To kill all specific processes such as php running under a user run,

ps -u USER | grep PROCESS |awk ‘{print $1}’ | xargs kill -9

replacing USER with username and PROCESS with php or any other process.

Hide Commands in Shell

To hide the commands you are entering in shell, use "stty" command :)

#stty -echo

Now, all commands that you type are invisible.
To disable this mode, issue the following command at the shell prompt:

#stty echo

Windows run commands

Windows Run Commands

Start Menu >> Run

Accessibility Controls - access.cpl
Add Hardware Wizard - hdwwiz.cpl
Add/Remove Programs - appwiz.cpl
Administrative Tools - control admintools
Automatic Updates - wuaucpl.cpl
Bluetooth Transfer Wizard - fsquirt
Calculator - calc
Certificate Manager - certmgr.msc
Character Map - charmap
Check Disk Utility - chkdsk
Clipboard Viewer - clipbrd
Command Prompt - cmd
Component Services - dcomcnfg
Computer Management - compmgmt.msc
Date and Time Properties - timedate.cpl
DDE Shares - ddeshare
Device Manager - devmgmt.msc
Direct X Control Panel (If Installed)* - directx.cpl
Direct X Troubleshooter - dxdiag
Disk Cleanup Utility - cleanmgr
Disk Defragment - dfrg.msc
Disk Management - diskmgmt.msc
Disk Partition Manager - diskpart
Display Properties - control desktop
Display Properties - desk.cpl
Display Properties (w/Appearance Tab Preselected) - control color
Dr. Watson System Troubleshooting Utility - drwtsn32
Driver Verifier Utility - verifier
Event Viewer - eventvwr.msc
File Signature Verification Tool - sigverif
Findfast - findfast.cpl
Folders Properties - control folders
Fonts - control fonts
Fonts Folder - fonts
Free Cell Card Game - freecell
Game Controllers - joy.cpl
Group Policy Editor (XP Prof) - gpedit.msc
Hearts Card Game - mshearts
Iexpress Wizard - iexpress
Indexing Service - ciadv.msc
Internet Properties - inetcpl.cpl
IP Configuration (Display Connection Configuration) - ipconfig /all
IP Configuration (Display DNS Cache Contents) - ipconfig /displaydns
IP Configuration (Delete DNS Cache Contents) - ipconfig /flushdns
IP Configuration (Release All Connections) - ipconfig /release
IP Configuration (Renew All Connections) - ipconfig /renew
IP Configuration (Refreshes DHCP & Re - Registers DNS) - ipconfig /registerdns
IP Configuration (Display DHCP Class ID) - ipconfig /showclassid
IP Configuration (Modifies DHCP Class ID) - ipconfig /setclassid
Java Control Panel (If Installed) - jpicpl32.cpl
Java Control Panel (If Installed) - javaws
Keyboard Properties - control keyboard
Local Security Settings - secpol.msc
Local Users and Groups - lusrmgr.msc
Logs You Out Of Windows - logoff
Microsoft Chat - winchat
Minesweeper Game - winmine
Mouse Properties - control mouse
Mouse Properties - main.cpl
Network Connections - control netconnections
Network Connections - ncpa.cpl
Network Setup Wizard - netsetup.cpl
Notepad - notepad
Nview Desktop Manager (If Installed) - nvtuicpl.cpl
Object Packager - packager
ODBC Data Source Administrator - odbccp32.cpl
On Screen Keyboard - osk
Opens AC3 Filter (If Installed) - ac3filter.cpl
Password Properties - password.cpl
Performance Monitor - perfmon.msc
Performance Monitor - perfmon
Phone and Modem Options - telephon.cpl
Power Configuration - powercfg.cpl
Printers and Faxes - control printers
Printers Folder - printers
Private Character Editor - eudcedit
Quicktime (If Installed) - QuickTime.cpl
Regional Settings - intl.cpl
Registry Editor - regedit
Registry Editor - regedit32
Remote Desktop - mstsc
Removable Storage - ntmsmgr.msc
Removable Storage Operator Requests - ntmsoprq.msc
Resultant Set of Policy (XP Prof) - rsop.msc
Scanners and Cameras - sticpl.cpl
Scheduled Tasks - control schedtasks
Security Center - wscui.cpl
Services - services.msc
Shared Folders - fsmgmt.msc
Shuts Down Windows - shutdown
Sounds and Audio - mmsys.cpl
Spider Solitare Card Game - spider
SQL Client Configuration - cliconfg
System Configuration Editor - sysedit
System Configuration Utility - msconfig
System File Checker Utility (Scan Immediately) - sfc /scannow
System File Checker Utility (Scan Once At Next Boot) - sfc /scanonce
System File Checker Utility (Scan On Every Boot) - sfc /scanboot
System File Checker Utility (Return to Default Setting) - sfc /revert
System File Checker Utility (Purge File Cache) - sfc /purgecache
System File Checker Utility (Set Cache Size to size x) - sfc /cachesize=x
System Properties - sysdm.cpl
Task Manager - taskmgr
Telnet Client - telnet
User Account Management - nusrmgr.cpl
Utility Manager - utilman
Windows Firewall - firewall.cpl
Windows Magnifier - magnify
Windows Management Infrastructure - wmimgmt.msc
Windows System Security Tool - syskey
Windows Update Launches - wupdmgr
Windows XP Tour Wizard - tourstart
Wordpad - write

How to make remote backup between your server and your remote server

To run a regular interactive FTP session.

lftp -u 'username,password' backupspace.remoteserver.com

To backup one or more files:

lftp -u 'username,password' backupspace.remoteserver.com -e "set ftp:ssl-protect-data true; mput local/dir/files* /remotedir; exit"

You need to set ftp:ssl-protect-data else you will not be able to store the file. If you want to make this a default option, add it to the lftp.conf file. e.g:

grep -qai "set ftp:ssl-protect-data true" /etc/lftp.conf || echo "set ftp:ssl-protect-data true" >> etc/lftp.conf

To restore a file from the FTP server to your server:

lftp -u 'username,password' backupspace.remoteserver.com -e "set ftp:ssl-protect-data true;mget /remotedir/files* -O /localdir; exit"

The -O option is not required it you wish to store to the current local directory.

To mirror a whole directory to the FTP server:

lftp -u 'username,password' backupspace.remoteserver.com -e "set ftp:ssl-protect-data true;mirror --reverse /local/dir/name remotedirname; exit"

--reverse means that the 'mirroring' is going in the reverse direction than 'normal'. i.e. from your server to the backup server. If you run man lftp there are a few other options to choose from. e.g. --delete to delete files on the backup server that do not exist locally. Or --continue to continue a mirror job. Or --exclude files to exclude certain files from the transfer.

To restore a whole directory from the FTP server to your server:

lftp -u 'username,password' backupspace.remoteserver.com -e "set ftp:ssl-protect-data true;mirror remotedirname /local/dir/name;exit"

To create a nightly cronjob that uploads a directory to the backup FTP server, create a /etc/crond.daily/ftpbackup file like this:

#!/bin/bash
lftp -u 'username,password' backupspace.remoteserver.com -e "set ftp:ssl-protect-data true;mirror --reverse /local/dir/name remotedirname;exit" > /dev/null

And run:

chmod +x /etc/cron.daily/ftpbackup

Then check the files have been mirrored as you expect the next day.

FTP

To create a self-signed certificate, you can use the following commands :

mkdir -p /etc/ssl/private

openssl req -x509 -nodes -newkey rsa:1024 -keyout \
/etc/ssl/private/pure-ftpd.pem \
-out /etc/ssl/private/pure-ftpd.pem

chmod 600 /etc/ssl/private/*.pem

Screen Command

GNU Screen enables you to run many shell processes in a single terminal. So in one e.g. xterm you can have many bash instances like layers in GIMP or Adobe Photoshop. Even better, you can split your terminal into different regions.

Steps
-----
1)Create a screen using the command
#screen -S abhi

2)Close the shell without logout

3)Open a new shell

4)Type screen -ls

[root@cochin1 ~]# screen -ls
There are screens on:
16921.test (Dead ???)
3981.name (Attached)
5002.abhi (Attached)
Remove dead screens with 'screen -wipe'.
3 Sockets in /tmp/screens/S-root.

5)You can login to that screen using the command screen -r 'screen name'

[root@cochin1 ~]# screen -r 5002.niyas
There is a screen on:
5002.abhi (Attached)

Extract files from tar.gz file

First unzip the file using

gunzip filename.tar.gz

This create a filename.tar file then to display the contets use

tar -t filename.tar

Then if you want to extract a file called abc.sql from that tar just give the command

tar -xvf /path/filename.tar -M /fullpath/abc.sql

It will be extracted to /fullpath/inside/abc.sql in the directory you are residing.

2009/08/15

PHP "nobody" Spammers

PHP and Apache has a history of not being able to track which users are sending out mail through the PHP mail function from the nobody user causing leaks in formmail scripts and malicious users to spam from your server without you knowing who or where.

Watching your exim_mainlog doesn't exactly help, you see th email going out but you can't track from which user or script is sending it. This is a quick and dirty way to get around the nobody spam problem on your Linux server.

If you check out your PHP.ini file you'll notice that your mail program is set to: /usr/sbin/sendmail and 99.99% of PHP scripts will just use the built in mail(); function for PHP - so everything will go through /usr/sbin/sendmail

Requirements:
We assume you're using Apache 1.3x, PHP 4.3x and Exim. This may work on other systems but we're only tested it on a Cpanel/WHM Red Hat Enterprise system.

Time:
10 Minutes, Root access required.

Step 1)
Login to your server and su - to root.

Step 2)
Turn off exim while we do this so it doesn't freak out.
/etc/init.d/exim stop

Step 3)
Backup your original /usr/sbin/sendmail file. On systems using Exim MTA, the sendmail file is just basically a pointer to Exim itself.
mv /usr/sbin/sendmail /usr/sbin/sendmail.hidden

Step 4)
Create the spam monitoring script for the new sendmail.
pico /usr/sbin/sendmail

Paste in the following:


#!/usr/local/bin/perl

# use strict;
use Env;
my $date = `date`;
chomp $date;
open (INFO, ">>/var/log/spam_log") || die "Failed to open file ::$!";
my $uid = $>;
my @info = getpwuid($uid);
if($REMOTE_ADDR) {
print INFO "$date - $REMOTE_ADDR ran $SCRIPT_NAME at $SERVER_NAME n";
}
else {

print INFO "$date - $PWD - @infon";

}
my $mailprog = '/usr/sbin/sendmail.hidden';
foreach (@ARGV) {
$arg="$arg" . " $_";
}

open (MAIL,"|$mailprog $arg") || die "cannot open $mailprog: $!n";
while ( ) {
print MAIL;
}
close (INFO);
close (MAIL);


Step 5)
Change the new sendmail permissions
chmod +x /usr/sbin/sendmail

Step 6)
Create a new log file to keep a history of all mail going out of the server using web scripts
touch /var/log/spam_log

chmod 0777 /var/log/spam_log

Step 7)
Start Exim up again.
/etc/init.d/exim start

Step Cool
Monitor your spam_log file for spam, try using any formmail or script that uses a mail function - a message board, a contact script.
tail - f /var/log/spam_log

Sample Log Output

Mon Apr 11 07:12:21 EDT 2005 - /home/username/public_html/directory/subdirectory - nobody x 99 99 Nobody / /sbin/nologin

Log Rotation Details
Your spam_log file isn't set to be rotated so it might get to be very large quickly. Keep an eye on it and consider adding it to your logrotation.

pico /etc/logrotate.conf

FIND:
# no packages own wtmp -- we'll rotate them here
/var/log/wtmp {
monthly
create 0664 root utmp
rotate 1
}

ADD BELOW:

# SPAM LOG rotation
/var/log/spam_log {
monthly
create 0777 root root
rotate 1
}

Notes:
You may also want to chattr + i /usr/sbin/sendmail so it doesn't get overwritten. Enjoy knowing you can see nobody is actually somebody

Prevent Spam For CPanel Servers (Using Antivirus.exim)

Preventing Spam with Antivirus.exim

Cpanel servers have a nice little file called antivirus.exim. Most of you probably have never of this magic little gem. It's a central filter for the exim mail server that lets you setup all kinds of wonderful filters to help stop spam from coming in and going out of your server.

I'm going to share my /etc/antivirus.exim config file with you guys because I hate spam and you do as well. This will help protect you and therefore protect me as well because your server might be spamming mine one day.

First off the default /etc/antivirus.exim has a couple different rule sets in it. The main ones are attachment filters to help stop email viruses from your users. They stop things like .src and .com and .exe attachments.

This shows you some custom rules to stop spammers from sending out of your server, you can also use it to stop spam from coming in. I don?t really go into a lot of detail for filtering incoming mail since other applications like Spam Assassin handle that better IMO.

You need root access to your Cpanel server as usual.

First off we need to create a special log file for these filters do this:

touch /var/log/filter.log
chmod 0644 /var/log/filter.log

Now open up the configuration file
vi /etc/antivirus.exim

It should have a whole whack of comments at the top.

Here?s the webhostgear.com antivirus.exim configuration. Simple add this to your existing file, save the changes and they take effect instantly. ########################################################

# START
# Filters all incoming an outgoing mail

logfile /var/log/filter.log 0644
## Common Spam
if

# Header Spam
$header_subject: contains "Pharmaceutical" or $header_subject: contains "Viagra"
or $header_subject: contains "Cialis"
or $header_subject: is "The Ultimate Online Pharmaceutical" or $header_subject: contains "***SPAM***" or $header_subject: contains "[SPAM]"

# Body Spam
or $message_body: contains "Cialis"
or $message_body: contains "Viagra"
or $message_body: contains "Leavitra"
or $message_body: contains "St0ck"
or $message_body: contains "Viaagrra"
or $message_body: contains "Cia1iis"
or $message_body: contains "URGENT BUSINESS PROPOSAL" or $message_body matches "angka[^s]+[net|com|org|biz|info|us|name]+?" or $message_body matches "v(i|1)agra|vag(i|1)n(a|4)|pen( i|1)s|asu|seks|l(o|0)l(i|1)ta|dewacolok"

then
# Log Message - SENDS RESPONSE BACK TO SENDER # SUGGESTED TO LEAVE OFF to prevent fail loops # and more work for the mail system
#fail text "Message has been rejected because it hasn # triggered our central filter." logwrite "$tod_log $message_id from $sender_address contained spam keywords"

seen finish
endif

# END
# Filters all incoming an outgoing mail

# START
# All outgoing mail on the server only - what is sent out

#Check forwarders so it doesn't get blocked #Forwarders still work =)

## FINANCIAL FAKE SENDERS
## Log all outgoing mail from server that matches rules logfile /var/log/filter.log 0644

if (
$received_protocol is "local" or
$received_protocol is "esmtpa"
) and (
$header_from contains "@citibank.com" or
$header_from contains "@bankofamerica.com" or
$header_from contains "@wamu.com" or
$header_from contains "@ebay.com" or
$header_from contains "@chase.com" or
$header_from contains "@paypal.com" or
$header_from contains "@wellsfargo.com" or
$header_from contains "@bankunited.com" or
$header_from contains "@bankerstrust.com" or
$header_from contains "@bankfirst.com" or
$header_from contains "@capitalone.com" or
$header_from contains "@citizensbank.com" or
$header_from contains "@jpmorgan.com" or
$header_from contains "@wachovia.com" or
$header_from contains "@bankone.com" or
$header_from contains "@suntrust.com" or
$header_from contains "@amazon.com" or
$header_from contains "@banksecurity.com" or
$header_from contains "@visa.com" or
$header_from contains "@mastercard.com" or
$header_from contains "@mbna.com"

)
then

logwrite "$tod_log $message_id from $sender_address is fraud"
seen finish

endif

## OTHER FAKE SENDERS SPAM
## Enable this to prevent users using @domain from addresses ## Not recommended since users do use from addresses not on the server ## Log all outgoing mail from server that matches rules logfile /var/log/filter.log 0644

#if (
# $received_protocol is "local" or
# $received_protocol is "esmtpa"
# ) and (
# $header_from contains "@hotmail.com" or
# $header_from contains "@yahoo.com" or
# $header_from contains "@aol.com"

#)
# then

# logwrite "$tod_log $message_id from $sender_address is forged fake"
# seen finish

# endif

## KNOWN FAKE PHISHING
### Log all outgoing mail from server that matches rules logfile /var/log/filter.log 0644

if (
$received_protocol is "local" or
$received_protocol is "esmtpa"
) and (
#Paypal
$message_body: contains "Dear valued PayPal member" or
$message_body: contains "Dear valued PayPal customer" or
$message_body: contains "Dear Paypal" or
$message_body: contains "The PayPal Team" or
$message_body: contains "Dear Paypal Customer" or
$message_body: contains "Paypal Account Review Department" or

#Ebay

$message_body: contains "Dear eBay member" or
$message_body: contains "Dear eBay User" or
$message_body: contains "The eBay team" or
$message_body: contains "Dear eBay Community Member" or

#Banks

$message_body: contains "Dear Charter One Customer" or
$message_body: contains "Dear wamu.com customer" or
$message_body: contains "Dear valued Citizens Bank member" or
$message_body: contains "Dear Visa" or
$message_body: contains "Dear Citibank" or
$message_body: contains "Citibank Email" or
$message_body: contains "Dear customer of Chase Bank" or
$message_body: contains "Dear Bank of America customer" or

#ISPs

$message_body: contains "Dear AOL Member" or
$message_body: contains "Dear AOL Customer"

)
then
logwrite "$tod_log $message_id from $sender_address is phishing"
seen finish

endif

# END
# All outgoing mail on the server only - what is sent out

The log file will have the logging format like this: /var/log/filter.log

2006-05-10 12:05:13 1Fds7S-0002Sa-MV from smooth595@gmail.com contained spam keywords 2006-05-10 14:18:47 1FduCn-0006GV-1r from dayton.nowellu7xn@gmail.com contained spam keywords 2006-04-27 15:44:35 1FZDLn-0005Mo-5z from nobody@ocean.wavepointmedia.com is fraud 2006-04-27 16:37:40 1FZEB9-0002KQ-VP from nobody@ocean.wavepointmedia.com is phishing

Date and time, the Exim message ID, the sender and the section of the filter, like phishing, fraud or spam. You can check the mail message by grepping the exim_mainlog for it like this

grep 1FZEB9-0002KQ-VP /var/log/exim_mainlog

Unable to send email

SMTP, Port: 25, Secure(SSL): No, Error Number: 0x800CCC0B

If you can not send email using mail.yourdomainname.com as your SMTP server,
it may be because your ISP is blocking port 25 on their network, used for sending outoing mail via the SMTP protocol.
In this instance, we recommend using your ISPs outgoing mail server, which can be obtained from your ISP.

Please check with your ISP for their outgoing mail server settings (SMTP) and adjust in your email program under email account setup .


If you are using Outlook Express

Solution Configuring an email client requires that you enable
authentication for all the outgoing emails. To do so follow the steps given below

1. Open the Outlook Express.
2. Go to Tools -> Accounts
3. Select the email account name from the Mail tab of Internet Account Window.
4. Click on the Properties.
5. Go to the Servers Tab.
6. Check the option My Server Requires authentication.
7. Click on Apply button
8. Click on Close button to close the Internet Mail Account Window

http://kb.mozillazine.org/Cannot_send_mail

-------------------

Why can I receive email, but not send any?

If you can receive mail and cannot send mail then there can be two reasons.

1. Authentication Failed You do need to authenticate before you can relay mail.
This means you will need to use SMTP Authentication in your mail client.

2. ISP is Blocking Port 25 If your ISP is blocking port 25, you may not be able to send email.
Some ISPs do this so that you are forced to use their email servers when sending email, as an attempt to prevent spam.

In order to test that the SMTP (outgoing) mail server is functioning properly, you will need to use telnet.
You may use any telnet client that will allow you to telnet to port 25 on your domain.
This can usually be done by simply trying to point your browser to telnet://daveonline.ca:25
or From your windows machine.
Start-->Run-->Cmd
telnet daveonline.ca 25

You will get a response like below from the mail server.

# telnet daveonline.ca 25
Trying 70.85.231.190...
Connected to daveonline.ca (70.85.231.190).
Escape character is '^]'.
220-mercury.nocstation.info ESMTP Exim 4.52

If you are using a Linux machine, then you can type in the command below to check if you are able to connect to the
mail server port 25
telnet daveonline.ca 25

Please check with your ISP for their outgoing mail server settings (SMTP) and adjust in your email program under
email account setup .

Stopping directory listing for the folders that don't have index.htm

To turn these directory listings off, simply create an .htaccess file in the directory you want to protect and insert:
Options -Indexes

503 valid RCPT command must precede DATA

The server responded: 503 valid RCPT command must precede DATA

means you must check your email before trying to send mail. The mail server requires authentication, which can be achieved using one of these methods:

1. Pop before smtp -- check your email for new mail before trying to send email. This adds your IP address to a relayhosts file and allows any email to be sent from that IP address for up to 30 minutes. After 30 minutes you have to authenticate again.

2. Configure your email client to authenticate automatically by checking the "my server requires authentication" box in your email configuration. You will be able to send mail without having to "pop" your mail box first.

Outlook Configeration

Outlook Configeration
----------------------

1. In Outlook, go to the Tools menu and click on Email Accounts.
2. Select Add a new email account and then click Next.
3. Select POP3 and then click Next.
4. Enter your email information:

Your Name: your name
Email Address: matt@castleman.net (the email address the messages will be sent from)
Incoming Mail server (POP3): mail.test.com
Outgoing Mail server (SMTP): mail.test.com
User Name: matt@test.com
Password: the password for the email address

5. Click on More Settings and Select the Outgoing Server Tab. Check My outgoing server (SMTP) requires authentication. Select Use same settings as my incoming mail server.

6.Click Ok. Click Next. Click Finish.

If you cannot send email using mail.yourdomainname.com as your SMTP server,
it may be because your ISP is blocking port 25 on their network, used for sending outoing mail via the SMTP protocol. In this instance, we recommend using your ISPs outgoing mail server, which can be obtained from your ISP.

How can I setup a remote connection to MySQL?

To remotely connect to your MySQL databases, you must have an I.P.-based account. Login to your control panel and click on the side menu "ValueApps" then the "Database" tab. If you have not installed MySQL, click on "MySQL Database" under Available ValueApps. If you have already installed MySQL, click on "MySQLs" under Installed ValueApps. Check the box "TCP/IP Connection". Now login to your account via SSH.

STEPS:
You have to login to MySQL first.
mysql -u root -p
(will prompt for password)

GRANT ALL PRIVILEGES ON *.* TO USERNAME@IP IDENTIFIED BY "PASSWORD";

*.* -- All Database or DatabaseName.*
USERNAME - Username
IP -- IP that needs to be allowed to connect to this server remotely.

How to reset the mySQL admin password

In a Unix environment, the procedure for resetting the root password is as follows:

1. Log on to your system as either the Unix root user or as the same user that the mysqld server runs as.

2. Locate the .pid file that contains the server's process ID. The exact location and name of this file depend on your distribution, hostname, and configuration. Common locations are /var/lib/mysql/, /var/run/mysqld/, and /usr/local/mysql/data/. Generally, the filename has the extension of .pid and begins with either mysqld or your system's hostname.

You can stop the MySQL server by sending a normal kill (not kill -9) to the mysqld process, using the pathname of the .pid file in the following command:

shell> kill `cat /mysql-data-directory/host_name.pid`

Note the use of backticks rather than forward quotes with the cat command; these cause the output of cat to be substituted into the kill command.

3. Restart the MySQL server with the special --skip-grant-tables option:

shell> mysqld_safe --skip-grant-tables &

4. Set a new password for the root@localhost MySQL account:

shell> mysqladmin -u root flush-privileges password "newpwd"

Replace "newpwd'' with the actual root password that you want to use.

5. You should be able to connect using the new password.

To Delete MySQL bin-log files

Log files are in /var/lib/mysql/

root@server01 [~]# find /var/lib/mysql/ -name 'mysql-bin.*' | wc -l
21115
root@server01 [~]# find /var/lib/mysql/ -name 'mysql-bin.*' -exec rm -f {} \;
root@server01 [~]# find /var/lib/mysql/ -name 'mysql-bin.*' | wc -l
0

Mysql Downgrade in Cpanel server

We need to do the following steps for downgrade MySQL,

1. Change the MySQL version in /var/cpanel/cpanel.config file,

mysql-version=4.1 to mysql-version=4.0

2. Take old MySQL database bakup,

# cp -rpf /var/lib/mysql /var/lib/mysql.old

3. Remove the old database,

# rm -rf /var/lib/mysql

4. Remove old mysql binary,

# rm -f /usr/sbin/mysqld

5. Now run the script mysqlup

# /script/mysqlup --force

6. It will install MySQL 4.0 on server.

Horde Problem

The client cannot able to login to his Horde account to check his mail. He would have reached till the login screen and if he click "Login" it will stay back in the same screen instead of going to his inbox. Here is the fix for it,

Check the following first,

1. goto " cd var/lib/mysql/horde " and check if there is a file named " horde_sessionhandler.frm "

2. move all the file named "horde_sessionhandler" with other name

3. Or you can goto mysql and can drop the table "horde_sessionhandler". It will show error message some times. If so use the step 2, so that the table gets moved automatically.(Remember that if you are using step2 skip the step 3)

4. Now type in shell "mysql"

5. It will take to mysql prompt . type "use horde";

6. copy this command and paste there :

CREATE TABLE horde_sessionhandler (session_id VARCHAR(32) NOT NULL, session_lastmodified INT NOT NULL, session_data LONGBLOB, PRIMARY KEY (session_id)) ENGINE = InnoDB;

7. quit from mysql and restart mysql.

8. Try now... Your issue is fixed!!!!! Cheesy Grin

2009/08/14

SuPHP

suPHP is a combination of an Apache module (mod_suphp) and an executable which provides a wrapper for PHP. With both together, it is possible to execute PHP scripts with the permissions of their owner without having to place a PHP binary in each user's cgi-bin directory. suPHP doesn't need Apache's suExec, and provides a logging function.

Suexec

Apache suEXEC is a feature of the Apache Web server. It allows users to run CGI and SSI applications as a different user - normally, all web server processes run as the default web server user (often wwwrun, apache or nobody). The suEXEC feature consists of a module for the web server and a binary executable which acts as a wrapper.

If a client requests a CGI and suEXEC is activated, it will call the suEXEC binary which then wraps the CGI scripts and executes it under the user account of the server process (virtual host) defined in the virtual host directive.

2009/08/13

Important Cpanel scripts to fix issues

Common cPanel /Scripts

Install Zend Optimizer /scripts/installzendopt
Hostname A Entry Missing! /scripts/fixndc then restart bind and apache
Install Cron on New Server /scripts/installrpm anacron vixie-cron ; /etc/rc.d/init.d/crond start
Bandwidth issues /scripts/cleanbw
/scripts/fixwebalizer (To fix problem in webalizer that stop updating stats)
/scripts/fixcommonproblems
/scripts/fixeverything
Fixing Mail List MailMan /usr/local/cpanel/bin/convertmailman2
Reinstall MailMan /scripts/reinstallmailman
Fix Permissions on accounts: /scripts/fixhome
Edit mySQL conf file: pico /etc/my.cnf
Edit php.ini: pico /usr/local/lib/php.ini
Edit Apache Conf: pico /etc/httpd/conf/httpd.conf
Checking Real Time Top Processes Login to SSH and run: top
Run cpanel backup /scripts/cpbackup
To try and fix domain controller: /scripts/fixndc

Quotas /scripts/initquotas - takes a while to run
/scripts/resetquotas
/scripts/fixquotas - takes a while to run

/scripts/adddns Add a Dns Entry
/scripts/addfpmail Install Frontpage Mail Exts
/scripts/addservlets Add JavaServlets to an account (jsp plugin required)
/scripts/adduser Add a User
/scripts/admin Run WHM Lite
/scripts/apachelimits Add Rlimits (cpu and mem limits) to apache.
/scripts/dnstransfer Resync with a master DNS Server
/scripts/editquota Edit A User’s Quota
/scripts/finddev Search For Trojans in /dev
/scripts/findtrojans Locate Trojan Horses
Suggest Usage
/scripts/findtrojans > /var/log/trojans
/scripts/fixtrojans /var/log/trojans
/scripts/fixcartwithsuexec Make Interchange work with suexec
/scripts/fixinterchange Fix Most Problems with Interchange
/scripts/fixtrojans Run on a trojans horse file created by findtrojans to remove them
/scripts/fixwebalizer Run this if a user’s stats stop working
/scripts/fixvaliases Fix a broken valias file
/scripts/hdparamify Turn on DMA and 32bit IDE hard drive access (once per boot)
/scripts/initquotas Re-scan quotas. Usually fixes Disk space display problems
/scripts/initsuexec Turn on SUEXEC (probably a bad idea)
/scripts/installzendopt Fetch + Install Zend Optimizer
/scripts/ipusage Display Ipusage Report
/scripts/killacct Terminate an Account
/scripts/killbadrpms Delete “Security Problem Infested RPMS”
/scripts/mailperm Fix Various Mail Permission Problems
/scripts/mailtroubleshoot Attempt to Troubleshoot a Mail Problem
/scripts/mysqlpasswd Change a Mysql Password
/scripts/quicksecure Kill Potential Security Problem Services
/scripts/rebuildippool Rebuild Ip Address Pool
/scripts/remdefssl Delete Nasty SSL entry in apache default httpd.conf
/scripts/restartsrv Restart a Service (valid services: httpd,proftpd,exim,sshd,cppop,bind,mysql)
/scripts/rpmup Syncup Security Updates from RedHat/Mandrake
/scripts/runlogsnow Force a webalizer/analog update.
/scripts/secureit Remove non-important suid binaries
/scripts/setupfp4 Install Frontpage 4+ on an account.
/scripts/simpleps Return a Simple process list. Useful for finding where cgi scripts are running from.
/scripts/suspendacct Suspend an account
/scripts/sysup Syncup Cpanel RPM Updates
/scripts/unblockip Unblock an IP
/scripts/unsuspendacct UnSuspend an account
/scripts/upcp Update Cpanel
/scripts/updatenow Update /scripts
/scripts/wwwacct Create a New Account

/scripts/runweblogs account username for awstats to run manually

Sometimes such behavior of apache/httpd (taking more and more memory until it dies or crashes the server) can be caused by corrupted MySQL database. Try to do the following:
1) Kill the mysql server
/etc/rc.d/init.d/mysql stop

2) Repair all SQL databases:
myisamchk -r /var/lib/mysql/*/*.MYI

3) Start mysql again:
/etc/rc.d/init.d/mysql start

2009/08/11

Prevent Spamming in Exim/cPanel

(You will have to do this through WHM if you want to make the changes permanent, otherwise any changes will be overwritten during the next WHM/Cpanel update Main >> Service Configuration >> Exim Configuration Editor >> Advanced Editor. You may want to make a copy from the command line first just in case you mess things up ‘cp /etc/exim.conf /etc/exim.conf.bak’)

RBL, or Real-time Blackhole Lists, are lists of IP addresses from known spammers. You can use these lists in Exim to reject email from said spammers using the steps below;

Scroll down to the three text input boxes just below “begin acl”
In the *middle* box find the line ” accept hosts = :” and just after that line insert the following

#**# RBL List Begin
#**#
#
# Always accept mail to postmaster & abuse
#
accept domains = +local_domains
local_parts = postmaster:abuse
#
# Check sending hosts against DNS black lists.
# Reject message if address listed in blacklist.
deny message = ${sender_host_address} is listed at ${dnslist_domain}; See ${dnslist_text}
!hosts = +relay_hosts
!authenticated = *
dnslists = zen.spamhaus.org : bl.spamcop.net
!domains = +local_domains
#**#
#**# RBL List End

Spamassasin
————————

# vi /etc/mail/spamassassin/local.cf ‘ you will see the line;

# trusted_networks 212.17.35.

You can uncomment that line and add the IP address of your mailserver and localhost (and whatever other IPs you want to trust);

trusted_networks 127.0.0.1
trusted_networks 66.249.0.28

The other setting I found was whitelist_auth. You can add this anywhere in the /etc/mail/spamassassin/local.cf. ‘whitelist_auth’ will only work if you are using SPF, DKIM, or DomainKeys to verify senders.

whitelist_auth dave@example.com
whitelist_auth *@spry.com

For more info type ‘perldoc Mail::SpamAssassin::Conf’ from the command line.

These settings will help lower the amount of mail that Spamassassin has to process by ignoring all mail coming from your server and any other trusted IP.

——————————————————————————————–

Change all default/catchall addresses from :blackhole: to :fail:

Then to change all default addresses to :fail: we’ll need to run two commands, one to change any :blackhole: settings and the other to change any default addresses that forward to another email address. First run this command in SSH …

Quote:
replace ‘:blackhole:’ ‘:fail:’ — /etc/valiases/*

… this will change any :blackhole: setting to the desired :fail: setting.

Change all default/catchall addresses to :fail:

Then the second command …

Quote:
sed -i ’s/^\*: [^ ]*$/*: :fail: ADDRESS DOES NOT EXIST/g’ /etc/valiases/*

… this will change any setting which sends the unrouted mail to another email address to the desired :fail: setting.

Now, running this command again should reveal no results because we have just changed all settings to :fail: …

Quote:
grep ‘*:’ /etc/valiases/* | egrep -v ‘:fail:’

2009/08/09

Linux Booting Process

Linux Booting Process 1. Introduction

"Booting the computer", this is a common word associated with starting the computer. Though we use it casually in our daily life, have you ever thought of what exactly it is ? or how the system brings itself to a workable environment ? Well, my attempt in this article is to explain all the stages involved in booting your Linux machine. In simple words, bootstrapping means starting up your computer. It involves all those stages, from the moment you power on your machine till the system is ready to log you in.

2. The Boot Process

The Boot process involves several different stages that the system undergoes while it is being booted. If any of these stages fail, then the system cannot start itself.

* The BIOS
* Kernel Initialization
* Hardware Configuration
* System Processes
* Startup Scripts
* Multiuser Mode

Lets look at each of the above stages in detail.

2.1 The BIOS

This is the initial stage of the boot process. The moment you power your system, the microprocessor is not aware of your computer environment or even your operating system. It is the BIOS, that provides the necessary instructions to microprocessor and helps to initialize the computer environment. That is why it is called Basic Input/Output System.

These are the main tasks of BIOS.

* POST (Power On Self Test): The BIOS performs a power on self test on all hardware components attached to the computer during booting. You might have noticed the LEDs on your keyboard flashing during booting. That is an example of POST. If anything fails, it will be reported to you on your screen.

* The BIOS provides a set of low level routines for the hardware components to interface with the Operating System. These routines act like drivers for your Screen, Keyboard, Ports etc.

* The BIOS helps to manage the settings of hard disks, your first boot device, system time and more.

The BIOS also initiates the bootstrapping sequence by loading the Initial Program Loader (The boot loader program) into the computer memory. The software is usually stored in the ROM. This stage is actually outside of the domain of the Operating System and it is more vendor specific.

2.2 Kernel Initialization

Linux actually implements a two stage boot process. In the first stage, the BIOS loads the boot program (Initial Program Loader) from the hard disk to the memory. In the second stage, the boot program loads the Operating System kernel vmlinuz into memory. Though, the kernel can be called any name, we'll call it vmlinuz. Well, it's just a tradition, where vm stands for the Virtual Memory support and last z denotes that it is a compressed image, ie vmlinux.z => vmlinuz.

When the kernel loads into memory, it performs a memory test. Most of the kernel data structures are initialized statically. So it sets aside a part of memory for kernel use. This part of the memory cannot be used by any other processes. It also reports the total amount of physical memory available and sets aside those for the user processes.

2.3 Hardware Configuration
If you have configured a Linux kernel, you would have configured the hardware sections as well. This is how the kernel knows what hardware to find. Based on the configuration, when the kernel boots, it tries to locate or configure those devices. It also prints the information of the devices it found during the bootup. It will probe the the bus for devices or asks the driver for information of the devices. Devices that are not present in the system or not responding to the probing will be disabled. It is possible to add more devices using the utility kudzu.

2.4 System Processes
Once the hardware initialization is complete, the kernel will create several spontaneous processes in the user space. The following are those processes.

* init
* keventd
* kswapd
* kupdated
* bdflush

These are called spontaneous processes because they are not created by the usual fork mechanism. Of these, only init is actually in the user space(only processes in the user space can be controlled by us) , we have no control over others. The rest of the boot up procedure is controlled by init.

2.5 Startup Scripts

Before explaining how startup scripts work, let's have a look at the tasks performed by them. The following are the important tasks performed by startup scripts.

* Set the name of the computer
* Set the time zone
* Check the hard disk with fsck
* Mount system disk
* Remove old files from /tmp partition
* Configure network interfaces with correct IP address
* Startup deamons and other network services

The startup scripts are found in /etc/rc.d/init.d folder in your Linux machine.

2.5.1 Init and runlevels

You can boot your Linux machine to different runlevels. A runlevel is a software defined configuration of your system where the system behavior will vary in different runlevels. Though, Linux can have 10 different runlevels, only 7 of them are used. I have mentioned them below.

runlevel description
0 shutdown
1 or S single user mode
2 multiuser mode without nfs
3 full multiuser mode
4 not used
5 X windows
6 reboot

You can specify the runlevel in the init configuration file /etc/inittab.

2.5.2 Startup Scripts and runlevels

You may see folders (rc[0-7].d) corresponding to each runlevel in the /etc folder. These folders contain files symbolically linked (in Linux everything is a file) to the startup scripts in folder /etc/rc.d/init.d. If you look at these folders, you may see that the name of the symbolic links starts with the letter S or K followed by a number and the name of the startup script /service to which it is linked to.

For example, the following are the files in runlevel 2 and 3.

/etc/rc2.d/K20nfs -> ../init.d/nfs
/etc/rc2.d/S55named -> ../init.d/named
The name of those files are important. Because when you switch between runlevels, the services are started/stopped based on these names. Consider these two cases here.

* switching to higher runlevels - init will run scripts that start with letter S, in ascending order of the number with argument start
* switching to lower runlevels - init will run scripts that start with letter K, in descending order of the number with argument stop
The runlevels init checks to switch between them, depends on the configuration of your system. The following commands will help. For more details of the commands, refer to the manual pages.

The commands that deal with runlevels are:

/sbin/runlevel - shows the previous and current runlevels
/sbin/init and /sbin/telinit[b] - to switch between runlevels
[b]/sbin/chkconfig - to enable/disable services in runlevels

2.5.3 Startup Scripts and /etc/sysconfig files
The files in the /etc/sysconfig folder are read by the startup scripts. So it's worth mentioning them here.

* network - contains information of your hostname, nisdomain name etc.
* clock - timezone information
* autofsck - automatic filesystem check during boot up
* network-scripts - folder contains interface configuration files ifcfg-lo, ifcfg-eth0 etc.
* hwconf - hardware information
* sendmail, spamassassin, syslog, yppasswdd - information about the corresponding daemons.

Edit the files in /etc/sysconfig folder to make changes to your system.

2.5.4 Init and single user mode

This runlevel is used by sysadmins to perform routine maintenance. Its most commonly used for checking errors in file system with command fsck. Only the root file system will be mounted in this runlevel and the system administrator is provided with a shell. If necessary, other partitions needs to be mounted manually. Also none of the deamons will be running in this runlevel. Only the system administrator can use the system in this mode. You can simply exit from the shell to boot it to the multiuser mode.

2.6 Multiuser Operation

Though the system has been booted to a particular runlevel, none of the users can login to the system until init spawns getty processes on terminals. If the system is booted to runlevel 5, init needs to spawn the graphical login system gdm.

If the system has gone through the above mentioned stages without any failures, you may say that your system is booted and is ready to perform the tasks Smile

3. Rebooting and Shutting down

We have discussed about the boot procedure so far. It is also important to shutdown the system properly. Otherwise you may end up with loss of data or serious damage to the file system.

You can safely use the commands /sbin/shutdown, /usr/bin/halt or /usr/bin/reboot to halt or reboot the computer. For more details of the commands, refer to the manual pages.


===================================================================================

Boot process in a simple manner
_____________________________

When a system is switched on the processor looks at the end of system memory for the Basic Input/Output System or BIOS program and runs it. The BIOS is made up of two parts: the POST code and runtime services. POST(Power On Self Test) checks the system hardware and performs local device initialization. Then BIOS runtime services check for a valid boot device. If no configuration changes are made in BIOS it will first check floppy drive then harddisk drive and then on removable disk drives if any. If no boot device is found it will sends an interrupt and boot process will be terminated.

The boot device contains primary bootloader in the first 512-byte sector of the disk. This segment is called the Boot Sector. Sometimes it is also called Master Boot Record(MBR). Once a valid boot device is found, primary bootloader is loaded into RAM and BIOS passes control to it.

Stage 1

The primary boot loader that resides in the MBR is a 512-byte image containing both program code and a small partition table. The first 446 bytes are the primary boot loader, which contains both executable code and error message text. The next sixty-four bytes are the partition table, which contains a record for each of four partitions (sixteen bytes each). The MBR ends with two bytes that are defined as the magic number (0xAA55). The magic number serves as a validation check of the MBR.

The job of the primary boot loader is to find and load the secondary boot loader (stage 2) by looking through the partition table for an active partition. When it finds an active partition, it scans the remaining partitions in the table to ensure that they're all inactive. When this is verified, the active partition's boot record (secondary boot loader) is read from the device into RAM and executed.

Stage 2

The secondary boot loader is also called the kernel loader. The task at this stage is to load the Linux kernel and optional initial RAM disk.

The second stage boot loader has two functions:

1. Display the list of available kernels upon request, defined in bootloader configuration file.
(ie, for LILO /etc/lilo.conf and for Grub /etc/grub.conf)

2. Consult with filesystem to load the default kernel image and initrd image into memory.

With the images ready, the stage 2 boot loader passes the control to kernel image.

Stage 3

From here the Kernel stage begins.

The kernel image is a compressed image typically a zImage or bzImage.

The bzImage is decompressed by the C function decompress_kernel (located in ./arch/i386/boot/compressed/misc.c). When the kernel is decompressed into memory, it immediately initializes and configures memory paging and configures the various hardware attached to the system, including all processors, I/O subsystems, and storage devices.

Then it loads the initial RAM disk(initrd) and loads all the necessary drivers. This initrd serves as a temporary root file system in RAM and allows the kernel to fully boot without having to mount any physical disks. At this point, there are no user applications that allow meaningful input to the system, not much can be done with the system. To set up the user environment, the kernel executes the /sbin/init program.

Init

After the kernel is booted and initialized, the kernel starts the first user-space application. The /sbin/init program (also called init) coordinates the rest of the boot process and configures the environment for the user.

--------------------------------------------------------------------

2009/08/08

VPS ( Virtual private server )

A virtual private server (VPS, also referred to as Virtual Dedicated Server or VDS) is a method of partitioning a physical server computer into multiple servers such that each has the appearance and capabilities of running on its own dedicated machine. Each virtual server can run its own full-fledged operating system, and each server can be independently rebooted.

The practice of partitioning a single server so that it appears as multiple servers has long been common practice in mainframe computers, but has seen a resurgence lately with the development of virtualization software and technologies for other architectures.