setting up Fail2ban on centos 6.x/RHEL 6.x/fedora

Machine used = centos 6.5 x64bit



Fail2ban setup Centos 6.x/RHEL 6.x    (centos 6.5)
# yum install fail2ban
Copy /etc/fail2ban/jail.conf to jail.local
# vi /etc/fail2ban/jail.conf
Now, you will see default section with some basic rules that are followed by fail2ban itself. If you want to add some extra layer of protection to your server, then you can customize the each rule section as per your needs.
[DEFAULT]
 
# "ignoreip" can be an IP address, a CIDR mask or a DNS host. Fail2ban will not
# ban a host which matches an address in this list. Several addresses can be
# defined using space separator.
ignoreip = 127.0.0.1
 
# "bantime" is the number of seconds that a host is banned.
bantime = 600
 
# A host is banned if it has generated "maxretry" during the last "findtime"
# seconds.
findtime = 600
 
# "maxretry" is the number of failures before a host get banned.
maxretry = 3


Let me describe each rule section with their description and what purpose we use these rules.
  1. ignoreip : IgnoreIP section allows you to white list certain IP addresses from blocking. Here, you can specify list of IP addresses with space separated and make sure you include your address.
  2. bantime : The number of seconds that a host would be banned from the server. The default is set for 600 (600 seconds = 10 minutes), you may increase this to an hour or higher if you like.
  3. findtime : The amount of time that a host has to log in. The default is set to 10 minutes, it means that if a host attempts, and fails, to log in more than the maxretry number of times, they will be banned.
  4. maxretry : The number of failed login attempts before a host is blocked for the length of the ban time.
Configuring ssh-iptables section for Fail2Ban
The following section is the default ssh-iptables section and it is turned on by default. So, you don’t need to make any changes to this section,
[ssh-iptables]

enabled  = true
filter   = sshd
action   = iptables[name=SSH, port=ssh, protocol=tcp]
           sendmail-whois[name=SSH, dest=root, sender=fail2ban@example.com]
logpath  = /var/log/secure
maxretry = 5
You can find the details of each rule described below.
  1. enabled : This section refers that SSH protection is on. You can turn it off by changing the word “true” to “false“.
  2. filter : This section by default set to sshd and refers the config file (/etc/fail2ban/filter.d/sshd.conf) containing the rules that fail2ban uses to find matches.
  3. action : This action tells the fail2ban to ban a matching IP address once a filter matches in the /etc/fail2ban/action.d/iptables.conf file. If your server have mail setup, you can add email address, where fail2ban sends you a email alerts whenever it bans an IP address. The sender section refers to file /etc/fail2ban/action.d/sendmail-whois.conf file.
  4. logpath : The log path is the location of logs where fail2ban will track.
  5. maxretry : The max retry section is the same definition as the default option that we discussed above.
Restarting Fail2Ban Service
Once you’ve made the changes to the fail2ban config file, then always make sure to restart Fail2Ban service.
# chkconfig --level 23 fail2ban on
# service fail2ban start
Starting fail2ban:                                         [  OK  ]
Verifying Fail2Ban iptables rules
Check the rules that fail2ban added in effect within the IP table section.
# iptables -L
I have made some failed login attempts from one of our server to the server where fail2ban installed and it works. You see the banned IP address of my server.

Watch Failed SSH login attempts

To see the current ssh failed login attempts, run the following command it will display a list of failed attempts attempted by hosts.
# cat /var/log/secure | grep 'Failed password' |  sort | uniq -c

Remove IP Address from Fail2Ban

To remove the banned IP address from the fail2ban iptable rules. Run the following command.
# iptables -D fail2ban-ssh 1

POSTFIX : Configuring Gmail as relay

Postfix part 2 BCC Maps , SMTP Auth , relay domains

Blind Carbon Copy Maps

#vim /etc/postfix/main.cf

#always_bcc = username  -->this user will get the copy of every message traversing/communicating in your system.
always_bcc = root       #you can use file redirects insted of root user

save/exit
#service postfix reload/restart

For demo:
send mail from userX  to userY, the root user will get the copy of message.

