Thursday, December 29, 2011

How to send mails using telnet

This post explains how to send mails to the users in the same system. From the user aswath to the user ajith. This is useful to troubleshoot mail server issues.

[root@localhost ~]# telnet 127.0.0.1 25
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 localhost.localhost.com ESMTP Sendmail 8.13.8/8.13.8; Fri, 30 Dec 2011 04:04:06 +0530
helo 127.0.0.1
250 localhost.localhost.com Hello localhost.localdomain [127.0.0.1], pleased to meet you
mail from:<aswath@localhost.localdomain>
250 2.1.0 <aswath@localhost.localdomain>... Sender ok
RCPT TO:<ajith@localhost.localdomain>
250 2.1.5 <ajith@localhost.localdomain>... Recipient ok
data
354 Enter mail, end with "." on a line by itself
subject:test1
hi test1
.
250 2.0.0 pBTMY6ln018613 Message accepted for delivery
quit
221 2.0.0 localhost.localhost.com closing connection
Connection closed by foreign host.
You have new mail in /var/spool/mail/root
[root@localhost ~]#

The mail log is as follows.

[root@localhost ~]# tail -f /var/log/maillog
Dec 30 04:05:02 localhost sendmail[18613]: pBTMY6ln018613: from=<aswath@localhost.localdomain>, size=23, class=0, nrcpts=1, msgid=<201112292234.pBTMY6ln018613@localhost.localhost.com>, proto=SMTP, daemon=MTA, relay=localhost.localdomain [127.0.0.1]
Dec 30 04:05:02 localhost sendmail[18615]: pBTMY6ln018613: to=<ajith@localhost.localdomain>, ctladdr=<aswath@localhost.localdomain> (501/501), delay=00:00:38, xdelay=00:00:00, mailer=local, pri=30380, dsn=2.0.0, stat=Sent

Thursday, December 8, 2011

how to enable mod_speling on directadmin


mod_speling how to
Enabling mod_speling in directadmin

[root@www custombuild]# cd /usr/local/directadmin/custombuild
[root@www custombuild]# mkdir -p custom/ap2
[root@www custombuild]# cp -Rp configure/ap2/configure.apache custom/ap2/configure.apache
[root@www custombuild]# vi custom/ap2/configure.apache
add     "--enable-speling" \ after    "--enable-so" \
save the file
[root@www custombuild]# ./build apache

add the following lines to /etc/httpd/conf/httpd.conf
[root@www custombuild]#  vi /etc/httpd/conf/httpd.conf
CheckSpelling On
CheckCaseOnly On
then save the file

Restart httpd
[root@www custombuild]# /etc/init.d/httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd: [Fri Dec 09 00:10:58 2011]
[root@www custombuild]#

Checking
[root@www custombuild]# httpd -l | grep spel
  mod_speling.c
[root@www custombuild]#

How to remove the spam mails from qmail queue


How to remove spam mails from qmail mail queue

This post helps you to remove spam mails containing a string (subject) or from a particular user from the qmail mail queue. You have to install a open source

software qmail-remove.

Go to the directory /usr/local/src
[root@host ~]# cd /usr/local/src

Download the qmail-remove package
[root@host ~]# wget http://www.linuxmagic.com/opensource/qmail/qmail-remove/qmail-remove-0.95.tar.gz

Untar the package
[root@host ~]# tar xvzf qmail-remove-0.95.tar.gz

cd to the untared directory
[root@host ~]# cd qmail-remove-0.95/

compile
[root@host ~]# make

Install
[root@host ~]# make install

You can check the options with -h option
[root@host ~]# qmail-remove -h

Now the package is installed but you have to create a yanked directory to store the mails you are removing. You have to create it in the qmail base

directory. In this case it is /var/qmail/queue/ yours may differ.
[root@host ~]# cd /var/qmail/queue/
[root@host ~]# mkdir yanked

And before running the commands using this package you must stop qmail
[root@host ~]# /etc/init.d/qmail stop

There is one helpful tool with you can count and list the spam mails. Install it. You can get the directions from here
http://www.atomicorp.com/wiki/index.php/Spam

You can use -s option to get the total no.of spam mails in queue
[root@host ~]# /usr/bin/qmhandle.pl -s
Total messages: 253998
Messages with local recipients: 17
Messages with remote recipients: 253965
Messages with bounces: 1
Messages in preprocess: 16
[root@host ~]# /usr/bin/qmhandle.pl -s
Total messages: 185000
Messages with local recipients: 17
Messages with remote recipients: 184962
Messages with bounces: 1
Messages in preprocess: 20
[root@host ~]#

You can use -l option to list the spam mails in queue
[root@host ~]# /usr/bin/qmhandle.pl -l

You can read a message using the option -m
[root@host ~]# /usr/bin/qmhandle.pl -m22616314
 --------------
MESSAGE NUMBER 22616314
 --------------
Received: (qmail 25932 invoked by uid 502); 7 Dec 2011 12:17:40 +1100
Date: 7 Dec 2011 12:17:40 +1100
Message-ID: <20111207011740.25927.qmail@host.xxxxxx.com>
To: lyttmab@ppppp.com
Subject: I WISH TO HAVE YOU AS A PERSONAL ASSISTANT.
From: Mr.Morgan Kent <mr.morgankent2@ppppp.com>
Reply-To: morgankent202@ppppp.com
MIME-Version: 1.0
Content-Type: text/plain
Content-Transfer-Encoding: 8bit
morgankent2011@ppppp.com
mr.morgankent2011@ppppp.com
######OUTPUT TRUNCATED########

You can read the headers of the mails in the queue using the following command
[root@host ~]# /var/qmail/bin/qmail-qread
7 Dec 2011 14:22:43 GMT  #22708222  3232  <anonymous@host.xxxxxx.com>
        remote  crehkow@ppppp.com
7 Dec 2011 12:12:16 GMT  #22609322  3233  <anonymous@host.xxxxxx.com>
        remote  jbilodeau1@ppppp.com
7 Dec 2011 10:55:48 GMT  #14396666  3237  <anonymous@host.xxxxxx.com>
        remote  izzy46martinez@ppppp.com

For listing the mails in the mail queue with a particular content use the following command
[root@host ~]# qmail-remove -i -p "I WISH TO HAVE YOU AS A PERSONAL ASSISTANT"
It will list the mails with content I WISH TO HAVE YOU AS A PERSONAL ASSISTANT in it

The above command will only list the mails. for deleting them use option -r. Then all those mails will be moved to yanked directory.
[root@host ~]# qmail-remove -i -p "I WISH TO HAVE YOU AS A PERSONAL ASSISTANT"  -r
[root@host yanked]# pwd
/var/qmail/queue/yanked
[root@host yanked]# ls | wc -l
593379
[root@host yanked]#

Useful links
http://www.atomicorp.com/wiki/index.php/Spam
http://kb.parallels.com/en/1711
http://kb.parallels.com/en/766
http://www.linuxmagic.com/opensource/qmail/qmail-remove

NRPE: Command 'check_mem' not defined

This error is coming because the missing of check_mem command on the client machine

open the following file and add the command as follows

root@server1 [/opt/Nagios/Nagios_NRPE/nrpe-2.12]# vi /usr/local/nagios/etc/nrpe.cfg
command[check_mem]=/usr/local/nagios/libexec/check_mem 85 95
save the file. That it.

root@server1 [~]# /usr/local/nagios/libexec/check_mem 85 95
OK - Memory usage is 2.000%
root@server1 [~]#

NRPE: Command 'check_disk' not defined

This error is coming because the missing of check_disk command on the client machine
open the following file and add the check_disk command as follows

root@server1 [/opt/Nagios/Nagios_NRPE/nrpe-2.12]# vi /usr/local/nagios/etc/nrpe.cfg
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda
save the file. That it.

You can also test the command as below on the client server.
root@server1 [/opt/Nagios/Nagios_NRPE/nrpe-2.12]# /usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda
DISK OK - free space: / 863034 MB (99% inode=99%);| /=4696MB;731966;823462;0;914958

CHECK_NRPE: Error - Could not complete SSL handshake

You may get an error like this while configuring nrpe with nagios
root@server1 [/opt/Nagios/Nagios_NRPE/nrpe-2.12]# /usr/local/nagios/libexec/check_nrpe -H x.x.x.x
CHECK_NRPE: Error - Could not complete SSL handshake.
root@server1 [/opt/Nagios/Nagios_NRPE/nrpe-2.12]# /usr/local/nagios/libexec/check_nrpe -H localhost
CHECK_NRPE: Error - Could not complete SSL handshake.
The problem is you didnt give the ip address in /etc/xinetd.d/nrpe

