nmap command

#2: Scan multiple IP address or subnet (IPv4)

nmap 192.168.1.1 192.168.1.2 192.168.1.3
## works with same subnet i.e. 192.168.1.0/24
nmap 192.168.1.1,2,3
You can scan a range of IP address too:
nmap 192.168.1.1-20
You can scan a range of IP address using a wildcard:
nmap 192.168.1.*
Finally, you scan an entire subnet:
nmap 192.168.1.0/24
 

#3: Read list of hosts/networks from a file (IPv4)

nmap -iL /tmp/test.txt
 
cat > /tmp/test.txt
 
server1.cyberciti.biz
192.168.1.0/24
192.168.1.1/24
10.1.2.3
localhost
 

#4: Excluding hosts/networks (IPv4)

When scanning a large number of hosts/networks you can exclude hosts from a scan:
nmap 192.168.1.0/24 --exclude 192.168.1.5
nmap 192.168.1.0/24 --exclude 192.168.1.5,192.168.1.254

OR exclude list from a file called /tmp/exclude.txt
 
nmap -iL /tmp/scanlist.txt --excludefile /tmp/exclude.txt
 

#5: Turn on OS and version detection scanning script (IPv4)

nmap -A 192.168.1.254 nmap -v -A 192.168.1.1 nmap -A -iL /tmp/scanlist.txt

#6: Find out if a host/network is protected by a firewall

nmap -sA 192.168.1.254 nmap -sA server1.cyberciti.biz

#7: Scan a host when protected by the firewall

nmap -PN 192.168.1.1 nmap -PN server1.cyberciti.biz

#8: Scan an IPv6 host/address

The -6 option enable IPv6 scanning. The syntax is:
nmap -6 IPv6-Address-Here nmap -6 server1.cyberciti.biz nmap -6 2607:f0d0:1002:51::4 nmap -v A -6 2607:f0d0:1002:51::4

#9: Scan a network and find out which servers and devices are up and running

This is known as host discovery or    ping scan:      
nmap -sP 192.168.1.0/24

#10: How do I perform a fast scan?

nmap -F 192.168.1.1

#11: Display the reason a port is in a particular state

nmap --reason 192.168.1.1
nmap --reason server1.cyberciti.biz

#12: Only show open (or possibly open) ports

nmap --open 192.168.1.1
nmap --open server1.cyberciti.biz

#13: Show all packets sent and received

nmap --packet-trace 192.168.1.1
nmap --packet-trace server1.cyberciti.biz
 

#12: Only show open (or possibly open) ports

nmap --open 192.168.1.1 nmap --open server1.cyberciti.biz

#13: Show all packets sent and received

nmap --packet-trace 192.168.1.1
nmap --packet-trace server1.cyberciti.biz
 

14#: Show host interfaces and routes

This is useful for debugging (ip command or route command or netstat command like output using nmap)
nmap --iflist

#15: scan specific ports?

## Scan port 80
nmap -p 80 192.168.1.1
 
## Scan TCP port 80
nmap -p T:80 192.168.1.1
 
## Scan UDP port 53
nmap -p U:53 192.168.1.1
 
## Scan two ports ##
nmap -p 80,443 192.168.1.1
 
## Scan port ranges ##
nmap -p 80-200 192.168.1.1
 
## Combine all options ##
nmap -p U:53,111,137,T:21-25,80,139,8080 192.168.1.1
nmap -p U:53,111,137,T:21-25,80,139,8080 server1.cyberciti.biz
nmap -v -sU -sT -p U:53,111,137,T:21-25,80,139,8080 192.168.1.254
 
## Scan all ports with * wildcard ##
nmap -p "*" 192.168.1.1
 
## Scan top ports i.e. scan $number most common ports ##
nmap --top-ports 5 192.168.1.1
nmap --top-ports 10 192.168.1.1
 

#16: The fastest way to scan all your devices/computers for open ports ever

nmap -T5 192.168.1.0/24

#17: How do I detect remote operating system?

You can identify a remote host apps and OS using the -O option:
 
nmap -O 192.168.1.1
nmap -O  --osscan-guess 192.168.1.1
nmap -v -O --osscan-guess 192.168.1.1
 

#18: How do I detect remote services (server / daemon) version numbers?

nmap -sV 192.168.1.1

#19: Scan a host using TCP ACK (PA) and TCP Syn (PS) ping

If firewall is blocking standard ICMP pings, try the following host discovery methods:
nmap -PS 192.168.1.1
nmap -PS 80,21,443 192.168.1.1
nmap -PA 192.168.1.1
nmap -PA 80,21,200-512 192.168.1.1
 

#20: Scan a host using IP protocol ping

nmap -PO 192.168.1.1

#21: Scan a host using UDP ping

This scan bypasses firewalls and filters that only screen TCP:
nmap -PU 192.168.1.1 nmap -PU 2000.2001 192.168.1.1

#22: Find out the most commonly used TCP ports using TCP SYN Scan

  ### Stealthy scan ### nmap -sS 192.168.1.1   ### Find out the most commonly used TCP ports using TCP connect scan (warning: no stealth scan) ### OS Fingerprinting ### nmap -sT 192.168.1.1   ### Find out the most commonly used TCP ports using TCP ACK scan nmap -sA 192.168.1.1   ### Find out the most commonly used TCP ports using TCP Window scan nmap -sW 192.168.1.1   ### Find out the most commonly used TCP ports using TCP Maimon scan nmap -sM 192.168.1.1 
 