-- -- -- --- -
To get BCC msg Sent (Received) by selective user

[root@server1 postfix]# vim /etc/postfix/main.cf
#always_bcc = root
sender_bcc_maps = hash:/etc/postfix/sender_bcc                                                       
#recipient_bcc_maps = hash:/etc/postfix/recipient_bcc    //mail received by user listed in recipient_bcc will be bcc'd to target user/file

[root@server1 postfix]#vim /etc/postfix/sender_bcc
#LHS(sender to match)   RHS(BCC Recipient)
salman                  root

[root@server1 postfix]#postmap sender_bcc

[root@server1 postfix]# file sender_bcc.db      < - hash db created
sender_bcc.db: Berkeley DB (Hash, version 9, native byte-order)

= = = = = = =  =  =
=   SMTP Auth  =
= = = = = = =  =  =

[root@server1 sasl2]# rpm -qa | grep sasl
cyrus-sasl-lib-2.1.23-13.el6_3.1.i686
cyrus-sasl-plain-2.1.23-13.el6_3.1.i686
cyrus-sasl-gssapi-2.1.23-13.el6_3.1.i686
cyrus-sasl-2.1.23-13.el6_3.1.i686
cyrus-sasl-devel-2.1.23-13.el6_3.1.i686
cyrus-sasl-md5-2.1.23-13.el6_3.1.i686

#vim /etc/postfix/main.cf
             #add
smtpd_sasl_path=smtpd             
smtpd_sasl_auth_enable = yes    

(we are using pam authentication)

#cat /etc/sysconfig/saslauthd                                       #for more info and modification

...................................................................................................................................................
#vim /usr/lib/sasl2/smtpd.conf

pwcheck_method: saslauthd
mech_list: PLAIN LOGIN


[root@server1 postfix]#service saslauthd start                    
OR
[root@server1 postfix]# saslauthd -a pam                           
[root@server1 postfix]# ps -ef | grep sasl
root      1281     1  0 07:54 ?        00:00:00 saslauthd -a pam
root      1282  1281  0 07:54 ?        00:00:00 saslauthd -a pam
root      1283  1281  0 07:54 ?        00:00:00 saslauthd -a pam
root      1284  1281  0 07:54 ?        00:00:00 saslauthd -a pam
root      1285  1281  0 07:54 ?        00:00:00 saslauthd -a pam
root      1290  1261  0 07:56 pts/0    00:00:00 grep sasl

# vim /etc/postfix/main.cf

smtpd_sasl_auth_enable = yes


smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination 



Relaydomain database
- - - -- - -  - - - - - - - --  --
Defining Rlay_domains Maps
# rpm -qa | grep db
Initially check for the Berkley DB packages are installed. These packages will be used by the postfix for database support.

/etc/postfix/main.cf

relay_domains = $ mydestination,  hash:/etc/postfix/relay_domains    #this could be any name


# vim /etc/postfix/relaydomains
domain1.com
domain2.com
domain3.com
domain4.com
domain5.com
# postmap /etc/postfix/relaydomains
# postfix reload

iptables

# Modify this file accordingly for your specific requirement.

# 1. Delete all existing rules

iptables -F

# 2. Set default chain policies

iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT DROP

# 3. Block a specific ip-address

#BLOCK_THIS_IP="x.x.x.x"
#iptables -A INPUT -s "$BLOCK_THIS_IP" -j DROP

# 4. Allow ALL incoming SSH
#iptables -A INPUT -i eth0 -p tcp --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
#iptables -A OUTPUT -o eth0 -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT

# 5. Allow incoming SSH only from a sepcific network
#iptables -A INPUT -i eth0 -p tcp -s 192.168.200.0/24 --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
#iptables -A OUTPUT -o eth0 -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT

# 6. Allow incoming HTTP
#iptables -A INPUT -i eth0 -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT
#iptables -A OUTPUT -o eth0 -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT

# Allow incoming HTTPS
#iptables -A INPUT -i eth0 -p tcp --dport 443 -m state --state NEW,ESTABLISHED -j ACCEPT
#iptables -A OUTPUT -o eth0 -p tcp --sport 443 -m state --state ESTABLISHED -j ACCEPT