Saturday, December 3, 2011

Error occurred during initialization of VM on javac

root@server [~]# /etc/init.d/red5  restart
Shutting down red5:                                        [FAILED]
Starting red5:                                                   [  OK  ]

root@server [~]# javac
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.

export _JAVA_OPTIONS="-Xms20m -Xmx64m -XX:MinHeapFreeRatio=20 -XX:MaxHeapFreeRatio=40 -XX:NewSize=10m -XX:MaxNewSize=10m -XX:SurvivorRatio=6 -XX:TargetSurvivorRatio=80 -XX:+CMSClassUnloadingEnabled -XX:+CMSClassUnloadingEnabled"

Thursday, December 1, 2011

Checking the php script sending the spam mails

This post explains how to check the php script sending the spam mails in exim.

Go to the mail sending directory of exim

root@server1 [~]# cd /var/spool/exim/input

Search for php scripts sent the spam mails
root@server1 [/var/spool/exim/input]#  egrep "X-PHP-Script" * -R

how to use a file as a hard disk partition.


This explains how to use a file as a hard disk partition. 

First we have to create a file(var.dsk) of  big size according to our need. Here we use dd command for this. A 1gb size file.
root@cpaneltest [~]# dd if=/dev/zero of=var.dsk bs=1024 count=1000000

Now you have to attach that file to a loop device. Using the command losetup.
root@cpaneltest [~]# losetup /dev/loop7 var.dsk

Now format the file with any filesystem. Here we use ext3.
root@cpaneltest [~]# mkfs.ext3 /dev/loop7

Now create a mount point.
root@cpaneltest [~]# mkdir /var_test

Mounting the attached loop device to the mount point
root@cpaneltest [~]# mount -t ext3 /dev/loop7 /var_test

Checking mount. See the last line.
root@cpaneltest [~]# mount
/dev/mapper/VolGroup00-LogVol00 on / type ext3 (rw,usrquota,acl)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/usr/tmpDSK on /tmp type ext3 (rw,noexec,nosuid,loop=/dev/loop0)
/tmp on /tmp type none (rw,noexec,nosuid,bind)
/dev/sdb1 on /root/dev_test type ext3 (rw)
/dev/loop7 on /var_test type ext3 (rw)

If you want to mount it permanantly so that it can survive reboots.
root@cpaneltest [~]# vi /etc/fstab
/dev/VolGroup00/LogVol00 /                       ext3    defaults,usrquota,acl        1 1
LABEL=/boot             /boot                   ext3    defaults        1 2
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
/dev/VolGroup00/LogVol01 swap                    swap    defaults        0 0
/usr/tmpDSK             /tmp                    ext3    noexec,nosuid,nodev,noatime,noauto        0 0
/tmp             /var/tmp                    ext3    noexec,nosuid,nodev,noatime,usrquota,bind,noauto        0 0
/dev/loop7      /var_test                       ext3    defaults        0 0
root@cpaneltest [~]# mount -a

For detaching the loop device and unmounting it.
root@cpaneltest [~]# umount  /var_test
root@cpaneltest [~]# losetup -d /dev/loop7
Remove the entry from fstab and run mount -a

Wednesday, November 30, 2011

calling two parameters from a file using bash script

this script explains how to call two parameters or arguments or values from a file using bash script in a for loop

file_path :  path to the file
i and j are the variables for the calling values


for i in `cut -d: -f2 file_path`
do
j=`cat file_path | grep $i | awk {'print $1'} | cut -d: -f1`
echo $i $j
done

Thursday, November 24, 2011

How to block the mails by subject in exim


Suppose you want to block the mails having subject job
Open the file /etc/mail/spamassassin/local.cf
And add the following lines.

header   JOB_SUBJECT Subject =~ /job/i
header   JOB_FROM    From =~ /job/i
meta     JOB_HEADER JOB_FROM && JOB_SUBJECT
score    JOB_HEADER 10.0
describe JOB_HEADER Block Mails with job in subject

save the file and restart the exim service if needed.

How to block mails by body content in exim

open the file /etc/mail/spamassassin/local.cf

and add the following lines.


rawbody  RULE_NAME  /CONTENT_WORD/i
score RULE_NAME 100

Restart the exim service if needed.

Tuesday, November 15, 2011

How to create a php info page

Go to the DocumentRoot of your domain or default DocumentRoot of your webserver.

Create a php info file as follows.
[root@server1 public_html]# cat info.php

<?php
// Show all information, defaults to INFO_ALL
phpinfo();
?>
[root@server1 public_html]#

Give proper permissions
permission 644
ownership as domain owners

Now go to the browser and access as given below:
http://your_domain/info.php
or

How to enable php json on centos


We can enable php json using pecl. This can be used in directadmin servers also.

First we have to find the location of perl command. Using the following command.
[root@server1 /]# which pecl
/usr/local/bin/pecl

Now installing json using pecl
[root@server1 /]# /usr/local/bin/pecl install json

Testing the module
[root@server1 /]# php -ini | grep json
json
json support => enabled
json version => 1.2.1
[root@server1 /]#

Wednesday, November 9, 2011

rebuilding corrupted named.conf in cpanel

Sometimes we will get our named.conf corrupted. Here is the way to fix that in cpanel servers.

First of all clear the named.conf using the following command

root@cpaneltest [~]#> /etc/named.conf

Now execute the cpanel script to rebuild the named.conf
root@cpaneltest [~]#/scripts/rebuildnamedconf

Now restart the named service
root@cpaneltest [~]#/etc/init.d/named restart
Everything should be fixed now.

/usr/sbin/chkfontpath is needed by msttcorefonts-2.0-1.noarch


You may getting this error while installing rpms.
/usr/sbin/chkfontpath is needed by msttcorefonts-2.0-1.noarch

Eg:
[root@vps /]# rpm -ivh msttcorefonts-2.0-1.noarch.rpm
error: Failed dependencies:
        /usr/sbin/chkfontpath is needed by msttcorefonts-2.0-1.noarch

You have to install the package chkfontpath using the fowllowing command
[root@vps /]# yum  install chkfontpath

You you can install the rpm without errors.
[root@vps /]# rpm -ivh msttcorefonts-2.0-1.noarch.rpm
Preparing...                   ########################################### [100%]
   1:msttcorefonts          ########################################### [100%]
[root@vps /]#

Confirming the installation
[root@vps /]# rpm -q msttcorefonts
msttcorefonts-2.0-1
[root@vps /]#

Tuesday, November 8, 2011

Configuring nginx as proxy for apache in ubuntu

Install apache2 and nginx services.

In this setup we configured apache to run on port 81 and nginx on port 80

nginx configuration file is given below :


root@host ~ # vi /etc/nginx/nginx.conf
user www-data;


worker_processes  1;
error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;
events {
    worker_connections  1024;
    # multi_accept on;
}
http {
    include       /etc/nginx/mime.types;
    access_log  /var/log/nginx/access.log;
    sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    tcp_nodelay        on;
    gzip  on;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";
    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
server {
        listen ip_address:80;
        server_name domain.com www.domain.com;
        location / {
        proxy_pass http://ip_address:81/;
        proxy_redirect http://ip_address:81/ /;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_connect_timeout 150;
        proxy_send_timeout 100;
        proxy_read_timeout 100;
        proxy_buffers 4 32k;
        client_max_body_size 8m;
        client_body_buffer_size 128k;
                }
        location ~* ^.+\.(jpg|js|jpeg|png|ico|gif|txt|js|css|swf|zip|rar|avi|exe|mpg|mp3|wav|mpeg|asf|wmv)$ {
        root document_root_of_domain;
                }
        }
}

Disabling the unnecessary services in ubuntu or debian


We can list all the services currently running using the following command. 
#service --status-all


Eg:
root@host ~ # service --status-all
 [ ? ]  amavis
 [ + ]  apache2
 [ + ]  apparmor
 [ ? ]  atd
 [ + ]  bind9
 [ - ]  bootlogd
 [ - ]  clamav-daemon
 [ + ]  clamav-freshclam
 [ ? ]  console-setup
***********out put truncated********


