Saturday 15 December 2012

Network Traffic Monitoring Tool

Network Traffic Monitoring  Tool:-
Monitoring Network Traffic:-
VNstat:-
VNstat is a console-based network traffic monitor for Linux and BSD that keeps a log of network traffic for the selected interface(s). It uses the network interface statistics provided by the kernel as information source. This means that VNstat won't actually be sniffing any traffic and also ensures light use of system resources. With VNstat you are able to keep a log of all incoming and outgoing traffic which will be logged by Minute,Hour,Day,Month,Year.

IPTraf:-
IPTraf is a console-based network statistics utility for Linux. It gathers a variety of figures such as TCP connection packet and byte counts, interface statistics and activity indicators, TCP/UDP traffic breakdowns, and LAN station packet and byte counts.

How to install these tools

CentOS/RHEL:-
Steps:-

 1)      Download the source and unpack the source:-
 [root@linuxnotes~] # cd

  [root@linuxnotes~] # wget http://humdi.net/vnstat/vnstat-1.11.tar.gz
2)      Extract vnstat -1.11
 [root@linuxnotes~] # tar -xvf  vnstat-1.11.tar.gz
3)      [root@linuxnotes~]  # ls
4)        [root@linuxnotes~] # cd vnstat-1.11
5)        [root@linuxnotes~] # ls
6)        [root@linuxnotes~] #  vi  INSTALL (Please  follow the all steps )
7)        [root@linuxnotes~] # make
8)        [root@linuxnotes~] # make install

**Note:- Now that the package is installed we need to make it start, and automatically restart on boot.


9)       [root@linuxnotes~] #  cp ~/vnstat-1.11/examples/init.d/redhat/vnstat /etc/init.d/vnstat
10)    [root@linuxnotes~] # chmod +x /etc/init.d/vnstat        
11)   [root@linuxnotes~] # /etc/init.d/vnstat status
12)   [root@linuxnotes~] #  /etc/init.d/vnstat start
13)    [root@linuxnotes~] # /etc/init.d/vnstat status
14)   [root@linuxnotes~]  # cd /etc/init.d/                                              
15)    [root@linuxnotes~] # chkconfig --add vnstat                                           // To add  vnstat in chkconfig
16)    [root@linuxnotes~]  # chkconfig vnstat on                                                 

Setup VNstat  monitoring  interfaces:- 

17  Public Interface
      [root@linuxnotes~] # vnstat -u -i eth0

18 # Private Interface
      [root@linuxnotes~] #  vnstat -u -i eth1

19  [root@localhost /]# yum search iptraf
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * atomic: www7.atomicorp.com
 * base: mirrors.hns.net.in
 * extras: mirrors.hns.net.in
 * updates: mirrors.hns.net.in
========================================================================= N/S Matched: iptraf ==========================================================================
iptraf.i686 : A console-based network monitoring utility

  Name and summary matches only, use "search all" for everything.

20 [root@linuxnotes~] # yum install iptraf.i686.

21 [root@linuxnotes~] #  vnstat

22 [root@linuxnotes~]  vnstat -h   

23 [root@linuxnotes~]  vnstat -m

24 [root@linuxnotes~] #  iptraf -g

Friday 14 December 2012

Mysql ERROR 1045 (28000) in centos


To resolve Mysql "ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) in Centos"

Please Refer the following Steps:-

Solution-:

 [root@linuxnotes~]# /etc/init.d/mysqld stop
 [root@linuxnotes~]# mysqld_safe --skip-grant-tables &
 [root@linuxnotes~]# mysql -u root
mysql> use mysql;
mysql> update user set password=PASSWORD("newrootpassword") where User='root';
mysql> flush privileges;
mysql> quit

Note:-

Before restarting the mysql service first kill all mysqld related process and then start mysqld service.

 [root@linuxnotes~]# /etc/init.d/mysqld stop
 [root@linuxnotes~]# /etc/init.d/mysqld start

Sunday 11 November 2012



To check  any type of process status and to count the no of process are currently running :-
#!/bin/bash
echo "To  check any type of processe status"
ps aux | grep $1 | grep -v "\(root\|grep\)" | wc -l