# 7. MultiPorts (Allow incoming SSH, HTTP, and HTTPS)
iptables -A INPUT -i eth0 -p tcp -m multiport --dports 22,80,443 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp -m multiport --sports 22,80,443 -m state --state ESTABLISHED -j ACCEPT

# 8. Allow outgoing SSH
iptables -A OUTPUT -o eth0 -p tcp --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -i eth0 -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT

# 9. Allow outgoing SSH only to a specific network
#iptables -A OUTPUT -o eth0 -p tcp -d 192.168.101.0/24 --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
#iptables -A INPUT -i eth0 -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT

# 10. Allow outgoing HTTPSiptables -A OUTPUT -o eth0 -p tcp --dport 443 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -i eth0 -p tcp --sport 443 -m state --state ESTABLISHED -j ACCEPT

# 11. Load balance incoming HTTPS traffic
#iptables -A PREROUTING -i eth0 -p tcp --dport 443 -m state --state NEW -m nth --counter 0 --every 3 --packet 0 -j DNAT --to-destination 192.168.1.101:443
#iptables -A PREROUTING -i eth0 -p tcp --dport 443 -m state --state NEW -m nth --counter 0 --every 3 --packet 1 -j DNAT --to-destination 192.168.1.102:443
#iptables -A PREROUTING -i eth0 -p tcp --dport 443 -m state --state NEW -m nth --counter 0 --every 3 --packet 2 -j DNAT --to-destination 192.168.1.103:443

# 12. Ping from inside to outside
iptables -A OUTPUT -p icmp --icmp-type echo-request -j ACCEPT
iptables -A INPUT -p icmp --icmp-type echo-reply -j ACCEPT

# 13. Ping from outside to inside
iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
iptables -A OUTPUT -p icmp --icmp-type echo-reply -j ACCEPT

# 14. Allow loopback access
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT

# 15. Allow packets from internal network to reach external network.
# if eth1 is connected to external network (internet)
# if eth0 is connected to internal network (192.168.1.x)
iptables -A FORWARD -i eth0 -o eth1 -j ACCEPT

# 16. Allow outbound DNS
#iptables -A OUTPUT -p udp -o eth0 --dport 53 -j ACCEPT
#iptables -A INPUT -p udp -i eth0 --sport 53 -j ACCEPT

# 17. Allow NIS Connections
# rpcinfo -p | grep ypbind ; This port is 853 and 850
#iptables -A INPUT -p tcp --dport 111 -j ACCEPT
#iptables -A INPUT -p udp --dport 111 -j ACCEPT
#iptables -A INPUT -p tcp --dport 853 -j ACCEPT
#iptables -A INPUT -p udp --dport 853 -j ACCEPT
#iptables -A INPUT -p tcp --dport 850 -j ACCEPT
#iptables -A INPUT -p udp --dport 850 -j ACCEPT

# 18. Allow rsync from a specific network
iptables -A INPUT -i eth0 -p tcp -s 192.168.101.0/24 --dport 873 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --sport 873 -m state --state ESTABLISHED -j ACCEPT

# 19. Allow MySQL connection only from a specific network
iptables -A INPUT -i eth0 -p tcp -s 192.168.200.0/24 --dport 3306 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --sport 3306 -m state --state ESTABLISHED -j ACCEPT

# 20. Allow Sendmail or Postfix
iptables -A INPUT -i eth0 -p tcp --dport 25 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --sport 25 -m state --state ESTABLISHED -j ACCEPT

# 21. Allow IMAP and IMAPS
iptables -A INPUT -i eth0 -p tcp --dport 143 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --sport 143 -m state --state ESTABLISHED -j ACCEPT

iptables -A INPUT -i eth0 -p tcp --dport 993 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --sport 993 -m state --state ESTABLISHED -j ACCEPT

# 22. Allow POP3 and POP3S

iptables -A INPUT -i eth0 -p tcp --dport 110 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --sport 110 -m state --state ESTABLISHED -j ACCEPT

iptables -A INPUT -i eth0 -p tcp --dport 995 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --sport 995 -m state --state ESTABLISHED -j ACCEPT