To remove a service from debian startup execute the following command
#update-rc.d -f  service_name remove

Eg:

root@host ~ # update-rc.d -f atd remove
 Removing any system startup links for /etc/init.d/atd ...
root@host ~ #


In case if you want to add a service to ubuntu default runlevels execute the following command. 
#update-rc.d service_name defaults

Eg:

root@host ~ # update-rc.d proftpd defaults
 Adding system startup for /etc/init.d/proftpd ...
   /etc/rc0.d/K20proftpd -> ../init.d/proftpd
   /etc/rc1.d/K20proftpd -> ../init.d/proftpd
   /etc/rc6.d/K20proftpd -> ../init.d/proftpd
   /etc/rc2.d/S20proftpd -> ../init.d/proftpd
   /etc/rc3.d/S20proftpd -> ../init.d/proftpd
   /etc/rc4.d/S20proftpd -> ../init.d/proftpd
   /etc/rc5.d/S20proftpd -> ../init.d/proftpd
root@host ~ #

How to find the parent package of a file on Ubuntu


We can find the parent package of a file using following command in debian or ubuntu. 

root@host ~ # dpkg -S /usr/sbin/mysqld
percona-server-server-5.5: /usr/sbin/mysqld
root@host ~ #

For the same purpose you can use following command in centos, redbat or fedora 


root@cpaneltest [~]# rpm -qf /usr/sbin/mysqld
MySQL-server-5.0.92-0.glibc23
root@cpaneltest [~]#


How to find the parent package of a file on Ubuntu


We can find the parent package of a file using following command in debian or ubuntu. 

root@host ~ # dpkg -S /usr/sbin/mysqld
percona-server-server-5.5: /usr/sbin/mysqld
root@host ~ #

For the same purpose you can use following command in centos, redbat or fedora 


root@cpaneltest [~]# rpm -qf /usr/sbin/mysqld
MySQL-server-5.0.92-0.glibc23
root@cpaneltest [~]#


Saturday, November 5, 2011

Configuring the GNUpanel

Configuring the GNUpanel here are the steps :

1. login to your vps  as root user.

2. run these following commands to configure :
 # cd /directorio/gnupanel_lenny_ubuntu_hardy_intrepid_0.3.0_R7
# gnupanel-config.sh

3. when the configuration finished the admin interface can be located here: http://ip-publica/admin

4. the detail instruction can be found here: http://gnupanel.org/archives/category/howtos

Friday, November 4, 2011

Finding the clientid and licenseid of directadmin

You can find the clientid and licenseid of currently installed directadmin  from the file /usr/local/directadmin/scripts/setup.txt


[root@localhost ~]# cat /usr/local/directadmin/scripts/setup.txt
hostname=host.domain.tld
email=admin@host.domain.tld
mysql=aQGNqbDD
mysqluser=da_admin
adminname=admin
adminpass=o9uMqaIn
ns1=ns1.domain.tld
ns2=ns2.domain.tld
ip=
netmask=
uid=123
lid=4567
services=services_es50.tar.gz
[root@localhost ~]#

You can update the license manually as follows

[root@localhost ~]#cd /usr/local/directadmin/scripts 
[root@localhost ~]#./getLicense.sh 123 1234
[root@localhost ~]#service directadmin restart

Tuesday, November 1, 2011

FFmpeg installation on Centos cpanel server

First you have to install the following repositories for yum. [check your system architecture]


rpm -Uvh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm
rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm
rpm -Uvh http://download1.rpmfusion.org/free/el/updates/testing/5/i386/rpmfusion-free-release-5-0.1.noarch.rpm
rpm -Uvh http://download1.rpmfusion.org/nonfree/el/updates/testing/5/i386/rpmfusion-nonfree-release-5-0.1.noarch.rpm

Install ffmpeg, mplayer and mencoder

yum install ffmpeg mplayer mencoder

Install ruby using cpanel script
/scripts/installruby

Install flvtool
gem install flvtool2

Install MP4Box
yum install gpac gpac-libs

Install development packages for ffmpeg
yum install ffmpeg-devel

Install ffmpeg-php
wget http://downloads.sourceforge.net/ffmpeg-php/ffmpeg-php-0.6.0.tbz2
tar xjf ffmpeg-php-0.6.0.tbz2
cd ffmpeg-php-0.6.0
phpize
./configure
make
make install

Enabling ssl version 3 in apache

This post explains how to enable ssl version3 and TLS v1.0 using apache httpd webserver.

Edit the httpd.conf file and add the following lines to it.


[root@server ~]# vi /etc/httpd/conf/httpd.conf
#SSL3


<IfDefine SSL>
SSLProtocol -all +SSLv3 +TLSv1
SSLCipherSuite SSLv3:+HIGH:+MEDIUM
</IfDefine>

Now restart the httpd service.
[root@server ~]# /etc/init.d/httpd restart

Thats it.

Tuesday, October 25, 2011

Modules needed for iptables nat and csf


These are the modules needed for the iptables nat to work on openvz vps :


ipt_MASQUERADE
ipt_helper
ipt_SAME
ipt_REDIRECT
ipt_state
ipt_TCPMSS
ipt_LOG
ipt_TOS
tun
iptable_nat
ipt_length
ipt_tcpmss
iptable_mangle
ipt_limit
ipt_tos
iptable_filter
ipt_helper
ipt_tos
ipt_ttl
ipt_REJECT


They can be enabled on the node server using the following commands :

modprobe ipt_MASQUERADE
modprobe ipt_helper
modprobe ipt_SAME
modprobe ipt_REDIRECT
modprobe ipt_state
modprobe ipt_TCPMSS
modprobe ipt_LOG
modprobe ipt_TOS
modprobe tun
modprobe iptable_nat
modprobe ipt_length
modprobe ipt_tcpmss
modprobe iptable_mangle
modprobe ipt_limit
modprobe ipt_tos
modprobe iptable_filter
modprobe ipt_helper
modprobe ipt_tos
modprobe ipt_ttl
modprobe ipt_REJECT

Installing pptpd vpn on Ubuntu

This post explains how to install pptpd vpn server on ubuntu. It is tested on Ubuntu 11.04 and will work with other Ubuntu and Debian vps.

This is implement on a openvz vps. So there are two parts. Part one needs to be done on Node server and part two is need to be done on the vps. In case if you are working in a dedicated server you have to do both on the dedicated server.

Part one:
on the node:

Find the VEID of your vps. If you dont have access ask your vps provider to enable ppp and nat
[root@Node ~]# vzlist -a | grep 184.x.x.x
       [VEID]         20 running   184.x.x.x vps

Loading modules needed for ppp
[root@Node ~]# modprobe ppp_mppe
[root@Node ~]# modprobe ppp_deflate
[root@Node ~]# modprobe zlib_deflate
[root@Node ~]# modprobe ppp_async
[root@Node ~]# modprobe ppp_generic
[root@Node ~]# modprobe slhc
[root@Node ~]# modprobe crc_ccitt

Checking the modules
[root@Node ~]#  lsmod | grep ppp
ppp_async              45056  0
crc_ccitt              35200  1 ppp_async
ppp_deflate            39168  0
zlib_deflate           52760  1 ppp_deflate
ppp_mppe               39816  0
ppp_generic            63632  3 ppp_async,ppp_deflate,ppp_mppe
slhc                   39680  1 ppp_generic

Enabling ppp for the vps with VEID [VEID]:
You have to stop the vps first:
[root@Node ~]# vzctl stop [VEID]
Stopping container ...
Container was stopped
Container is unmounted

Now setting the parameters:
[root@Node ~]# vzctl set [VEID] --features ppp:on --save
Saved parameters for CT [VEID]
[root@Node ~]# vzctl set [VEID] --devices c:108:0:rw --save
Saved parameters for CT [VEID]
[root@Node ~]# vzctl start [VEID]
Starting container ...
Container is mounted
Adding IP address(es): 184.154.103.231
Setting CPU limit: 100
Setting CPU units: 1000
Setting CPUs: 1
Setting devices
Set hostname: vps
File resolv.conf was modified
Setting quota ugidlimit: 10000
Container start in progress...
[root@Node ~]# vzctl exec [VEID] mknod /dev/ppp c 108 0
[root@Node ~]# vzctl exec [VEID] chmod 600 /dev/ppp