#23: Scan a host for UDP services (UDP scan)

Most popular services on the Internet run over the TCP protocol. DNS, SNMP, and DHCP are three of the most common UDP services. Use the following syntax to find out UDP services:
nmap -sU nas03
nmap -sU 192.168.1.1

#24: Scan for IP protocol

This type of scan allows you to determine which IP protocols (TCP, ICMP, IGMP, etc.) are supported by target machines:
nmap -sO 192.168.1.1

#25: Scan a firewall for security weakness

The following scan types exploit a subtle loophole in the TCP and good for testing security of common attacks:
 
## TCP Null Scan to fool a firewall to generate a response ##
## Does not set any bits (TCP flag header is 0) ##
nmap -sN 192.168.1.254
 
## TCP Fin scan to check firewall ##
## Sets just the TCP FIN bit ##
nmap -sF 192.168.1.254
 
## TCP Xmas scan to check firewall ##
## Sets the FIN, PSH, and URG flags, lighting the packet up like a Christmas tree ##
nmap -sX 192.168.1.254

 

#26: Scan a firewall for packets fragments

The -f option causes the requested scan (including ping scans) to use tiny fragmented IP packets. The idea is to split up the TCP header over
several packets to make it harder for packet filters, intrusion detection systems, and other annoyances to detect what you are doing.
nmap -f 192.168.1.1
nmap -f fw2.nixcraft.net.in
nmap -f 15 fw2.nixcraft.net.in
## Set your own offset size with the --mtu option ##
nmap --mtu 32 192.168.1.1

#27: Cloak a scan with decoys

The -D option it appear to the remote host that the host(s) you specify as decoys are scanning the target network too. Thus their IDS might report 5-10 port scans from unique IP addresses, but they won't know which IP was scanning them and which were innocent decoys:
nmap -n -Ddecoy-ip1,decoy-ip2,your-own-ip,decoy-ip3,decoy-ip4 remote-host-ip nmap -n -D192.168.1.5,10.5.1.2,172.1.2.4,3.4.2.1 192.168.1.5

#28: Scan a firewall for MAC address spoofing

  ### Spoof your MAC address ## nmap --spoof-mac MAC-ADDRESS-HERE 192.168.1.1   ### Add other options ### nmap -v -sT -PN --spoof-mac MAC-ADDRESS-HERE 192.168.1.1     ### Use a random MAC address ### ### The number 0, means nmap chooses a completely random MAC address ### nmap -v -sT -PN --spoof-mac 0 192.168.1.1  

#29: How do I save output to a text file?

The syntax is:
nmap 192.168.1.1 > output.txt nmap -oN /path/to/filename 192.168.1.1 nmap -oN output.txt 192.168.1.1

setup spamassassin centos 6 for zpanel

First we need to install postgrey daemon.
Open a terminal window and enter:


Code:
yum install postgrey

OK. Service installed!

Now open /etc/init.d/postgrey with your favorite editor and find this line:

Code:
vi /etc/init.d/postgrey

# search for this line
Code:
options="--unix=/var/spool/postfix/postgrey/socket"

It means that process "postgrey" is using socket instead of tcp connection. Socket path is cruical for postfix to communicate with postgrey. CTRL (CMD) + C this path for later use!

We need to start the service and make sure, that the service will start automatically after reboot!

Code:
service post grey start
chkconfig postgrey on

The postfix config part…
With your favourite editor open /etc/postfix/main.cf

Code:
vi /etc/postfix/main.cf

… and find the

Code:
smtpd_recipient_restrictions =

it should look something like this:

Code:
smtpd_recipient_restrictions =
   permit_mynetworks,
   permit_sasl_authenticated,
   check_policy_service unix:/var/spool/postfix/postgrey/socket, ### Add this line. Double check the socket path!!!

Mine smtpd_recipient_restrictions block looks like this:

Code:
smtpd_recipient_restrictions =
        permit_mynetworks,
        permit_sasl_authenticated,
        check_policy_service unix:/var/spool/postfix/postgrey/socket,
        reject_invalid_hostname,
        reject_unauth_destination,
        reject_non_fqdn_sender,
        reject_non_fqdn_recipient,
        reject_unknown_recipient_domain,
        reject_unauth_pipelining,
        reject_unknown_sender_domain,
        reject_unknown_recipient_domain,

# SPAM/black list checks

        reject_rbl_client sbl-xbl.spamhaus.org,
#       reject_rbl_client multi.uribl.com, ### Too many requests - payable service
        reject_rbl_client dsn.rfc-ignorant.org,
        reject_rbl_client dul.dnsbl.sorbs.net,
        reject_rbl_client dnsbl.njabl.org,
        reject_rbl_client bl.spamcop.net,
#       reject_rbl_client dnsbl.sorbs.net, ### This one is blocking emails from yahoo
        reject_rbl_client cbl.abuseat.org,
        reject_rbl_client ix.dnsbl.manitu.net,
        reject_rbl_client combined.rbl.msrbl.net,
        reject_rbl_client rabl.nuclearelephant.com,
        permit

If you want to whitelist some clients/recipients open this two files with your editor of choice:

Code:
vi /etc/postfix/postgrey_whitelist_clients
vi /etc/postfix/postgrey_whitelist_recipients

For the last step all we have to do is to reload the Postfix configuration with:

Code:
service postfix reload

Just to be sure that Postfix and Postgrey are working together check the maillog with:

Code:
tail -f /var/log/maillog

… and find this line

Code:
Aug 28 17:33:59 hostname postgrey[20092]: action=greylist, reason=new, client_name=remote.mail.server, client_address=<remote IP address>, sender=<email@address>, recipient=<email@address>

Well done. You've just dramatically reduced the number of SPAM messages.

If you want to read more about Postgrey service, here is the link: http://projects.puremagic.com/greylisting/

Enjoy!
=================================================================
 SCRIPT TO INSTALL IN CENTOS

#!/bin/sh
#
# Script to install postgrey and spamassassin, tested on Centos 6.4 and ZPanel 10.1.0
#
if which postgrey >/dev/null; then
echo "postgrey already exist"
else
echo "Installing postgrey"
yum -y install postgrey
sed -i '/^smtpd_recipient_restrictions =/ s/$/ check_policy_service inet:127.0.0.1:60000,/' /etc/zpanel/configs/postfix/main.cf
sed -i 's/options=\"--unix=\/var\/spool\/postfix\/postgrey\/socket\"/options=\"--inet=127.0.0.1:60000 --delay=150\"/g' /etc/init.d/postgrey
service postgrey start
service postfix reload
chkconfig postgrey on
echo "postgrey installed"
fi
#
if which spamassassin >/dev/null; then
echo "spamassassin already exist"
else
echo "Installing spamassassin"
yum -y install spamassassin
echo -e "\n" > /etc/mail/spamassassin/local.cf
sed -i '1s/^/required_hits 5.0\n/' /etc/mail/spamassassin/local.cf
sed -i '2s/^/report_safe 0\n/' /etc/mail/spamassassin/local.cf
sed -i '3s/^/required_score 5\n/' /etc/mail/spamassassin/local.cf
sed -i '4s/^/rewrite_header Subject ***SPAM***\n/' /etc/mail/spamassassin/local.cf
groupadd spamd
useradd -g spamd -s /bin/false -d /var/log/spamassassin spamd
chown spamd:spamd /var/log/spamassassin
sed -i '/^smtp        inet/ s/$/ -o content_filter=spamassassin/' /etc/zpanel/configs/postfix/master.cf
sed -i '/^smtp      inet/ s/$/ -o content_filter=spamassassin/' /etc/zpanel/configs/postfix/master.cf
sed -i '/^smtp    inet/ s/$/ -o content_filter=spamassassin/' /etc/zpanel/configs/postfix/master.cf
sed -i '/^smtp  inet/ s/$/ -o content_filter=spamassassin/' /etc/zpanel/configs/postfix/master.cf
echo -e "\nspamassassin unix - n n - - pipe flags=R user=spamd argv=/usr/bin/spamc -e /usr/sbin/sendmail.postfix -oi -f \${sender} \${recipient}\n" >> /etc/zpanel/configs/postfix/master.cf
/etc/init.d/postfix restart
/etc/init.d/spamassassin restart
echo "SpamAssassin installed, to test it send a mail from outside with the subject: XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X"
echo "Your first email will take about 150 seconds to arrive"
fi

setup spamassassin ubuntu 12.04 for zpanel

 http://forums.sentora.io/showthread.php?tid=22
Ubuntu :How to setup Spamassassin
How to setup Spamassassin

1: Use apt-get to install Spamassassin and spamc.
Code: (Select All)
apt-get install spamassassin spamc
Add Spamassassin user

2: First add the group spams:
Code: (Select All)
groupadd spamd

3: Then add the user spamd with the home irectory /var/log/spamassassin:
Code: (Select All)
useradd -g spamd -s /bin/false -d /var/log/spamassassin spamd

4: then create the directory /var/log/spamassassin and change the ownership:
Code: (Select All)
mkdir /var/log/spamassassin
chown spamd:spamd /var/log/spamassassin

Setting Up Spamassassin
5: Open the spamassassin config file using:
Code: (Select All)
nano /etc/default/spamassassin

6: Setting up spamassassin
Code: (Select All)
Find ENABLED=0 and change to ENABLED=1
Find CRON=0 and change to CRON=1
Find OPTIONS and change the line to
OPTIONS="--create-prefs --max-children 2 --username spamd \ -H ${SAHOME} -s ${SAHOME}spamd.log"
save and exit

7: Now create a variable named SAHOME with the Spamassassin home directory:
Code: (Select All)
SAHOME="/var/log/spamassassin/"

8: start spamassassin
Code: (Select All)
service spamassassin start

Configuring Postfix

9: Open Postfix config file using:
Code: (Select All)
nano /etc/postfix/master.cf

10: Find the the line
Code: (Select All)
smtp    inet n     -     -     -     -     smtpd
add "-o content_filter=spamassassin" after smtpd

11 End of the file add:
Code: (Select All)
spamassassin unix - n n - - pipe user=spamd argv=/usr/bin/spamc -f -e /usr/sbin/sendmail -oi -f ${sender} ${recipient}

12: restart postfix
Code: (Select All)
service postfix restart

Configuring Spamassassin

13: Open the Spamassassin default rules file using:
Code: (Select All)
nano /etc/spamassassin/local.cf

14 : make rules
Code: (Select All)
change
#rewrite_header
Subject ***** SPAM ***** to
rewrite_header Subject [*** SPAM ***]
change required_score 5.0 to required_score 3.0
use_bayes from 0 to 1
bayes_auto_learn from 0 to 1

15: now restart spamassassin
Code: (Select All)
service spamassassin restart