# 23. Prevent DoS attack
iptables -A INPUT -p tcp --dport 80 -m limit --limit 25/minute --limit-burst 100 -j ACCEPT

# 24. Port forwarding 422 to 22
iptables -t nat -A PREROUTING -p tcp -d 192.168.102.37 --dport 422 -j DNAT --to 192.168.102.37:22
iptables -A INPUT -i eth0 -p tcp --dport 422 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --sport 422 -m state --state ESTABLISHED -j ACCEPT

# 25. Log dropped packets

iptables -N LOGGING
iptables -A INPUT -j LOGGING
iptables -A LOGGING -m limit --limit 2/min -j LOG --log-prefix "IPTables Packet Dropped: " --log-level 7
iptables -A LOGGING -j DROP

Postfix part 1 DNS, aliases, vacation , sender receiver canonical maps

http://flurdy.com/docs/postfix/#config-imap-dovecot

Setup the system time
http://repos.oostergo.net/6/postfix-2.11/                              
[root@server1 postfix]# date --set="26 May 2014 22:56:00"
Mon May 26 22:56:00 NPT 2014

Setting up D.N.S record           Example 1                                                                             
#yum install bind*
On centos 6.5 problem in starting named may occur to resolve follow below step:-
 [root@mta1 ~]# service named start
Generating /etc/rndc.key:                               ..Stucks here


[root@mta1 ~]# rndc-confgen -a -r /dev/urandom
wrote key file "/etc/rndc.key"


 #service named start

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

#cat /etc/named.conf
...
.......
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
zone "blues.com" IN {
    type master;
    file "blues.com";
    allow-update { none; };
};
zone "213.168.192.in-addr.arpa" IN {
    type master;
    file "192.168.213.zone";
    allow-update { none; };
};
recursion no;   #for testing in virtual enviroment
---------------------------------------------------------------------------------

Forward Zone 1                       
[root@localhost named]# cat blues.com
$TTL 1D ; time a RR may be cached(or saved) by another DNS server.
$ORIGIN blues.com.
@    IN SOA    server1.blues.com. dnsadmin.blues.com (
                    2014130501    ; serial
                    1D    ; refresh When the refreshvalue is reached, the slave name server for this zone will try to read the SOA RR from the zone master
                    1H    ; retry Defines the retry interval in secondsif the slave fails to make contact with the zone master during a refresh cycle. Typical values are from 10 to 60 minutes.
                    1W    ; expire Defines the time in seconds after which the zone records are assumed to be no longer authoritative
                    3H )    ; minimum
@  IN    NS    server1.blues.com.
@  IN   MX 10 server1.blues.com.

server1.blues.com.  IN    A 192.168.213.10


Setting up D.N.S record              Example  2                                                                          

                                       Forward Zone 2                                                 
[root@localhost named]# vim sagarmatha.org

$TTL 1D ; time a RR may be cached(or saved) by another DNS server.
$ORIGIN sagarmatha.org.
@    IN SOA    sagarmatha.org. dnsadmin.sagarmatha.org (
                    2014130502    ; serial
                    1D    ; refresh When the refreshvalue is reached, the slave name server for this zone will try to read the SOA RR from the zone master
                    1H    ; retry Defines the retry interval in secondsif the slave fails to make contact with the zone master during a refresh cycle. Typical values are from 10 to 60 minutes.
                    1W    ; expire Defines the time in seconds after which the zone records are assumed to be no longer authoritative
                    3H )    ; minimum

@  IN    NS    server1.sagarmatha.org.
@  IN   MX 10 server1.sagarmatha.org.

server1                       IN A 192.168.213.10
sagarmatha.org.           IN A 192.168.213.10
www                          IN CNAME server1.sagarmatha.org.
mail                            IN CNAME server1.sagarmatha.org.
Reverse Zone
[root@server1 named]# cat 192.168.213.zone
$TTL 1D
@    IN SOA    server1.blues.com. dnsadmin.blues.com. (
                    2014130504    ; serial
                    1D    ; refresh
                    1H    ; retry
                    1W    ; expire
                    3H )    ; minimum