Enabling NAT on openvz vps:
[root@Node ~]# vzctl stop [VEID]
[root@Node ~]# vzctl set [VEID]  --iptables ipt_REJECT --iptables ipt_tos --iptables ipt_TOS --iptables ipt_LOG --iptables ip_conntrack --iptables ipt_limit --iptables ipt_multiport --iptables iptable_filter --iptables iptable_mangle --iptables ipt_TCPMSS --iptables ipt_tcpmss --iptables ipt_ttl --iptables ipt_length --iptables ipt_state --iptables iptable_nat --iptables ip_nat_ftp --save
[root@Node ~]# vzctl start [VEID]

Part two:
Inside vps:
Searching the package pptpd on Ubuntu vps:
root@vps:~# apt-cache search pptp
pptpd - PoPToP Point to Point Tunneling Server

Installing the pptpd package:
root@vps:~# apt-get install pptpd

Testing the ppp module:
root@vps:/# /usr/sbin/pppd
~ÿ}#À!}!}!} }4}"}&} } } } }%}&} 3ä}'}"}(}"P};~~ÿ

Configuring the local ip and remote ip range for the vpn connections:
root@vps:/# vi /etc/pptpd.conf
localip 192.168.0.1
remoteip 192.168.0.234-238,192.168.0.245

Setting the DNS ip address for the vpn clients
root@vps:/# vi /etc/ppp/pptpd-options
ms-dns 8.8.8.8
ms-dns 8.8.4.4

masquerading the vpn client ips to the vps ip address
root@vps:/# iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -o venet0 -j MASQUERADE

Saving the iptables rules:
root@vps:/# iptables-save > /etc/iptables.conf

Writing iptables restore script:
root@vps:/# cat /etc/network/if-up.d/iptables
#!/bin/sh
iptables-restore < /etc/iptables.conf
root@vps:/#

Giving the execute permission for the restore script:
root@vps:/# chmod +x /etc/network/if-up.d/iptables

Enable packet forwarding:
root@vps:/# vi /etc/sysctl.conf
net.ipv4.ip_forward=1
root@vps:/# sysctl  -p
net.ipv4.ip_forward = 1

Creating vpn users for pptpd
root@vps:/# cat /etc/ppp/chap-secrets
# Secrets for authentication using CHAP
# client        server  secret                  IP addresses
vpn     pptpd   abc123$ *
root@vps:/#

Restarting the service.
root@vps:/# /etc/init.d/pptpd restart
Restarting PPTP:
Stopping PPTP: pptpd.
Starting PPTP Daemon: pptpd.
root@vps:/#

Thats it. Enjoy. Leave comments.

Enabling and testing mod_wsgi with EasyApache for WHM/cPanel

This post explains how to enable mod_wsgi using easyapache script.

Step 1:
You have to download and extract custom_opt_mod-mod_wsgi.tar.gz. From the link given below.
http://code.google.com/p/modwsgi/issues/detail?id=214

Step 2:
After downloading it extract it to location identifiable by easyapache
tar -C /var/cpanel/easy/apache/custom_opt_mods -xzf custom_opt_mod-mod_wsgi.tar.gz

Step 3:
Now run /scripts/easyapache
select mod_wsgi option while configuring profile.

Thats it.

Testing mod_wsgi with apache on cpanel server. :

Step 1:
First you have to create a test file as follows
root@server [/usr/local/apache/htdocs/test]# cat index.wsgi
def application(environ, start_response):
    """Simplest possible application object"""
    output = "Hello World"
    status = '200 OK'
    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)
    return [output]
root@server [/usr/local/apache/htdocs/test]#

Step 2:
And create one .htaccess file as follows.
root@server [/usr/local/apache/htdocs/test]# cat .htaccess
Options +ExecCGI
#DirectoryIndex DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm index.wsgi
AddHandler cgi-script .cgi
AddHandler wsgi-script .wsgi
<IfModule mod_wsgi.c>
WSGIScriptAlias /test /usr/local/apache/htdocs/test/index.wsgi
WSGIDaemonProcess root processes=5 threads=1 display-name=%{GROUP}
WSGIProcessGroup root
WSGIApplicationGroup %{GLOBAL}
</IfModule>
root@server [/usr/local/apache/htdocs/test]#

And add following lines in httpd.conf and restart apache
root@server1 [/usr/local/apache/htdocs/test]# vi /usr/local/apache/conf/httpd.conf
<Directory "/usr/local/apache/htdocs/test">
Options +ExecCGI
AddHandler cgi-script .cgi
</Directory>

You can check the script using the following url
http://YOUR_IP_ADDRESS/test/index.wsgi

Sunday, October 23, 2011

cpanel webmail login failed and asks login details twice

Sometimes you have to login twice if you are using webmail with cpanel. And still the login fails with error
login failed because your username or password was entered incorrectly (horde, roundcube, squirrelmail).

Here is the solution:
Check the hostname using the fowllowing command
#hostname
Server needs a FQDN hostname configured and also need to be resolvable in DNS
For example if your domain name is linuxhelp.in then hostname can be server.linuxhelp.in
And you should add an entry for server.linuxhelp.in in the DNS.

You can do that in cpanel as follows
Main >> Networking Setup >> Change Hostname
It will aslo ask you add an A record entry for it. Give your vps/server ip.

Now run the following commands.

rm -f /etc/userdomains
/usr/local/cpanel/scripts/updateuserdomains --force

Now restart the cpanel if needed.
/etc/init.d/cpaenl restart.
Thats it. The webmail  login error with cpanel should be fixed now. And you wont have to give login details twice.

Saturday, October 8, 2011

how to restore xen vps from tar backup

Here we discuss how to restore a xen vps or virtual private server or container for a .tar backup file.
For this, You must have enabled ftp backups and the backup should be there in a remote ftp backup server.

And suppose you have a backup as this in the backup server
569-xen-vm601-1.tar.gz
id=569
CID/XID=vm601

Now go to the node(server) where vps is created and run the following command.

[root@xendell ~]# /scripts/ftp-restore
/usr/lib/php/modules/dbase.so: cannot open shared object file: No such file or directory in Unknown on line 0

Checking connectivity to FTP backup server...
###### Pre Test Succeeded ######
SolusVM Virtual Server Restore       |      0 to quit
=====================================================

Enter the Vserver ID of a Virtual Server: 569
[this is the id of the vps not CID/XID]
Found virtual server, Please wait.....

Downloading xen dat...
Downloading xen cfg...
Downloading xen backup. This may take a while...

Filename: config-569.dat

/tmp/569-xen-vm601-1.tar.gz:                           596.49 MB   70.17 MB/s
/tmp/569-xen-vm601-1.tar.gz:                           596.49 MB   70.17 MB/s
Check no virtual servers are running with the same ID...
Determining disk size...
Determining swap size...
Creating logical volumes...
Creating config file...
Restoring backup. This may take a while...
Booting restored virtual server...
Cleaning up...
Restore complete.

Thats it. Vps restored.

Sunday, October 2, 2011

Error: Kernel image does not exist: /boot/solus-vmlinuz

You may get this error while starting a xen vps.

[root@test ~]# xm create /home/xen/vm302/vm302.cfg
Using config file "/home/xen/vm302/vm302.cfg".
Error: Kernel image does not exist: /boot/solus-vmlinuz

Solution:

[root@test~]# php /usr/local/solusvm/includes/xenkernel.php
Making SolusVM initrd...
Setting kernel links...
Kernel setup completed.
[root@test~]#

Now try:

[root@test~]# xm create /home/xen/vm302/vm302.cfg
Using config file "/home/xen/vm302/vm302.cfg".
Started domain vm302
[root@test~]#

Tuesday, September 27, 2011

Error: httpd is disabled via /etc/apachedisable please re-enable to continue

You may get this error while running the script easyapache

!! 'httpd' is disabled via '/etc/apachedisable', please re-enable to continue. !!

Solution:
Enable httpd in Service Manager

Steps:
Login to WHM

Main >> Service Configuration >> Service Manager
Check the boxes for httpd
Save it [bottom in page]
Now try again.

See the following images if confused.

Main >> Service Configuration >> Service Manager


Check the boxes for httpd


After checking

Now run easypache again

Monday, September 26, 2011

date: cannot set date: Operation not permitted openvz

This post explains how to solve the following error while setting the time in a openvz container vps.

Error:
date: cannot set date: Operation not permitted

Reason:
Capability not set for the vps

Soultion:

On Openvz node:

Stop the vps
[root@test ~]# vzctl stop 9851

set the parameter

[root@test ~]# vzctl set 9851 --save --capability sys_time:on
Saved parameters for CT 9851

Start the vps
[root@test ~]# vzctl start 9851

Enter into the vps
[root@test8 ~]# vzctl enter 9851
entered into CT 9851
[root@abc /]#

check date
[root@abc /]# date
Fri Sep 16 00:39:09 CST 2011

Change date
[root@abc /]# date -s "Tue Sep 27 00:39:09 CST 2011"
Tue Sep 27 00:39:09 CST 2011

check date again
[root@abc /]# date
Tue Sep 27 00:39:19 CST 2011

Thats it. Date has been changed. 



Recommended Reading

1. Practical Guide to Linux Commands, Editors, and Shell Programming, A (2nd Edition)
2. UNIX and Linux System Administration Handbook (4th Edition)
3. Linux All-in-One For Dummies
4. Introduction to the Command Line (Second Edition): The Fat Free Guide to Unix and Linux Commands

Tuesday, September 20, 2011

Error: Device (vbd) could not be connected /etc/xen/scripts/block failed error detected

You may get this error while starting a xen vps


[root@test ~]# xm create /home/xen/vm854/vm854.cfg
Using config file "/home/xen/vm854/vm854.cfg".
Error: Device 5632 (vbd) could not be connected. /etc/xen/scripts/block failed; error detected.

Check the hotplug log

[root@test ~]# tail /var/log/xen/xen-hotplug.log
xenstore-read: couldn't read path backend/vbd/176/5632/node
Nothing to flush.
losetup: could not find any free loop device
xenstore-read: couldn't read path backend/vbd/177/5632/node
Nothing to flush.
losetup: could not find any free loop device
xenstore-read: couldn't read path backend/vbd/178/5632/node
losetup: could not find any free loop device
Nothing to flush.
xenstore-read: couldn't read path backend/vbd/179/5632/node

See the reason
losetup: could not find any free loop device


it says there is no free loop back devices. Your vps might be at present mounted with a cd-rom. but as there is no free loop device it cant mount it and start vps. Unmount the cdrom and start the vps again. It will work.

Monday, September 19, 2011

changing the RAM of Domain-0 in xen

This post explains how to set or change Domain-0 RAM allocation. This is a dynamic method so I'm not sure it will survive reboot.

Current usage

[root@test ~]# xm list
Name                                      ID Mem(MiB) VCPUs State   Time(s)
Domain-0                                   0    19002     8 r----- 331242.1
vm649                                     27     1007     2 r-----  81706.6
vm652                                     20     2007     2 -b---- 156137.8
vm770                                     26     2007     2 r----- 230305.3

Now setting the Domain-0 RAM to 4GB

[root@test ~]# xm mem-set 0 4096

After changing the RAM of Domain-0

[root@test ~]# xm list
Name                                      ID Mem(MiB) VCPUs State   Time(s)
Domain-0                                   0     4096     8 r----- 331416.8
vm649                                     27     1007     2 r-----  82261.6
vm652                                     20     2007     2 -b---- 156240.8
vm770                                     26     2007     2 r----- 230515.7
[root@test ~]#

There is also another method which edits grub.conf
#vi /etc/grub.conf

title CentOS (2.6.18-238.19.1.el5xen)
        root (hd0,0)
        kernel /boot/xen.gz-2.6.18-238.19.1.el5 dom0_mem=4096
        module /boot/vmlinuz-2.6.18-238.19.1.el5xen ro root=LABEL=/ rhgb quiet
        module /boot/initrd-2.6.18-238.19.1.el5xen.img
It needs rebooting the system

clearing arp cache in linux

Address Resolution Protocol (also known as ARP) is one of the effective ways for searching the address of a host’s hardware(Ethernet). Sometimes wrong arp cache will make problems. You can clear all arp cache using following commands.

how to see current arp cache
root@cpaneltest [~]# arp -n
Address HWtype HWaddress Flags Mask Iface
192.168.1.1 ether 00:25:5E:1F:7A:BE C eth0
192.168.1.2 ether 6C:F0:49:C5:BF:6A C eth0
192.168.1.4 ether 6C:F0:49:C5:BF:26 C eth0
root@cpaneltest [~]#

Clearing arp cache with verbose
root@cpaneltest [~]# ip -s -s neigh flush all
192.168.1.1 dev eth0 lladdr 00:25:5e:1f:7a:be ref 17 used 28/27/81 REACHABLE
192.168.1.2 dev eth0 lladdr 6c:f0:49:c5:bf:6a ref 2 used 64/64/20 STALE
192.168.1.4 dev eth0 lladdr 6c:f0:49:c5:bf:26 ref 4 used 92/3/0 REACHABLE

*** Round 1, deleting 3 entries ***
*** Flush is complete after 1 round ***

current entries
root@cpaneltest [~]# arp -n
Address HWtype HWaddress Flags Mask Iface
192.168.1.1 (incomplete) eth0
192.168.1.2 (incomplete) eth0
192.168.1.4 ether 6C:F0:49:C5:BF:26 C eth0
root@cpaneltest [~]#

You can also delete particular arp entries using following command
root@cpaneltest [~]# arp -d 192.168.1.1
root@cpaneltest [~]# arp -d 192.168.1.2

Adding a static arp entry
root@cpaneltest [~]# arp -s 192.168.1.10 00:00:93:12:04:57

This will answer ARP requests for 10.0.0.2 on eth0 with the MAC address for eth1.
 #arp -i eth0 -Ds 10.0.0.2 eth1 pub

Delete the ARP table entry for 10.0.0.1 on interface eth1. This will match published proxy ARP entries and permanent entries.
#arp -i eth1 -d 10.0.0.1


Recommended Reading

1. Practical Guide to Linux Commands, Editors, and Shell Programming, A (2nd Edition)
2. Understanding the Linux Virtual Memory Manager
3. UNIX and Linux System Administration Handbook (4th Edition)

Thursday, September 15, 2011

How to disable mod_security using .htaccess

This post explains how to disable mod_security using .htaccess for one domain. You may have problem with mod_security if you are using certain plugins, XMLRPC, wordpress, etc.


Go to your public_html directory of the desired domain and in .htaccess file add the following lines.


#vi .htaccess


<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>


Thats it. Now mod_security is disabled.

Wednesday, September 14, 2011

How to enable passive ftp in vsftpd

This post explains how to configure or enable passive ftp in vsftpd and open the ports in csf firewall. This is configuring in centos linux. It will also work in other linux distors.

# vi /etc/vsftpd/vsftpd.conf

##Add the following lines

pasv_enable=YES
pasv_promiscuous=NO
port_enable=YES
port_promiscuous=NO
pasv_max_port=65534
pasv_min_port=49152

Save the file.

Tuesday, September 13, 2011

route add command in linux

You can add a routing rule in a linux system as follows. It will work all linux systems including redhat, centos, ubuntu and debian

Syntax
route add -net network_id netmask subnet_mask gw gateway_ip dev device_name

root@cpaneltest [~]# route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.10 dev eth0