Hardening wordpress website

Hardening WordPress Website
==================================================================
Vulnerabilities in WordPress
Like many modern software packages, WordPress is updated regularly to address new security issues that may arise. Improving software security is always an ongoing concern, and to that end you should always keep up to date with the latest version of WordPress. Older versions of WordPress are not maintained with security updates.

Passwords
Many potential vulnerabilities can be avoided with good security habits. A strong password is an important aspect of this.

The goal with your password is to make it hard for other people to guess and hard for a brute force attack to succeed. Many automatic password generators are available that can be used to create secure passwords.

Securing wp-admin
Adding server-side password protection (such as BasicAuth) to /wp-admin/ adds a second layer of protection around your blog's admin area, the login screen, and your files. This forces an attacker or bot to attack this second layer of protection instead of your actual admin files. Many WordPress attacks are carried out autonomously by malicious software bots. One of the application you can use is latch. For more information on this application you can visit https://latch.elevenpaths.com/, its not only for your WordPress website but can also be used for others too.

Make use of following plugins:
Bulletproof security --> to create strong .htaccess file
Anti-Malware --> to scan the malicious files in the domain
ip blacklist --> to blacklist the ip which tries to do brute force attack


Generate the salt from following link and paste it in wp-config.php file
http://api.wordpress.org/secret-key/1.1/salt/


Summarizing:
1. Making sure your WordPress installation has the latest updates
2. Minimizing the number of plugins you use (and deleting the ones you don’t)
3. Choosing passwords that are difficult to crack
4. Performing regular data backups
5. Protecting your WordPress using .htaccess


For more information please visit following links
http://codex.wordpress.org/Hardening_WordPress
http://www.firedaemon.com/blog/wordpress-hardening-guide
http://thematosoup.com/wordpress-security-htaccess/

find DDOS attack on apache and blocking dos attack

netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n

tail -n 10000 yourweblog.log|cut -f 1 -d ' '|sort|uniq -c|sort -nr|more
Take a look at the top IP addresses. If any stand out from the others, those would be the ones to firewall.
netstat -n|grep :80|cut -c 45-|cut -f 1 -d ':'|sort|uniq -c|sort -nr|more
This will look at the currently active connections to see if there are any IPs connecting to port 80. You might need to alter the cut -c 45- as the IP address may not start at column 45. If someone was doing a UDP flood to your webserver, this would pick it up as well.
On the off chance that neither of these show any IPs that are excessively out of the norm, you would need to assume that you have a botnet attacking you and would need to look for particular patterns in the logs to see what they are doing. A common attack against wordpress sites is:
GET /index.php? HTTP/1.0
If you look through the access logs for your website, you might be able to do something like:
cut -f 2 -d '"' yourweblog.log|cut -f 2 -d ' '|sort|uniq -c|sort -nr|more
which would show you the most commonly hit URLs. You might find that they are hitting a particular script rather than loading the entire site.
cut -f 4 -d '"' yourweblog.log|sort|uniq -c|sort -nr|more
would allow you to see common UserAgents. It is possible that they are using a single UserAgent in their attack.
The trick is to find something in common with the attack traffic that doesn't exist in your normal traffic and then filter that through iptables, mod_rewrite or upstream with your webhost. If you are getting hit with Slowloris, Apache 2.2.15 now has the reqtimeout module which allows you to configure some settings to better protect against Slowloris.
more on :-

http://linoxide.com/firewall/how-to-ddos-in-linux/
http://www.opensourceforu.com/2011/04/securing-apache-part-8-dos-ddos-attacks/

Postfix ip rotation bash style

[root@mx12 postfix]# pwd
/etc/postfix

[root@mx12 postfix]# touch current.txt &&  vim  bal.cf