213.168.192.in-addr.arpa.  IN    NS    server1.blues.com.

10 IN    PTR    server1.blues.com.

############
postfix aliases (mail will be redirected to users mentioned on list)                     

1)one to one
vim /etc/aliases
postmaster: root    <=this is one to one where root is reciepient
2)one to many (or List alias)
sales:  root,user12,user3    <=this is one to many where blue-highlighted items are recipients for group sales
3)include example:
support:  :include:/etc/postfix/support_list.txt
4)File eg.  abuse:  /var/log/mail/abuse.mail    <=mail will be appended to the target file (here the file is abuse.mail)
5)Pipes  eg-  help:  |/usr/local/bin/sendhelp   <=pipes allow another application or script take care of the mail.
Run #newaliases   
after changing /etc/aliases

##############
local.forward    File
any message destined to user1@exampledomain.com  can be further redirected to another account or another acc. on another machine 
First install the vacation program
youcan download the vacation binary here http://puias.math.ias.edu/data/puias/6/x86_64/os/Addons/vacation-1.2.7.0-7.puias6.x86_64.rpm
now in my case ,
[root@mailvm ~]# yum install vacation-1.2.7.0-7.puias6.x86_64.rpm
Transaction Test Succeeded
Running Transaction
  Installing : vacation-1.2.7.0-7.puias6.x86_64                                                                                                                    1/1
  Verifying  : vacation-1.2.7.0-7.puias6.x86_64                                                                                                                   1/1 Installed:
  vacation.x86_64 0:1.2.7.0-7.puias6

[root@mailvm ~]# which vacation
/usr/bin/vacation

Create a hidden file .vacation.msg and write your message on it :

[orange@mailvm ~]$ cat .vacation.msg
Hi !! I am on vacation

Create a hidden file .forward

[orange@mailvm ~]$ cat .forward
\orange, "|/usr/bin/vacation orange"    #here orange is a local linux acc user

Note :  the " \ "infront of "orange," will tell postfix not to do  any further lookups for alias orange and
|  will pipe the email to the vacation program to process

this notation \orange, "|/usr/bin/vacation orange"    caues the vacation message sent back to user.

Initialize the vacation program
$ vacation -i
$ls -al
 -rw-r--r--. 1 orange orange 12288 May 16 23:07 .vacation.db   <=new file created after initializing vacation program.
all the messages that are sent to sender as response are stored and know when/who to respond ,mitigates DOS attacks

Now for demo:
ssh into your machine as "root" and send mail to user  "orange" using mail or mutt here i used mutt
the message to the root appears like this
[root@mailvm Mail]# mutt

i:Exit  -:PrevPg  <Space>:NextPg v:View Attachm.  d:Del  r:Reply  j:Next ?:Help
Date: Fri, 16 May 2014 23:18:39 +0545 (NPT)
From: orange@mailvm.fender.com
To: root@mailvm.fender.com
User-Agent: 1.2.7 http://vacation.sourceforge.net

Hi Iam on vacation leave

#sendmail -v user11@remotesystem.com
testing remote mail
Ctrl+d( to send)
- --  -- -- --  -- -- --  -- -- --  -- -- --  -- -- --  -- -- --  -- -- --  -- -- --  -- -- --  -- -- --  -- -- --  -- -- --

#cd /var/spool/postfix/maildrop
messages are dropped in maildrop using postfix compatible command called sendmail with/out postfix master process need not necessary to run

pickup process (usr/libexec/pickup)spawned by master program feeds locally submitted message to cleanup process(takes care of addressing task like

from: to: fqdn check etc)
message is then moved to qmgr process(deliver message using localmailing or localmailing and smtp)


# cat /etc/nsswitch.conf
this file contains directives which dictates order in which name resolution occurs

-- --  -- -- --  -- -- --  -- -- --  -- -- --  -- -- --  -- -- --  -- -- --  -- -- --  -- -- --  -- -- --  -- -- --  -- -- - myorigin / masquerading
-- -- -- -- -- -- -- -- -- --
Define outbound envelope information [masquerading] not header information
$mydomain=example1.com
$myorigin=$mydomain