Run it by following command :-
sh cntproc.sh "process name"
examaple:- [root@localhost scriptexamples.sh]# sh cntproc.sh  sendmail
To count the currently how many apache processes are  running
1



All Service Status


To check all Service Status:-
#!/bin/bash
echo "To check status of all services are running or not "
service --status-all|grep "\(run\)"
service --status-all|grep "\(not run\)"
sh allservstatus.sh |awk '{ print $1 }'

Monday 5 November 2012


To  check   user account is lock or not:-
First create user account by using following command:-
Useradd username
Passwd  “password”

Example:-

 [root@linuxnotes~]# useradd swapnil

[root@linuxnotes~]# passwd swapnil

 Changing password for user swapnil.
 New password:*******
 BAD PASSWORD: it is based on a dictionary word
 BAD PASSWORD: is too simple
 Retype new password:********
 passwd: all authentication tokens updated successfully.

 [root@linuxnotes~]#

 Command to lock user account :-

[root@linuxnotes~]# passwd -l swapnil
Locking password for user swapnil.
passwd: Success

To test useraccount is lock or not :-
login as: swapnil
swapnil@linuxnotes.co.in password:
Access denied
swapnil@linuxnotes.co.in password:

To unlock the useraccount:-
[root@linuxnotes~]# passwd -u swapnil
Unlocking password for user swapnil.
passwd: Success
[root@linuxnotes~]#

**Note:- Any type of changes in linux you should login by useraccount root.

 .  

Wednesday 28 March 2012

To delete mail queue from sendmail server


To delete mail queue from sendmail server:- 

Steps are as follows :-

First Login to your mail server 

[root@linuxnotes~]# cd /var/spool/mqueue/

[root@linuxnotes~]# ls -l 

[root@linuxnotes~]# rm -rf *

Sunday 15 January 2012

How to create a Swap Space ?

-->
In Linux, as in most other Unix-like operating systems, it is common to use a whole partition of a hard disk for swapping. However, with the 2.6 Linux kernel, swap files are just as fast as swap partitions, although I recommends using a swap partition. The administrative flexibility of swap files outweighs that of partitions; since modern high capacity hard drives can remap physical sectors, no partition is guaranteed to be contiguous. You can add swap file as a dedicated partition or use following instructions to create a swap file. 

Procedure To Add a Swap File Under Linux
You need to use the dd command to create swap file. The mkswap command is used to set up a Linux swap area on a device or in a file.
Step 1: Login as the Root User
Open a terminal window (select Applications > Accessories > Terminal) or login to remote server using the ssh client. Switch to the root user by typing su - and entering the root password, when prompted

Step 2: Create Storage File

Type the following command to create 1024MB swap file (1024 * 1024MB = 1048576 block size):
[root@linuxnotes~]# dd if=/dev/zero of=/swapfile1 bs=1024 count=1048576
Where,
  1. if=/dev/zero : Read from /dev/zero file. /dev/zero is a special file in that provides as many null characters to build storage file called /swapfile1.
  2. of=/swapfile1 : Read from /dev/zero write stoage file to /swapfile1.
  3. bs=1024 : Read and write 1024 BYTES bytes at a time.
  4. count=1048576 : Copy only 1048576 BLOCKS input blocks.

Step 3: Set Up a Linux Swap Area

Type the following command to set up a Linux swap area in a file:
[root@linuxnotes~]# mkswap /swapfile1
Setup correct file permission for security reasons, enter:
[root@linuxnotes~]# chown root:root /swapfile1

[root@linuxnotes~]# chmod 0600 /swapfile1
A world-readable swap file is a huge local vulnerability. The above command make sure only root user can read/write to the file.
Finally, activate /swapfile1 swap space immediately, enter:
[root@linuxnotes~]# swapon /swapfile1

 To activate /swapfile1 after Linux system reboot, add entry to /etc/fstab file. Open this file using a text editor such as vi:
[root@linuxnotes~]# vi /etc/fstab
Append the following line:
/swapfile1 swap swap defaults 0 0
Save and close the file. Next time Linux comes up after reboot, it enables the new swap file for you -->automatically.
How do I Verify Swap is Activated or Not?
Simply use the free command:
[root@linuxnotes~]#free -m