#!/bin/bash
ips=("5.9.240.232" "5.9.219.160" "5.9.219.166" "5.9.219.167")
length=${#ips[@]}
pos=`cat current.txt`
oldip=${ips[$pos - 1]}
if [ "$length" -eq "$pos" ] ; then
    echo "limit reached"
    pos=1
else
    echo "increment!"
    (( pos++ ))
fi

echo "$pos" > current.txt

newip=${ips[$pos - 1]}
echo "prev: $oldip"
echo "new: $newip"
echo "=============="
sed -ie "s/smtp_bind_address=$oldip/smtp_bind_address=$newip/g" /etc/postfix/main.cf > /dev/null
service MailScanner restart


[root@mx12 postfix]# cat current.txt
1

put the script bal.cf in crontab to run every  5 or 10 or 15 so...........


RAID setup in rhel 6

This document attempts to provide step-by-step procedures that can be followed to:
• Set up software RAID in RHEL 6
• Migrate existing storage from Non-RAID to Software RAID
• Resize RAID volumes
• Recover from a broken RAID
This document uses RAID-1 as an example while working with Software RAID. The procedure can however be applied to other RAID types as applicable. Please consult the mdadm(8) man page for details on exact options for various RAID types.

We used a Dell PowerEdgeTM R510 server with a Dell PERC H200 storage controller on the system for this procedure. All the storage volumes were exported directly to the OS without using any controller hardware RAID features.

Note: Ensure that all data backed up before performing any of these procedures

Setting up Software RAID in RHEL 6
Setup during Installation
The RHEL 6 installer (anaconda) has functionality that enables the OS to be installed on a software RAID partition. This section describes the steps to install RHEL 6 on a RAID-1 partition.
1. Start the RHEL 6 installer and follow the on-screen installation instructions and select the “Custom” layout for installation.
2. Create a minimum of two partitions to create RAID-1 device type and set the File System Type as software raid.
3. Create a RAID-1 device from RAID members created in Step2, select the filesystem and RAID-1 level
Here is the minimum number of software RAID partitions required for each RAID level:
• RAID 0,1,10 – 2 partitions
• RAID 4,5 – 3 partitions
• RAID 6 – 4 partitions
4. After creating all the necessary partitions (/boot, /, swap, etc.) on RAID-1 volume, proceed with the installation.
5. Once the installation is completed, the OS will boot successfully from the partitions on the RAID volume.
Note: Ensure that the boot-loader is installed on the first disk and not on the RAID device.
Installing boot-loader on the RAID device may result in failure to boot the OS after installation.

Setup after Installation
Software RAID volumes can be created on a running system post install as well. Ensure that the partition/s on which the OS is installed are not used for creating software RAID partitions, failure to do that may results in re-installing OS on the system.
Following section describes steps to create RAID-1 partition on the system.
1. Create the raid-1 md device using the mdadm command with /dev/sdj1 and /dev/sdl1. sdj1 and sdl1 are un-used partitions on this system

Note: "--metadata=0.90" is only used when you create /boot partition, because CentOS 6.x (6.4) still does not support boot from default metadata 1.2

[root@Dell-PowerEdge-R510 ~]# mdadm --create /dev/md9 --level=1 --raid-disks=2 /dev/sdj1 /dev/sdl1 --metadata=0.90
mdadm: array /dev/md9 started.
2. Create ext4 filesystem layout on the md device and add array details mdadm –-detail –scan to /etc/mdadm.conf file. Mount the device /dev/md9 on the system to use it.

[root@Dell-PowerEdge-R510 ~]# mkfs.ext4 /dev/md9

[root@Dell-PowerEdge-R510 ~]# mdadm --detail --scan >> /etc/mdadm.conf

[root@Dell-PowerEdge-R510 ~]# mount /dev/md9 /data/
3. Add a new entry in /etc/fstab file to auto mount the md raid partition, whenever system reboots.

[root@Dell-PowerEdge-R510 ~]# cat /etc/fstab
/dev/md9 /data ext4 defaults 1 1

Migration of Storage from Non-RAID to RAID Configurations
It is possible to migrate to software raid, the “/” partition without having to re-install the operating system if you installed RHEL 6 OS without software raid volumes. This section explains how migration of storage from non-raid to raid configuration can be achieved.

At a high level, here is how it can be achieved:
• Prepare the new storage volume
• Update fstab and grub configuration to boot from newly created storage volume
• Sync the data from the old partitions to the new storage volume
• Install the boot loader on new storage volume
• Add the old partition volume to the md raid-1 set


Prepare the new storage volume
1. Create the partition layout on the /dev/sdj volume similar to /dev/sdh.

[root@Dell-PowerEdge-R510 ~]# sfdisk -d /dev/sdh | sfdisk --force /dev/sdj
Device     Boot      Start         End   #sectors  Id System
/dev/sdj1  *         2048  20482047  20480000 83 Linux
/dev/sdj2      20482048  24578047    4096000 82 Linux swap / Solaris
Warning: partition 1 does not end at a cylinder boundary
Successfully wrote the new partition table

2. Set the partition id of /dev/sdj1 to Linux RAID

[root@Dell-PowerEdge-R510 ~]# sfdisk -c /dev/sdj 1 fd
Done

Create RAID-1 using mdadm utility:
1. Create the raid-1 md device using the mdadm command with /dev/sdj1. Mark the first volume as “missing”, which will be sdh volume, and it will be added later in the steps. Since sdh has OS installed, we have to add this to raid array after copying the contents from sdj to sdh drive.

Note: "--metadata=0.90" is only used when you create /boot partition, because CentOS 6.x (6.4) still does not support boot from default metadata 1.2

[root@Dell-PowerEdge-R510 ~]# mdadm --create /dev/md9 --level=1 --raid-disks=2 missing /dev/sdj1 --metadata=0.90
mdadm: array /dev/md9 started.
2. Create ext4 filesystem layout on the md device and add the array details mdadm –-detail –scan to /etc/mdadm.conf file.

[root@Dell-PowerEdge-R510 ~]# mkfs.ext4 /dev/md9

[root@Dell-PowerEdge-R510 ~]# mdadm --detail --scan >> /etc/mdadm.conf
Update fstab and grub configuration to boot from newly created storage volume:
1. Modify the /etc/fstab and /boot/grub/menu.lst with md device.

[root@Dell-PowerEdge-R510 ~]# blkid | grep –i md9
/dev/md9: UUID="016db049-6802-4369-bf66-bd48aad15395" TYPE="ext4"

[root@Dell-PowerEdge-R510 ~]# cat /etc/fstab
#UUID=38b56dff-c6d2-434f-bb48-25efb97f3a58 / 1 1 ext4 defaults
UUID=016db049-6802-4369-bf66-bd48aad15395 / 1 1 ext4 defaults

[root@Dell-PowerEdge-R510 ~]# cat /boot/grub/menu.lst
2. Add sdj to the device map entry to install the grub on the sdj device.

[root@Dell-PowerEdge-R510 ~]# cat /boot/grub/device.map
# this device map was generated by anaconda
(hd0) /dev/sdh
(hd1) /dev/sdj

Sync the data from the old partitions to the new storage volume:
1. Since we are trying to replicate the contents from currently running partition. It is recommended that you execute the following steps in run level1
2. Mount the array volume and copy the contents from sdh1 to md9.

[root@Dell-PowerEdge-R510 ~]# mount /dev/md9 //

[root@Dell-PowerEdge-R510 ~]# rsync -aqxP / //

Install the boot loader on new storage volume:
1. Install the boot loader on the sdj device.

[root@Dell-PowerEdge-R510 ~]# grub-install /dev/sdj
Installation finished. No error reported.
This is the contents of the device map /boot/grub/device.map.
Check if this is correct or not. If any of the lines is incorrect, fix it and re-run the script `grub-install'.
# this device map was generated by anaconda
(hd0) /dev/sdh
(hd1) /dev/sdj

2. Reboot the system and verify the system has booted with the md device using the mount command.

Add the old partition volume to the md raid-1 set:
1. Change the partition of sdh1 and add the sdh1 device to md9 array and allow the resync to complete from sdh1 to sdj1.

[root@Dell-PowerEdge-R510 ~]# sfdisk -c /dev/sdh 1 fd
Done

[root@Dell-PowerEdge-R510 ~]# mdadm --add /dev/md9 /dev/sdh1
mdadm: added /dev/sdh1

[root@Dell-PowerEdge-R510 ~]# watch cat /proc/mdstat
2. Reboot the system to verify the md migration completed successfully.
3. Run the cat /proc /mdstat command to check the status of the running array.

Resizing an existing RAID Partition
The Linux software-RAID solution allows us to resize (increase or decrease) the RAID partition size. Following steps explain how to increase the size of existing software RAID partition (data and OS partitions).

Here is what is required:
• Prepare partitions of the new size desired
• Replace both RAID members with newly created partitions by breaking existing RAID
• Resize the RAID array
• If dealing with OS partitions, Prepare the new RAID volume to be bootable

Prepare partitions of the new size desired:
1. Initially create the md9 raid-1 level with a size approximately 100 GB comprised of both the sdh1 and sdj1 volumes. The md-0 array RAID set will be increased to approximately 200 GB by using the sdl1 and sdm1 volumes.
2. Create the new RAID partition of increased size on sdl and sdm. In this example, we created a new RAID partition of approximately 200GB in size on the sdl volume.

[root@Dell-PowerEdge-R510 ~]# sfdisk -c /dev/sdl 1 fd
Done

[root@Dell-PowerEdge-R510 ~]# fdisk -l /dev/sdl
Disk /dev/sdl: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x4c0a9054
Device     Boot Start     End      Blocks       Id System
/dev/sdl1           1      25000  200812468+ fd Linux raid autodetect

Replace both RAID members with newly created partitions by breaking existing RAID:
1. Set the sdj1 volume to faulty and remove the volume from the RAID set.

[root@Dell-PowerEdge-R510 ~]# mdadm /dev/md9 –-fail /dev/sdj1 –remove /dev/sdj1
mdadm: set /dev/sdj1 faulty in /dev/md9
mdadm: hot removed /dev/sdj1 from /dev/md9

2. Add the new partition to the RAID set and allow the resync to complete on the new partition added to the RAID set. Run cat /proc/mdstat to show the status of resynchronization.
[root@Dell-PowerEdge-R510 ~]# mdadm --add /dev/md9 /dev/sdl1
mdadm: added /dev/sdl1
[root@Dell-PowerEdge-R510 ~]# cat /proc/mdstat
Personalities : [RAID-1]
md9 : active RAID-1 sdl1[2] sdh1[0]
102399928 blocks super 1.0 [2/2] [UU]
bitmap: 1/1 pages [4KB], 65536KB chunk
unused devices:

3. Repeat the above steps adding the /dev/sdm1 partition. Remove the /dev/sdh1 partition from the RAID set. Allow the resynchronization to complete on the /dev/sdm1 partition.
[root@Dell-PowerEdge-R510 ~]# cat /proc/mdstat
Personalities : [RAID-1]
md9 : active RAID-1 sdm1[3] sdl1[2]
102399928 blocks super 1.0 [2/1] [_U]
[>....................]
recovery =
finish=20.7min speed=81894K/sec
bitmap: 1/1 pages [4KB], 65536KB chunk
0.3%
(409472/102399928)
unused devices:

Resize the RAID array:
1. Set the /dev/md9 partition size to use the new volume partition size and allow the resync to complete.
[root@Dell-PowerEdge-R510 ~]# mdadm --grow /dev/md9 --size=max
mdadm: Cann[ot set device size for /dev/md9: Device or resource busy
Bitmap must be removed before size can be changed
[root@Dell-PowerEdge-R510 ~]# mdadm --grow /dev/md9 --bitmap none
[root@Dell-PowerEdge-R510 ~]# mdadm --grow /dev/md9 --size=max
mdadm: component size of /dev/md9 has been set to 200812396K

2. Resize the file system of the /dev/md9 partition to increase the file system size. Now the df –h command shows the increased md RAID set.
[root@Dell-PowerEdge-R510 ~]# resize2fs /dev/md9
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/md9 is mounted on /; on-line resizing required old desc_blocks = 7, new_desc_blocks = 12
Performing an on-line resize of /dev/md9 to 50203099 (4k) blocks.
The filesystem on /dev/md9 is now 50203099 blocks long.
[root@Dell-PowerEdge-R510 ~]# df -h
Filesystem  Size Used Avail Use% Mounted on
/dev/md9 189G 1.4G 178G     1% /
tmpfs       1.9G     0 1.9G       0% /dev/shm

If dealing with OS partitions, prepare the new RAID volume to be bootable:

Note: Following steps are required to boot the Linux system, if you are replacing the drive from RAID array which has boot loader and file system already installed.
Before resizing the RAID partition, ensure that the md-raid set has two active drives, sdh1 and sdj1 and that grub is installed in /dev/sdh. After the resizing operation, the md-raid set has been replaced with sdl1 and sdm1 volumes and boot loader has been installed on sdl volume.

1. Add the sdl and sdm entries in device.map file.
[root@Dell-PowerEdge-R510 ~]# cat /boot/grub/device.map
# this device map was generated by anaconda
(hd0) /dev/sdh
(hd1) /dev/sdj
(hd2) /dev/sdl
(hd3) /dev/sdm

2. Install the grub boot loader on the /dev/sdl volume and then remove the older drives from the system.
[root@Dell-PowerEdge-R510 ~]# grub-install /dev/sdl
Installation finished. No error reported.
This is the contents of the device map /boot/grub/device.map. Check if this is correct or not. If any of the lines is incorrect, fix it and re-run the script `grub-install'.
# this device map was generated by anaconda
(hd0) /dev/sdh
(hd1) /dev/sdj
(hd2) /dev/sdl
(hd3) /dev/sdm

3. Reboot the system and enter the storage controller BIOS configuration.
4. Change the boot drive to new drive where the boot loader is now installed.
5. Save the configuration and restart the system to boot from new RAID set partition.

Recovery from a Broken RAID
In case of RAID failures on a system running Linux Software RAID (md) solution (for example, media failure or disk driver failure), it is possible to recover the system by any of these methods
• replacing the faulty disk
• adding a new disk
• using the spare disk

In Linux software raid, recovery is achieved through “failover” mechanisms. Failover mechanism ensures data protection by providing additional drives (spares) and can be automatic or manual.

Automatic Failover
Linux md-raid solution has an intelligent monitor mechanism to detect hardware failure in RAID arrays.
If any disk in the RAID array fails, the monitors sets the failed drive to faulty and starts using one of the available spare drives for regeneration. To check the status of the RAID array, look at  /proc/mdstat file.
To replicate a raid failure to check how automatic failover scenario works, follow the steps.
1. Create a RAID-1 setup with three raid partition. Minimum two raid partitions are required to create RAID-1 device and third raid partition is used as a spare disk, will be used as a replacement if one of the active RAID partition fails.
2. Simply pull out one of the disks which are active in the raid array and check the status of the array using the cat /proc/mdstat command, will show the removed drive as faulty and use the spare drive as replacement for date re-generation.

Manual Failover
Faulty drives in the raid array can be replaced manually. Following steps discuss how to manually replace the faulty drive from the RAID-1 array:
1. Raid-1 setup is created with sdh1 and sdj1 partitions. Set the sdh1 drive to faulty.
[root@DELL-PowerEdge-R510 ~]# mdadm -f /dev/md9 /dev/sdh1
mdadm: set /dev/sdh1 faulty in /dev/md9
2. Remove the faulty drive sdh1 from the array.
[root@DELL-PowerEdge-R510 ~]# mdadm -r /dev/md9 /dev/sdh1
mdadm: hot removed /dev/sdh1 from /dev/md9
3. Replace the faulty drive with adding a new one to the array.
[root@DELL-PowerEdge-R510 ~]# mdadm --add /dev/md9 /dev/sdl1
Device Added
4. Look at status of the RAID array by executing the cat /proc/mdstat command, showing /dev/sdl1 added to the RAID array. Also check that the resynchronization is complete.
[root@DELL-PowerEdge-R510 ~]# cat /proc/mdstat
Personalities : [RAID-1]
md9 : active RAID-1 sdl1[2] sdj1[0]
40958908 blocks super 1.1 [2/2] [UU]
bitmap: 1/1 pages [4KB], 65536KB chunk

Adding a Spare Disk to the Array
Spare disks provide additional protection to a raid configuration. If a disk fails in a raid array, the spare disk automatically replaces the failed drive; also the raid can be rebuilt automatically in the background. Spare drives can be added to the RAID array during the time of creation of the array or later.

Adding spare disk during raid array creation
[root@Dell-PowerEdge-R510 ~]# mdadm --create /dev/md9 --level=1 --raid-disks=2 /dev/sdj1 /dev/sdl1 --metadata=0.90 –-spare-devices=1 /dev/sdm1
mdadm: array /dev/md9 started.

Adding spare disk to an existing array.
[root@DELL-PowerEdge-R510 ~]# mdadm --add /dev/md9 /dev/sdl1
mdadm: added /dev/sdl1
[root@DELL-Poweredge-R510 ~]# cat /proc/mdstat
Personalities : [RAID-1]
md8 : active RAID-1 sdl1[2](S) sdh1[0] sdj1[1] sdl

References
• http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/index.html
• http://www.spinics.net/lists/raid/
• https://raid.wiki.kernel.org/index.php/Linux_Raid
-------------------------------------------------------------------------------------------

Stopping resync-a:
echo "idle" > /sys/block/md0/md/sync_action

Rename:

Last time I did this it was from a later distribution --- either a RHEL-4 or FC-5 rescue CD, I cannot recall which at this point.  I did it precisely for the reason you give, to move an existing /dev/md0 to another RHEL-4 box.  But it wasn't hard, using mdadm.  Knowing the devices belonging to the array (sda5 and sdb5 in this case), I just did:

# mdadm --stop /dev/md0
# mdadm -A /dev/md6 -m0 --update=super-minor /dev/sda5 /dev/sdb5

which stops the array as /dev/md0 and then reassembles it as /dev/md6.
The reassembly looks for devices which have an existing minor number of 0, not 6 (-m0), and then updates the minors in the superblocks to the new number.

I believe the same options are present in taroon's mdadm.

mdadm ---create --level=1 --raid-devices=2 /dev/sdh1 /dev/sdg1

(Repair filesystem) Writing not allowed. Solution:
mount -w -o remount /

Linux console scroll : Shift + PgDn ili Shift + PgUp

Creating Boot RAID1:
[root@kancelarija yum]# mdadm --create /dev/md9 --level=1 --raid-disks=2 /dev/sdd1 /dev/sde1 --metadata=0.90

Creating RAID10 far,2:
[root@kancelarija yum]# mdadm --create /dev/md9 --level=10 --layout=f2 --raid-disks=2 /dev/sdd9 /dev/sde9

6.3. Activate RAID Devices
The installation media doesn't include a default mdadm.conf file, so it must be created. An easy method is...

mdadm --examine --scan > /etc/mdadm.conf

Next, activate all discovered RAID devices with...

mdadm --assemble --scan

cat /proc/sys/dev/raid/speed_limit_max
200000
cat /proc/sys/dev/raid/speed_limit_min
1000

50MB/s:
echo 50000 >/proc/sys/dev/raid/speed_limit_min

vsftpd ftp file server setup

yum install vsftpd ftp -y

chkconfig vsftpd on
sestatus              # to check selinux status
[root@web vsftpd]#  getsebool -a | grep ftp  
allow_ftpd_anon_write --> off
allow_ftpd_full_access --> off
allow_ftpd_use_cifs --> off
allow_ftpd_use_nfs --> off
ftp_home_dir --> off
ftpd_connect_db --> off
ftpd_use_passive_mode --> off
httpd_enable_ftp_server --> off
tftp_anon_write --> off

you need to enable ftp_home_dir => on

# setsebool -P ftp_home_dir=1   

vim /etc/vsftpd/vsftpd.conf

anonymous_enable=NO
chroot_local_user=YES
chroot_list_enable=NO
chroot_list_file=/etc/vsftpd/chroot_list 
 
listen=YES
#listen_ipv6=YES  this will disable ipv6 listening
#current version doesnt support the vsftp listening on ipv4 and ipv6 simultaneously.
 
And lets configure vsftpd to be able to chroot(commonly referred to as 
jailing or jail) users to their home directories for security and 
privacy:
 
 
  • Also, lock down vsftpd to a predictable port range. (By default, vsftpd runs in passive mode and will choose a port between 1024-65535). Add the following:
pasv_min_port=3000
pasv_max_port=3050

  • Create the chroot_list file so you do not get an error when restarting:
sudo touch /etc/vsftpd/chroot_list

For RHEL6

iptables -I INPUT -m tcp -p tcp --dport 21 -j ACCEPT
iptables -I INPUT 1 -p tcp --dport 3000:3050 -j ACCEPT
 
For RHEL5 
 
iptables -I RH-Firewall-1-INPUT 1 -p tcp --dport 3000:3050 -j ACCEPT
iptables -I RH-Firewall-1-INPUT -m tcp -p tcp --dport 21 -j ACCEPT 


Setup user for ftp with no login

# useradd test
    # passwd test
 
usermod -s /sbin/nologin test
 
 
Making the softlink work !!!!!!
 
we create a symbolic link inside user’s folder to point to the music folder:
 
ln -s /tmp/harddisk/music /tmp/harddisk/ftp_pvt/user/music 


It seems like everything is okay. As long as the permissions for the folder music grants access for the right users

Instead of copying whole content use mount

  mkdir /tmp/harddisk/ftp_pvt/user/music



 
 
Mount the folder you want user to access using the bind option  
 
  mount --bind /tmp/harddisk/music /tmp/harddisk/ftp_pvt/user/music
 

 Consider "/realdata/dir   /virtual/dir  none default,bind 0 0" in 
/etc/fstab to make the "mount -B" available on reboot as well (perhaps 
less obscure than "/etc/rc.local"). Note: don't bother looking into hard
 links, since they will not link directories, and will not file systems.

postfix change port 25

Bydefault the SMTP protocol runs at port no. 25.
You can change the port no. to any port no. other than below 2048.
0 to 2048 are IANA authorized known port no.but we have some other port no. also which are bydefault used by manyapplication for. eg. port no. 8080 for tomcat.
To know more about port number click this wikipedia URL .
Here we are using Postfix as our MTA.
To change the smtp port no. in postfix,edit the master.cf file and change the given below value
vi /etc/postfix/master.cf
smtp inet n – n – – smtpd
change smtp word to your desired port no. Here I am changing it to 9267
9267 inet n – n – – smtpd
Now restart the postfix
/etc/init.d/postfix restart
Check the port no. status with netstat command
[root@localhost postfix]# netstat -tanp|grep 9267
tcp 0 0 0.0.0.0:9267 0.0.0.0:* LISTEN 9788/master
[root@localhost postfix]#