$myorigin is used for masquerading



-- -- ---- -- ---- -- ---- -- ---- -- ---- -- ---- -- ---- -- ---- -- ---- -- ---- -- ---- -- ---- -- ---- -- --
note: mail routing is based on header information.  

 #service postfix reload

check for new mail check duration
user123@mailserver1.example.com$ set  | grep -i mail
MAIL=/var/mail/user123
MAILCHECK=60       ;;mailcheck is 60 seconds


"  canonical maps  "                                                                               
                         @For         --             Local users
Types :
  1. #canonical_maps = hash:/etc/postfix/canonical      //will effect   sender/receiver
  2. #sender_canonical_maps=hash:/etc/postfix/canonical   //will effect only sender part , rcpt portion is   untouched
  3. #recipient_canonical_maps=hash:/etc/postfix/canonical   //will effect only recipient part,sender portion is untouched 



(rewriting at cleanup process and trivial rewrite process is done)
canonical map will alter <envelope from> and <envelope to> addresses which are heading out of the machine to recipient.

vim /etc/postfix/canonical
#any message "from" user "apple" should be re written to "applefruit" and david to david.baekham
apple  applefruit
david      david.beckham


#vim /etc/postfix/main.cf

                                       [  type  :   /  location  ]     
canonical_maps =  hash:/etc/postfix/canonical


#postmap /etc/postfix/canonical    // this will generate (hash database) canonical.db file
note: postmap requires berkley library pkg's
@   with --> canonical_maps                                                               

{for inbound emaild}
#tail /var/log/maillog
May 26 18:46:21 mailvm postfix/pickup[1129]: EA2E0FF660: uid=501 from=<apple>
May 26 18:46:21 mailvm postfix/cleanup[1272]: EA2E0FF660: message-id=<20140526130121.GB1212@mailvm.urgens.com>
May 26 18:46:21 mailvm postfix/qmgr[1130]: EA2E0FF660: from=<applefruit@urgens.com>, size=433, nrcpt=1 (queue active)
May 26 18:46:22 mailvm postfix/local[1274]: EA2E0FF660: to=<root@mailvm.urgens.com>, relay=local, delay=0.11, delays=0.08/0.03/0/0, dsn=2.0.0, status=sent (delivered to mailbox)
May 26 18:46:22 mailvm postfix/qmgr[1130]: EA2E0FF660: removed
 

#changing /etc/aliases
.;;[user]    is equivalent to local user dean ;;       
sales: user1,root,managersales
applefruit:      apple
save/exit
#new aliases


@/etc/postfix/main.cf
-- -- -- -- --   -- -- - - - -- -- - - -- -- - - - -- - - - -   - - -  - -- --  --  - - - -  
Summary
-- -- - --  --  -- - -- -- - -- -- - - -- -- - -- - -- - -   -- --  -- - -- - - - -- - - -
#canonical_maps = hash:/etc/postfix/canonical      //will effect sender/receiver


#sender_canonical_maps=hash:/etc/postfix/canonical   //will effect only sender part , rcpt portion is   untouched
#recipient_canonical_maps=hash:/etc/postfix/canonical   //will effect only recipient part,sender portion is untouched

----- 

with sender_canonical_maps                                            .

From applefruit@urgens.com  Mon May 26 23:36:02 2014
Return-Path: <applefruit@urgens.com>
X-Original-To: apple@mailvm.urgens.com
Delivered-To: apple@mailvm.urgens.com
Received: by mailvm.urgens.com (Postfix, from userid 501)
           id 30BE4FF6A0; Mon, 26 May 2014 23:36:02 +0545 (NPT)
Date: Mon, 26 May 2014 23:36:02 +0545
From: applefruit@urgens.com
To: apple@mailvm.urgens.com
Subject: sender canonical test
Message-ID: <20140526175102.GA1574@mailvm.urgens.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
User-Agent: Mutt/1.5.20 (2009-12-10)

with recipient_canonical_maps   