Checking the rule
root@cpaneltest [~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.51    0.0.0.0         255.255.255.255 UH    0      0        0 eth0
192.168.1.52    0.0.0.0         255.255.255.255 UH    0      0        0 eth0
192.168.1.0     192.168.1.10    255.255.255.0   UG    0    0    0 eth0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth0
0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 eth0

You can delete the above rule as follows
root@cpaneltest [~]# route del -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.10 dev eth0

Checking again
root@cpaneltest [~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.51    0.0.0.0         255.255.255.255 UH    0      0        0 eth0
192.168.1.52    0.0.0.0         255.255.255.255 UH    0      0        0 eth0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth0
0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 eth0
root@cpaneltest [~]#

Wednesday, September 7, 2011

nameserver ips showing old ips in cpanel

Even after changing the nameserver ips, the nameserver ips in WHM may show old ips. This post explains how to change the nameserver ip addresses in a cpanel server.
You can change this as follows:

First edit the /etc/nameserverips

root@test[~]# cat /etc/nameserverips
IP_address1=ns1.domain.tld
IP_address2=ns2.domain.tld
root@test[~]#

Now edit /var/cpanel/nameserverips.yaml

root@test[~]# cat /var/cpanel/nameserverips.yaml
---
ns1.domain.tld:
  IP_address1: 1
  count: '3'
  zones: ns1.domain.tld,domain.tld,ns2.domain.tld
ns2.domain.tld:
  IP_address2: 1
  count: '3'
  zones: ns1.domain.tld,domain.tld,ns2.domain.tld
root@test[~]#

Names of zones files can be found in /etc/named.conf
Now restart the cpanel
root@test[~]# /etc/init.d/cpanel restart

Thats it. It should effect the changes on WHM

Resetting kloxo password

In case if you forgot your kloxo admin password, you have to reset the password for login again. This post explains how to reset the password for admin for kloxo lxadmin control panel.

#cd /usr/local/lxlabs/kloxo/httpdocs
#/usr/bin/lphp.exe ../bin/common/resetpassword.php master PASSWORD

Thats it. Now the admin password is changed to PASSWORD

Tuesday, September 6, 2011

vzctl start Container already locked

While starting the openvz container you may get an error like this
Error:
Container already locked

You wont be able to start, restart or stop the container. It is because the container is locked.

Solution:
Delete the /vz/lock/VEID.lck file (where VEID is the number of your VPS).
vzctl chkpnt VEID --kill

Now start the vps.
vzctl start VEID

hypervm adding ip to /etc/hosts.deny

You may get this error while sshing to a ip
ssh_exchange_identification: Connection closed by remote host

It could be because of many reasons. One of them is hypervm adding the ips to /etc/hosts.deny file.
It will add the ip again if you remove it from /etc/hosts.deny.

The solution is after removing the ip, run this command

chattr +i /etc/hosts.deny

Sunday, September 4, 2011

jail environment using vsftpd

This post explains how to limit users to only their home directory in vsftpd ftp demon so that the users will be in a jail environment and he can not change to other directories.

Open the vstpd configuration file
vi /etc/vsftpd/vsftpd.conf

Add the following variable

chroot_local_user=YES

Restart the vsftpd service
/etc/init.d/vsftpd restart

Now on wards when the user logs in via ftp he gets into his home directory. But he cannot change the directory out of it. This is known as jailed environment. 

Backing up and restoring mysql databases

Tacking the back up of a database
mysqldump  -u username -ppassword  database_name > database_name.sql
For example
mysqldump  -u root -pabc123 horde > horde.sql

Restoring the database
mysql database_name < database_name.sql
For example
mysql horde < horde.sql

Restart the mysql
/etc/init.d/mysqld restart

Saturday, September 3, 2011

/usr/bin/ld: cannot find -lglut


Error:
/usr/bin/ld: cannot find -lglut
collect2: ld returned 1 exit status
make: *** [etr] Error 1

Solution:
apt-get install freeglut3-dev

Listing installed packages in ubuntu and centos


You can list installed packages in ubuntu or debian system using following command
#dpkg --get-selections

You can search whether a package is available or not using
#apt-cache search package_name

You can list installed packages in centos or redhat based system using following command
#yum list installed

All the files installed and available
#yum list all
#yum list package_name

Segmentation faultsts... 0% in ubuntu

You may get this error while using apt-get or aptitude


root@test# apt-get  install libogg
Segmentation faultsts... 0%

Reason:
Files got corrupted in /var/cache/apt

solution:
#rm /var/cache/apt/*.bin

Then update aptitude
#aptitude update

If you are using apt-get
#apt-get update

Sometimes you may need a reboot.

Installing phpmyadmin on ubuntu

This post explains how to install and configure phpmyadmin on ubuntu or debian systems.

Install phpmyadmin using apt-get
#apt-get install phpmyadmin

Copy the phpmyadmin apache configuration file to /etc/apache2/conf.d/
#cp /etc/phpmyadmin/apache.conf /etc/apache2/conf.d/
Or
You can include the configuration file in apache2.conf by adding this line to it
Include /etc/phpmyadmin/apache.conf

No restart apache
#/etc/init.d/apache2 restart

Sometimes you may have to add a blowfish secret to accept cookies.
#vi /var/lib/phpmyadmin/blowfish_secret.inc.php
$cfg['blowfish_secret'] = 'a8b7dafdferHJHJ^&U^45776TIUuiYc6d';

error: 'PIX_FMT_RGBA32' undeclared

You may get this error while installing ffmpeg.
The solution is
#vi /usr/local/src/ffmpeg-php-0.6.0/ffmpeg_frame.c
and

:%s/PIX_FMT_RGBA32/PIX_FMT_RGB32
The thing is you have to replace
 “PIX_FMT_RGBA32″ by  “PIX_FMT_RGB32″ in the file ffmpeg_frame.c
save the file and you can proceed with installation.

Saturday, August 20, 2011

drop or clear cache in linux

Many times you may find the system is running out of memory. When checked you can see lots of memory is assigned to buffers and caches.Allocating lots of memory to buffers and caches is not necessary. If you are running mysql and oracle like softwares, they have their own buffers and caches. So mostly you can free or drop this buffers and caches. This post explains how to drop caches in Linux. Also the entry for sysctl.conf so that it will remember the action.

According to the linux documentations, the variable drop_caches defined as, Writing to this will cause the kernel to drop clean caches, dentries and inodes from memory, causing that memory to become free.

To free pagecache:
echo 1 > /proc/sys/vm/drop_caches
To free dentries and inodes:
echo 2 > /proc/sys/vm/drop_caches
To free pagecache, dentries and inodes:
echo 3 > /proc/sys/vm/drop_caches

As this is a non-destructive operation and dirty objects are not freeable, the user should run `sync' first.
So the command to drop all caches are,
#sync; echo 3 > /proc/sys/vm/drop_caches

Or you can specify this in /etc/sysctl.conf
#echo "vm.drop_caches = 3" >> /etc/sysctl.conf
Now reload sysctl.conf
#sysctl -p

Thursday, August 18, 2011

Installing nagios with nrpe to monitor remote hosts

This post explains installing nagios with nrpe to monitor remote hosts. Nagios is one of the most used monitoring tools today.

On Remote client server to be monitored:

Create the user nagios and set password:
# useradd nagios
# passwd nagios

Download the nagios plugin from http://www.nagios.org/download/plugins

# mkdir -p /opt/Nagios/Nagios_Plugins
# cd /opt/Nagios/Nagios_Plugins
# cd ..
# tar xzf nagios-plugins-1.4.15.tar.gz
# cd nagios-plugins-1.4.15

Compiling and Installing:
Pere-requisite openssl-devel package.
#rpm -q openssl-devel
if not installed, then
# yum -y install openssl-devel

Configuring: 

# cd /opt/Nagios/nagios-plugins-1.4.15
# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
If the configure struck with ICMP ping check run as below
./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-ping-command=ping
# make
# make install

Changing permissions:
# chown nagios.nagios /usr/local/nagios
# chown -R nagios.nagios /usr/local/nagios/libexec

Installing xinetd super demon if not installed
# yum install xinetd

Now downloading and installing nrpe demon from

# mkdir -p /opt/Nagios/Nagios_NRPE
# cd /opt/Nagios/Nagios_NRPE
#cd ..
# tar -xzf nrpe-2.12.tar.gz
# cd nrpe-2.12

Compiling and Configuring nrpe
# cd /opt/Nagios/nrpe-2.12
# ./configure 
# make all
# make install-plugin
# make install-daemon
# make install-daemon-config
# make install-xinetd

Add Nagios Monitoring server to the “only_from” directive
# vi /etc/xinetd.d/nrpe
only_from =  

Add entry for nrpe daemon to services
# vi /etc/services
nrpe      5666/tcp    # NRPE

Restart Xinetd and set chkconfig on
# chkconfig xinetd on
# service xinetd restart
Checking whether NRPE daemon is running and listening on port 5666:
# netstat -at |grep nrpe
tcp    0    0 *:nrpe    *.*    LISTEN

Open Port 5666 on Firewall
if using csf add 5666 to TCP_IN and TCP_OUT in /etc/csf/csf.conf and restart as
#csf -r

And add the following lines to /usr/local/nagios/etc/nrpe.cfg

command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda
command[check_mem]=/usr/local/nagios/libexec/check_mem 85 95


Nagios server  Setup (mail nagios server)
Downloading and installing nrpe demon from

# mkdir -p /opt/Nagios/Nagios_NRPE
# cd /opt/Nagios/Nagios_NRPE
#cd ..
# tar -xzf nrpe-2.12.tar.gz
# cd nrpe-2.12

Compiling and Configuring nrpe
# cd /opt/Nagios/nrpe-2.12
# ./configure 
# make all
# make install-plugin

Check NRPE daemon is functioning from nagios server. 
# /usr/local/nagios/libexec/check_nrpe -H
Output:
NRPE v2.12

Check whether it is defined or not.
# vi /usr/local/nagios/etc/objects/commands.cfg
define command{
        command_name check_nrpe
        command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
        }

If you want to add a few ips then define them in hosts.cfg
and make a hostgroup in hostgroups.cfg with all the needed users as members
and now in services.cfg and the services you want and specidy hostgroup name as follows

### CPU LOAD/Load Average ###
define service{
        use                             basic-service
        hostgroup_name                  customer1
        contact_groups                  admins
        service_description             CPU LOAD
        check_command                   check_nrpe!check_load
}

### Disk Usage ###
define service{
        use                             basic-service
        hostgroup_name                  customer1
        contact_groups                  admins
        service_description             CHECK DISK
        check_command                   check_nrpe!check_disk
}

### RAM Usage ###
define service{
        use                             basic-service
        hostgroup_name                  customer1
        contact_groups                  admins
        service_description             CHECK MEM
        check_command                   check_nrpe!check_mem

Check the configuration  as :
#/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Now restart
#/etc/init.d/nagios restart

Wednesday, August 17, 2011

Websites each system admin should know

System administrators will have to do a lot of stuffs by themselves. But there are a lot of online tools which are helpful and they save a lot of time. But most of the administrators don't know them. Here is a list I know of. If you know any please comment with their use, I'll include them.

To know your public ip. It shows location and other details too.
http://whatismyipaddress.com/

For checking nameservers, mx record, A record, PTR record and other DNS details.
http://www.intodns.com/

Example:
http://www.intodns.com/randeeppr.me

For checking the accessibility of your ip address or url. It gives ping results from many parts of the world.
http://www.just-ping.com/

For checking the domain details such as owner of the domain and contact details.
http://www.whois.sc/

Example:
http://whois.domaintools.com/randeeppr.me

To check whether your ip is blacklisted or not
http://www.mxtoolbox.com/blacklists.aspx

To check the loading time of the url from different parts of world
http://alertra.com/spotcheck_do

To check the domain propagation, NS, MX, A Record etc from different parts of the world at the moment.
http://www.whatsmydns.net/

To check the cpanel license is expired or not
http://www.cpanel.net/apps/verify/

To paste the error log and make a link to exchange
http://pastebin.com/

To encrypt a string with md5 algorithm
http://md5-encryption.com/

To decrypt a string with md5 algorithm
http://md5-decrypter.com/

To check the validity and other details of SSL certificates
http://www.digicert.com/help/

Tuesday, August 16, 2011

How to see history with time in linux

First set the variable HISTTIMEFORMAT as given below.
root@cpaneltest [~]# HISTTIMEFORMAT="%d/%m/%y %T "

Now checking the variable value :
root@cpaneltest [~]# echo $HISTTIMEFORMAT
%d/%m/%y %T

root@cpaneltest [~]#
Now run the command history.
root@cpaneltest [~]# history

   21  16/08/11 00:39:47 for i in $(cat ip) ; do echo $i; done
   22  16/08/11 00:39:47 for i in $(cat ip) ; do ping -t1 $i; done



How to change the values of numproc and privvmpages

You may get memory over consume errors in openvz vps'. Error can be fork error. For Eg:
fork : unable to fork new process

You can confirm the error is because of memory overconsumption by checking the following command.

root@cpanel [/]# cat /proc/user_beancounters
Version: 2.5
       uid  resource        held            maxheld          barrier           limit                                                   failcnt
      101:  kmemsize   21335253   359571636   9223372036854775807  9223372036854775807   0
            lockedpages     0                   10              4925440              4925440                                     0
            privvmpages   235064           7784716             10000000             10000000                45752
            shmpages       24                 1320  9223372036854775807  9223372036854775807            0
            dummy            0                    0                    0                    0                                                   0
            numproc         98                 1500                 4096                 5120                            1992344
            physpages     123667              4965574                    0  9223372036854775807                    0
            vmguarpages          0                    0              9820160  9223372036854775807                    0
            oomguarpages   23668            4969178              9820160  9223372036854775807             0
            numtcpsock     260              3726  9223372036854775807  9223372036854775807            0
            numflock      7                  182  9223372036854775807  9223372036854775807                 0
            numpty               1                    2                  255                  255                                          0
            numsiginfo              0                 1024                 1500                 2000                               905
            tcpsndbuf      13916424   119625936  9223372036854775807  9223372036854775807        0
            tcprcvbuf      4297032             61066072  9223372036854775807 223372036854775807      0
            othersockbuf    120688     5234368  9223372036854775807  9223372036854775807           0
            dgramrcvbuf     0     13080  9223372036854775807  9223372036854775807                    0
            numothersock   104     1519  9223372036854775807  9223372036854775807                    0
            dcachesize    2743654        16510107  9223372036854775807  9223372036854775807         0
            numfile   7077                72257  9223372036854775807  9223372036854775807                    0
            dummy                           0                    0                    0                    0                    0
            dummy                           0                    0                    0                    0                    0
            dummy                           0                    0                    0                    0                    0
            numiptent                   43                   43  9223372036854775807  9223372036854775807      0
root@cpanel [/]#

uid 101 means the veid of the vps. 
The main parameters are explained below:

held - how many kernel level threads you are using at the time you cat the file
maxheld - how many is the maximum number of kernel level threads you have had
barrier - guaranteed amount of resources your vps is allocated
limit - physical limit your vps can consume
failcnt - also known as fail count or the number of times your vps has hit the specified limit

You can increase the value of these parameters by editing the configuration file of the vps on the node server. 
# vi /etc/vz/conf/101.conf

#NUMPROC="1500:1800"
NUMPROC="4096:5120"

#PRIVVMPAGES="7772160:7784660"
PRIVVMPAGES="10000000:10000000"

#NUMSIGINFO="1024:1024"
NUMSIGINFO="1500:2000"

Restart the vps after that. 
# vzctl restart 101

Saturday, August 13, 2011

How to tackle ddos and script to block the ips

You can check whether the attack is coming from a single ip using the following commands.
For normal server :
tcpdump -l -n -i eth0
If it is a vps:
tcpdump -l -n -i venet0:0
If the attack is from many ips and its nature is synflood you can know the ips and the no.of connections to them using the following command.
netstat -anp |grep 'tcp\|udp' | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
Block the ips that are having more connections.


If you want you can use the following script to block the ips causing ddos.




#!/bin/bash

netstat -anp |grep 'tcp\|udp' | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n > test.out
for i in `cat test.out | awk '{print $2}' `
do
 {
 if [ "$i" != "127.0.0.1" ] && [ `cat test.out | grep $i | awk '{print$1}'` -gt 35 ] && [  "$i" != "0.0.0.0" ]
 then
 iptables -A INPUT -s $i -j DROP
 echo "Writing the rule :iptables -A INPUT -s $i -j DROP"
 fi
 }
done
The script is tested on centos system and it will work in other distros also.

How to enable tun tap and iptables nat on a openvz vps

When we are using vps with vpn softwares such as openvpn, we need to enable tun tap and nat modules for them. Here we discuss how to enabled tun tap modules in openvz contailers.

Checking whether the module is enabled or not :
#lsmod | grep tun
If it is not there:-
#modprobe tun

Now Enabling Tun/Tap :
#vzctl set [VEID] --devices c:10:200:rw --save
#vzctl stop [VEID]
#vzctl set [VEID] --capability net_admin:on --save
#vzctl start [VEID]

Now enabling NAT for iptables :
#vzctl stop [VEID]
#vzctl set [VEID] --iptables ipt_REJECT --iptables ipt_tos --iptables ipt_TOS --iptables ipt_LOG --iptables ip_conntrack --iptables ipt_limit --iptables ipt_multiport --iptables iptable_filter --iptables iptable_mangle --iptables ipt_TCPMSS --iptables ipt_tcpmss --iptables ipt_ttl --iptables ipt_length --iptables ipt_state --iptables iptable_nat --iptables ip_nat_ftp --save
#vzctl start [VEID]

Thats it Enjoy :)

Thursday, August 11, 2011

error SoftException Mismatch between target UID (99) and UID (32008) of file /usr/local/nagios/share/index.php


[error] [client x.x.x.x] SoftException in Application.cpp:422: Mismatch between target UID (99) and UID (32008) of file "/usr/local/nagios/share/index.php"

You may get this error while installing nagios on a cpanel server. It is because of the suphp.
Solution:
Disable suphp using the script /scripts/easyapache

Error logs can be found at :
tail -f /usr/local/apache/logs/suphp_log
tail -f  /usr/local/apache/logs/error_log

Wednesday, August 3, 2011

cpanel error : To add, edit, or remove IPs, please contact your server administrator.

Add the ip to the file /etc/ips as shown below.

root@cpanel [~]# cat /etc/ips
ip:netmask:broadcast
192.168.1.244:255.255.255.255:192.168.1.255
root@cpanel [~]#

Restart the ipalias service
root@cpanel [~]# /etc/init.d/ipaliases restart
Bringing up venet0:0:cp1                                   [  OK  ]
Routing 192.168.1.244                                     [  OK  ]
root@cpanel [~]#

Tuesday, August 2, 2011

How to whitelist an ip address using csf

This post explains how to whitelist an ip address using csf firewall.
For example your ip address is 192.168.0.55  then

#csf -a 192.168.0.55

Restart if needed
#csf -r

How to whitelist a network using csf

This post explains how to whitelist a network using csf firewall.
For example your ip address is dynamic 192.168.0.55 and keep changing after 192.168 then

#csf -a 192.168.0.0/24

Restart if needed
#csf -r



Friday, July 29, 2011

How to test phpmail()

Create a php script as below.

root@cpanel [~]# cat test.mail
$to      = 'username@gmail.com';
$subject = 'testing phpmail';
$message = 'hello';
$headers = 'From:yourname' . "\r\n" .
    'Reply-To: yourname' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>
root@cpanel [~]#
Now execute the command as below to send mail
root@cpanel [~]# php test.mail
Thats it. Check your inbox. If everything is it, it'll be delivered successfully.

preventing root user or account from ssh

This post explains how to prevent root user to ssh directly to a linux box. This is tested in redhat rhel5 system and works on almost other linux distros.

Open the ssh configuration file
# vi /etc/ssh/sshd_config
Changethe following line
PermitRootLogin yes
To
PermitRootLogin no

Now restart the ssh demon.
/etc/init.d/sshd restart

Thursday, July 28, 2011

Allowing root account to ssh

This post explains how to allow root user to ssh directly to a linux box. This is tested in redhat rhel5 system and works on almost other linux distros.

Open the ssh configuration file
# vi /etc/ssh/sshd_config

Changethe following line
PermitRootLogin no
To
PermitRootLogin yes

Now restart the ssh demon.
/etc/init.d/sshd restart

Wednesday, July 27, 2011

How to enable brute force attack on exim

This post explains how to disable brute force attack or multiple login attempts with wrong passwords on exim using csf / lfd

open csf.conf

vi /etc/csf/csf.conf


LF_TRIGGER = "0"
LF_POP3D = "10"
LF_IMAPD = "10"
LF_POP3D_PERM ="180"

Restart csf
#csf -r

How to enable brute force detection for directadmin

This post explains how to enable brute force detection for directadmin or how to prevent multiple login attempts with wrong passwords.

open directadmin.conf

#Brutforce detection is enabled and the count is set to 5.
bruteforce=1
brutecount=5

if more than 5 attempt is done, then the ip will be added to the black list file. It will never be cleared (unless manually).
/usr/local/directadmin/data/admin/ip_blacklist

Tuesday, July 26, 2011

How to change the password of the openvz vps

Here the steps to change the password of the openvz vps or virtual private server from the command line.


[root@test ~]# vzlist -a | grep 192.168.0.100
       462        245 running   192.168.0.100    abc.xyx.com

Always take back up of configuration file before you do anything
[root@test ~]# cp /etc/sysconfig/vz-scripts/462.conf{,bfchpass}

Syntax
vzctl set VE_ID --userpasswd root:[newpasswd] --save

[root@test ~]# vzctl set 462 --userpasswd root:abc123$ --save
Changing password for user root.
passwd: all authentication tokens updated successfully.
Saved parameters for CT 462
[root@test ~]#

Sunday, July 10, 2011

Error: Device 0 (vif) could not be connected. Hotplug scripts not working xen restart solved

You may get this error while restarting the xen vps or virtual server.
It wont start if you are restarting it from front end like solusvm.

So start form the backend.
[root@xen ~]# xm create /home/xen/vm130/vm130.cfg
Using config file "/home/xen/vm130/vm130.cfg".
Error: Device 0 (vif) could not be connected. Hotplug scripts not working.

If you get any hotplug error then check the hotplug error log.
[root@xen ~]#  tail /var/log/xen/xen-hotplug.log
Nothing to flush.

can't add vifvm130.0 to bridge eth0: Operation not supported
Nothing to flush.
can't add vifvm130.0 to bridge eth0: Operation not supported
Nothing to flush.
can't add vifvm130.0 to bridge eth0: Operation not supported
[root@xen ~]#

Now you know the error. Open the configuration file.
vi /home/xen/vm130/vm130.cfg

See the bridge device name was given
vif        = ['type=ioemu, ip=178.162.239.188, vifname=vifvm130.0, mac=00:16:3e:50:e1:8c, bridge=eth0']

Change it to as follows.
vif        = ['type=ioemu, ip=178.162.239.188, vifname=vifvm130.0, mac=00:16:3e:50:e1:8c']
Now it works. Have fun.

(network.c.336) SSL: error:00000000:lib(0):func(0):reason(0) Kloxo restart error solved

Error :
[root@test /]# /etc/init.d/kloxo restart
Stopping kloxo: Waiting for the process to die.....
Stopped kloxo
Starting kloxo: 11
2011-07-09 19:01:30: (network.c.336) SSL: error:00000000:lib(0):func(0):reason(0)
mysqld (pid 1557) is running...
Started kloxo
[root@test /]#

Solution

Remove the openssl with nodeps option

rpm -e --nodeps openssl

Download lower version
http://download.clearfoundation.com/clearos/enterprise/5.1/System/RPMS/openssl-0.9.8e-12.el5_4.1.i686.rpm
rpm -ivh openssl-0.9.8e-12.el5_4.1.i686.rpm

Now restart Kloxo
/etc/init.d/kloxo restart

[root@test /]# /etc/init.d/kloxo restart
Stopping kloxo: ../bin/common/function.sh: line 28:  7239 Terminated              $__path_server_exe $string >/dev/null 2>&1
Waiting for the process to die.....
Stopped kloxo
Starting kloxo: 11
mysqld (pid 1557) is running...
Started kloxo
[root@test /]#

Friday, July 8, 2011

How to enable user authentication in squid proxy

This post explains how to enable user authentication on a squid proxy. 

Suppose you have an ip 1.2.3.4 to be enabled for a user test_user 

Syntax :
acl acl_name proxy_auth username REQUIRED
tcp_outgoing_address ipaddress acl_name
http_access allow acl_name

eg:-
acl auth_user2 proxy_auth test_user REQUIRED
tcp_outgoing_address 1.2.3.4 auth_user2
http_access allow auth_user2

And also you can create passwords for the users by using the following command
#htpasswd passwordfile username
eg:-
#htpasswd /etc/squid/squidpasswd test_user
New password: *type the password here
Re-type new password: *retype the password here

Save the squid configuration file and restart the service. 

Tuesday, July 5, 2011

How to create a new vps or virtual server in openvz using vzctl

Here is the steps.


First go to the following directory which has the templates.
cd /vz/template/cache/

Now create the vps with VEID 10 with template for debian 64  bit ( you can choose the one you want )
vzctl create 10 --ostemplate debian-5.0-x86_64

Enabling onboot
vzctl set 10 --onboot yes --save

Adding the default ip
vzctl set 10 --ipadd IP_ADDRESS --save

Setting name servers
vzctl set 10 --nameserver 8.8.8.8 --save
vzctl set 10 --nameserver 8.8.4.4 --save

Setting the diskspace. Here 50Gb
vzctl set 10 --diskspace 50G --save

Setting the RAM and Bust RAM
vzctl set 10 --vmguarpages 4G:8G --save

Starting vps
vzctl start 10

Setting password for the root user of the vps
vzctl exec 10 passwd

Logging in
vzctl enter 10