From apple@urgens.com  Mon May 26 23:39:42 2014
Return-Path: <apple@urgens.com>
X-Original-To: apple@mailvm.urgens.com
Delivered-To: applefruit@urgens.com
Received: by mailvm.urgens.com (Postfix, from userid 501)
           id 31346FF683; Mon, 26 May 2014 23:39:42 +0545 (NPT)
Date: Mon, 26 May 2014 23:39:42 +0545
From: apple@mailvm.urgens.com
To: applefruit@urgens.com
Subject: reciepient canonical test
Message-ID: <20140526175442.GB1574@mailvm.urgens.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
User-Agent: Mutt/1.5.20 (2009-12-10)

Notice the envelope and header parts ...


mysql reset user password

Setting, Changing And Resetting MySQL Root Passwords

 
This tutorial explains how you can set, change and reset (if you've forgotten the password) MySQL root passwords. Time and again I see problems like mysqladmin:  connect to server at 'localhost' failed error: 'Access denied for user 'root'@'localhost' (using password: YES)'. So I thought it's time to remind you how to solve MySQL related password problems. If you are just looking for a quick fix how to reset a MySQL root password you can find that at the bottom of this tutorial.

mysqladmin Command To Change Root Password

Method 1 - Set up root password for the first time

If you have never set a root password for MySQL, the server does not require a password at all for connecting as root. To set up a root password for the first time, use the mysqladmin command at the shell prompt as follows:
$ mysqladmin -u root password newpass
If you want to change (or update) a root password, then you need to use the following command:
$ mysqladmin -u root -p oldpassword newpass
Enter password:
If you get...
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: YES)'
then follow the instructions below on how to recover your MySQL password.

Change MySQL password for other users

To change a normal user password you need to type:
$ mysqladmin -u user-name -p oldpassword newpass
 

Method 2 - Update or change password

MySQL stores usernames and passwords in the user table inside the MySQL database. You can directly update a password using the following method to update or change passwords:
1) Login to the MySQL server, type the following command at the shell prompt:
$ mysql -u root -p
2) Use the mysql database (type commands at the mysql> prompt):
mysql> use mysql;
3) Change password for a user:
mysql> update user set password=PASSWORD("newpass") where User='ENTER-USER-NAME-HERE';
4) Reload privileges:
mysql> flush privileges;
mysql> quit
This method you need to use while using PHP or Perl scripting.

Recover MySQL root password

You can recover a MySQL database server password with the following five easy steps:
Step # 1: Stop the MySQL server process.
Step # 2: Start the MySQL (mysqld) server/daemon process with the --skip-grant-tables option so that it will not prompt for a password.
Step # 3: Connect to the MySQL server as the root user.
Step # 4: Set a new root password.
Step # 5: Exit and restart the MySQL server.
Here are the commands you need to type for each step (log in as the root user):
Step # 1 : Stop the MySQL service:
# /etc/init.d/mysql stop
Output:
Stopping MySQL database server: mysqld.
Step # 2: Start the MySQL server w/o password:
# mysqld_safe --skip-grant-tables &
Output:
[1] 5988
Starting mysqld daemon with databases from /var/lib/mysql
mysqld_safe[6025]: started
Step # 3: Connect to the MySQL server using the MySQL client:
# mysql -u root
Output:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 4.1.15-Debian_1-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>
Step # 4: Set a new MySQL root user password:
mysql> use mysql;
mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit
Step # 5: Stop the MySQL server:
# /etc/init.d/mysql stop
Output:
Stopping MySQL database server: mysqld
STOPPING server from pid file /var/run/mysqld/mysqld.pid
mysqld_safe[6186]: ended

[1]+  Done                    mysqld_safe --skip-grant-tables
Start the MySQL server and test it:
# /etc/init.d/mysql start
# mysql -u root -p

mysql secure installation error touch: cannot touch `.my.cnf.4519': Read-only file system

[root@mailvm Packages]# mysql_secure_installation
touch: cannot touch `.my.cnf.4519': Read-only file system
touch: cannot touch `.mysql.4519': Read-only file system
chmod: cannot access `.my.cnf.4519': No such file or directory
chmod: cannot access `.mysql.4519': No such file or directory

Just change your directory to other than dvd or cd
eg. to / or
and run #mysql_secure_installation