mail server in linux

Upload: kaushik2076

Post on 08-Apr-2018

235 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/7/2019 MAil Server in Linux

    1/27

    Configure Host Name Lookup in RHEL/CentOS 5

    Before starting to use Red Hat Enterprise Linux 5 or CentOS 5, the static host name table lookup file /etc/hosts must

    be corrected first. The steps below describes how to do this.

    Configure Host

    1. ClickApplications, selectSystem Tools then clickFile Browser. This will launch the File Browser window.

    http://www.linuxmail.info/configure-host-name-lookup-centos-5/http://www.linuxmail.info/images/centos-5/file-browser.pnghttp://www.linuxmail.info/configure-host-name-lookup-centos-5/
  • 8/7/2019 MAil Server in Linux

    2/27

    2. In theLocation field, type in/etc and press Enter. If you dont see the Location field, click the notepad button to

    toggle to text-based location bar.

    3. Locate and double click on the file hosts to open it for editing. Update the content similar to the lines below.

    127.0.0.1 localhost.localdomain localhost

    ::1 localhost6.localdomain6 localhost6

    192.168.0.4 mail.acme.local mail

    http://www.linuxmail.info/images/centos-5/edit-hosts.pnghttp://www.linuxmail.info/images/centos-5/file-browser-etc.png
  • 8/7/2019 MAil Server in Linux

    3/27

    Replace the last line with your ownIP address,fully qualified domain name and host name.

    Test the Host Name Lookup

    1. ClickApplications, selectAccessories, and clickTerminal. This will launch the Terminal window.

    http://www.linuxmail.info/images/centos-5/ping-localhost.pnghttp://www.linuxmail.info/images/centos-5/terminal.png
  • 8/7/2019 MAil Server in Linux

    4/27

    2. In the terminal window, type in the command below.

    ping localhost

    You should see localhost.localdomain and 127.0.0.1

    3. Next, type in the command below.

    ping mail

    Replace mailwith your own hostname. You should see your fully qualified domain name and ip address.

    Postfix SMTP Server Setup Howto for RHEL/CentOS 5

    Installing and setting up Postfix SMTP Server in Red Hat Enterprise Linux 5 or CentOS 5 is easy. Postfix has secure

    default settings so we just need to open it up a bit.

    Install Postfix and Mail Transport Agent Switcher

    http://www.linuxmail.info/postfix-smtp-server-howto-centos-5/http://www.linuxmail.info/images/centos-5/ping-mail.pnghttp://www.linuxmail.info/postfix-smtp-server-howto-centos-5/
  • 8/7/2019 MAil Server in Linux

    5/27

    1. If you did not add postfix and system-switch-mail-gnome during the CentOS installation, you can add it now

    using Package Managertool.

    Switch to Postfix from Sendmail:

    By default, Sendmail is the active SMTP server. Heres how to change it.

    http://www.linuxmail.info/how-to-add-remove-applications-centos-5/http://www.linuxmail.info/how-to-add-remove-applications-centos-5/http://www.linuxmail.info/images/centos-5/package-manager.pnghttp://www.linuxmail.info/how-to-add-remove-applications-centos-5/
  • 8/7/2019 MAil Server in Linux

    6/27

    1. ClickSystem,

    selectAdministration, and clickMail Transport Agent Switcher. This will launch the system-switch-mailwindow.

    2. In the system-

    switch-mail window, selectPostfixand clickOk.

    Configure Postfix

    http://www.linuxmail.info/images/centos-5/system-switch-mail.pnghttp://www.linuxmail.info/images/centos-5/mail-transport-switcher.png
  • 8/7/2019 MAil Server in Linux

    7/27

    1. ClickApplications,

    selectSystem Tools then clickFile Browser. This will launch the File Browser window.

    2. In

    theLocation field, type in/etc/postfixand press Enter. If you dont see the Location field, click the notepad button to

    toggle to text-based location bar.

    http://www.linuxmail.info/images/centos-5/file-browser-2.pnghttp://www.linuxmail.info/images/centos-5/file-browser.png
  • 8/7/2019 MAil Server in Linux

    8/27

    3. Double click on the

    file main.cfto open it for editing. We need to make it listen to network request, accept mails bound to our domain and

    usemaildirwhich is a better mailbox format than mbox the default.

    Find the following keys and change its values as follows

    inet_interfaces = all

    mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

    home_mailbox = Maildir/

    In main.cf, lines starting with # are comments. Save the file after completing your changes.

    Make sure that all mail_spool_directory lines are commented out. Otherwise, it will override the

    setting in the home_mailbox line above.

    http://www.linuxmail.info/mbox-maildir-mail-storage-formats/http://www.linuxmail.info/mbox-maildir-mail-storage-formats/http://www.linuxmail.info/mbox-maildir-mail-storage-formats/http://www.linuxmail.info/images/centos-5/edit-main-cf.pnghttp://www.linuxmail.info/mbox-maildir-mail-storage-formats/
  • 8/7/2019 MAil Server in Linux

    9/27

    4. Restart the postfix service.Learn how to restart services here.

    Test Postfix

    1. ClickApplications,

    selectAccessories, and clickTerminal. This will launch the Terminal window.

    http://www.linuxmail.info/how-to-start-stop-services-centos-5/http://www.linuxmail.info/how-to-start-stop-services-centos-5/http://www.linuxmail.info/images/centos-5/terminal-shortcut.pnghttp://www.linuxmail.info/images/centos-5/service-config-2.pnghttp://www.linuxmail.info/how-to-start-stop-services-centos-5/
  • 8/7/2019 MAil Server in Linux

    10/27

    2. In

    the Terminal window, type in the highlighted commands below.

    Sample postfix session. Replacejohndoe with any valid user account. The dot after the line test is a command that

    should be typed in.

    If you need to add new user accounts,learn how to add or remove user accounts here.

    [root@mail ~]# telnet localhost smtp

    Trying 127.0.0.1...

    Connected to localhost.localdomain (127.0.0.1).

    Escape character is '^]'.

    220 mail.acme.local ESMTP Postfix

    ehlo localhost

    250-mail.acme.local

    250-PIPELINING

    250-SIZE 10240000

    250-VRFY

    250-ETRN

    250-ENHANCEDSTATUSCODES

    250-8BITMIME

    250 DSN

    mail from:

    250 2.1.0 Ok

    rcpt to:

    250 2.1.5 Ok

    data

    http://www.linuxmail.info/how-to-add-remove-user-accounts-centos-5/http://www.linuxmail.info/how-to-add-remove-user-accounts-centos-5/http://www.linuxmail.info/images/centos-5/terminal.pnghttp://www.linuxmail.info/how-to-add-remove-user-accounts-centos-5/
  • 8/7/2019 MAil Server in Linux

    11/27

    354 End data with .

    test

    .

    250 2.0.0 Ok: queued as 9729067C17

    quit

    221 2.0.0 Bye

    Connection closed by foreign host.

    [root@mail ~]#

    To check if the mail indeed exists

    [root@mail ~]# cd /home/johndoe/Maildir/new

    [root@mail new]# ls

    1185669817.Vfd00I18012M795756.mail.acme.local

    [root@mail new]# cat 1185669817.Vfd00I18012M795756.mail.acme.local

    Dont worry, you dont have to type in the whole filename above. Just type in the first few characters say118 then

    press Tab to activate automatic completion.

    From [email protected] Thu Feb 22 21:48:28 2007

    Return-Path:

    X-Original-To: johndoe

    Delivered-To: [email protected]

    Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])

    by mail.acme.local (Postfix) with SMTP id 9729067C17

    for ; Thu, 22 Feb 2007 21:48:26 -0500 (EST)

    Message-Id:

    Date: Thu, 22 Feb 2007 21:48:26 -0500 (EST)

    From: [email protected]

    To: undisclosed-recipients:;

    test

    [root@mail mail]#

    If you encounter any problems, check the log file at/var/log/maillog.

    Review yourPostfix aliases configuration file. There are some predefined email aliases that might conflict with

    your existing mail accounts like sales, marketing, info, etc.

    How to Add or Remove User Accounts in RHEL/CentOS 5

    In Linux, new user accounts automatically receive mail accounts. Here are the steps for adding a new user account in

    Red Hat Enterprise Linux 5 and its derivative CentOS 5.

    Manage User and Group Accounts (GUI)

    http://www.linuxmail.info/postfix-aliases-mailing-list/http://www.linuxmail.info/postfix-aliases-mailing-list/http://www.linuxmail.info/how-to-add-remove-user-accounts-centos-5/http://www.linuxmail.info/postfix-aliases-mailing-list/http://www.linuxmail.info/how-to-add-remove-user-accounts-centos-5/
  • 8/7/2019 MAil Server in Linux

    12/27

    This section describes how to use the User Manager to manage the user and group accounts.

    1. ClickApplications then selectSystem Settings and clickUsers and Groups. This will launch the User

    Manager window.

    http://www.linuxmail.info/images/centos-5/user-manager.pnghttp://www.linuxmail.info/images/centos-5/users-and-groups.png
  • 8/7/2019 MAil Server in Linux

    13/27

    2. In the User Manager window, clickAdd User. This will show the Create New User window.

    3. In the Create New User window, fill in the User Name,Full Name,Passwordand Confirm Password.

    ClickOk when youre done.

    To avoid user account related problems, do not use uppercase letters when creating user names.

    http://www.linuxmail.info/images/centos-5/create-new-user.png
  • 8/7/2019 MAil Server in Linux

    14/27

    4. Thats it, you have just created a new user. To remove a user, select the user you want to remove and clickDelete.

    Manage User and Group Accounts (Console)

    Below are the console commands to manage the user and group accounts. Type in any of the commands below

    without any parameter to see that commands help information.

    /usr/sbin/useradd [options] login_name

    creates a new user

    /usr/sbin/usermod [options] login_name

    modifies a users attributes

    /usr/sbin/userdel [options] login_name

    deletes the specified user. Use the -roption to automatically remove the users home directory and mail spool.

    /usr/bin/passwd login_name

    sets the password for the specified user

    /usr/sbin/groupadd [options] group_name

    creates a new group

    /usr/sbin/groupmod [options] group_namemodifies a groups attributes

    /usr/sbin/groupdel group_name

    deletes the specified group

    Setup of user password Expiration:

    http://www.linuxmail.info/images/centos-5/user-manager-2.png
  • 8/7/2019 MAil Server in Linux

    15/27

    1.

    ClickApplications then selectSystem Settings and clickUsers and Groups. This will launch the User

    Manager window.

    2. Select the user you wish to configure and clickProperties.

    http://www.linuxmail.info/images/centos-5/user-manager-2.pnghttp://www.linuxmail.info/images/centos-5/users-and-groups.png
  • 8/7/2019 MAil Server in Linux

    16/27

    3. In the User Properties windows, click thePassword Info tab.

    4. Check theEnable Password Expiration checkbox to enable password expiration. The list below describes the

    available settings.

    Days before change allowed

    Number of days from the last password change to allow another password change.

    http://www.linuxmail.info/images/centos-5/user-manager-password-info.pnghttp://www.linuxmail.info/images/centos-5/user-manager-user-data.png
  • 8/7/2019 MAil Server in Linux

    17/27

    Days before change required

    Number of days from the last password change to require another password change.

    Days warning before change

    Number of days before the expiry of the password to notify the user.

    Days before account inactive

    Number of inactive days after the expiry of the password to deactivate the account. 0 means

    do not deactivate.

    You can also do this from the command line, below are the equivalent commands.

    chage login_name

    modifies the password expiry information of the specified login name. You need root access to use this command.

    chage -l login_name

    shows the password expiry information of the specified login name

    chage

    displays the help information

    You can notify the users with expiring password via email using the checkpwexpire script. Copy the script into

    the/etc/cron.daily and give it execute permission so it will automatically run every day.

    Dovecot POP3/IMAP Server Setup Howto for RHEL/CentOS 5

    Installing and setting up Dovecot in Red Hat Enterprise Linux 5 or CentOS 5 is easy. All we have to do is to enable the

    services we would like to provide and we are good to go.

    Install Dovecot

    http://www.linuxmail.info/files/checkpwexpirehttp://www.linuxmail.info/files/checkpwexpirehttp://www.linuxmail.info/install-setup-dovecot-centos-5/http://www.linuxmail.info/files/checkpwexpirehttp://www.linuxmail.info/install-setup-dovecot-centos-5/
  • 8/7/2019 MAil Server in Linux

    18/27

    1. If you did not add dovecot during the CentOS installation, you can add it now using Package Manager.

    Configure Dovecot

    1. ClickApplications, selectSystem Tools then clickFile Browser. This will launch the File Browser window.

    http://www.linuxmail.info/how-to-add-remove-applications-centos-5/http://www.linuxmail.info/images/centos-5/file-browser.pnghttp://www.linuxmail.info/images/centos-5/package-manager.pnghttp://www.linuxmail.info/how-to-add-remove-applications-centos-5/
  • 8/7/2019 MAil Server in Linux

    19/27

    2. In theLocation field, type in/etc and press Enter. If you dont see the Location field, click the notepad button to

    toggle to text-based location bar.

    3. Double click on the file dovecot.confto open it for editing. We need to change a few key items.

    Find the following keys and change its values as follows

    http://www.linuxmail.info/images/centos-5/edit-dovecot-cf.pnghttp://www.linuxmail.info/images/centos-5/file-browser-3.png
  • 8/7/2019 MAil Server in Linux

    20/27

    protocols = pop3 pop3s imap imaps

    mail_location = maildir:~/Maildir/

    pop3_uidl_format = %08Xu%08Xv

    imap_client_workarounds = delay-newmail outlook-idle netscape-eoh

    pop3_client_workarounds = outlook-no-nuls oe-ns-eoh

    For 64-bit users: Add the line login_process_size = 64 in the file/etc/dovecot.conf.

    Lines starting with # are comments. The last two line enables workarounds for various client bugs. Save the file after

    completing your changes.

    4. Start the dovecot service.Learn how to start and stop services here.

    Test Dovecot

    http://www.linuxmail.info/how-to-start-stop-services-centos-5/http://www.linuxmail.info/how-to-start-stop-services-centos-5/http://www.linuxmail.info/images/centos-5/service-config.pnghttp://www.linuxmail.info/how-to-start-stop-services-centos-5/
  • 8/7/2019 MAil Server in Linux

    21/27

    1. ClickApplications, selectAccessories, and clickTerminal. This will launch the Terminal window.

    2. In the Terminal window, type in the highlighted commands below.

    Sample dovecot session. Replacejohndoe and password with any valid user name and password.

    http://www.linuxmail.info/images/centos-5/terminal.pnghttp://www.linuxmail.info/images/centos-5/terminal-shortcut.png
  • 8/7/2019 MAil Server in Linux

    22/27

    [root@mail ~]# telnet localhost pop3

    +OK dovecot ready.

    user johndoe

    +OK

    pass password

    +OK Logged in.

    list

    +OK 1 messages:1 622

    .

    retr 1

    +OK 622 octets

    Return-Path:

    X-Original-To: johndoe

    Delivered-To: [email protected]

    Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])

    by mail.acme.local (Postfix) with SMTP id 9729067C17

    for ; Thu, 22 Feb 2007 09:06:37 -0500 (EST)

    Message-Id: Date: Thu, 22 Feb 2007 09:06:37 -0500 (EST)

    From: [email protected]

    To: undisclosed-recipients:;

    X-IMAPbase: 1172153557 1

    Status: O

    X-UID: 1

    Content-Length: 5

    X-Keywords:

    test

    .

    quit

    +OK Logging out.

    Connection closed by foreign host.

    [root@mail ~]#

    If you encounter any problems, check the log file at/var/log/maillog.

    Postfix SMTP Authentication and Dovecot SASL

    SMTP Authentication (SMTP Auth) provides an access control mechanism that can be used to allow legitimate

    users to relay mail while denying relay service to unauthorized users, such as spammers.

    Thanks to the new SASL support in Dovecot 1.0 and the new Dovecot SASL support in Postfix 2.3, setting up SMTP

    authentication is now easier. Instead of setting up two separate authentication for Postfix and Dovecot, we can now

    just setup the authentication in Dovecot and just let Postfix talk to Dovecot.

    http://www.linuxmail.info/postfix-smtp-auth-dovecot-sasl/http://www.linuxmail.info/postfix-smtp-auth-dovecot-sasl/
  • 8/7/2019 MAil Server in Linux

    23/27

    Configure Postfix and Dovecot

    1. Edit the file/etc/dovecot.confand make sure your auth defaultsection has the lines below.

    auth default {

    socket listen {

    client {

    path = /var/spool/postfix/private/auth

    mode = 0660user = postfix

    group = postfix

    }

    }

    mechanisms = plain login

    }

    http://www.linuxmail.info/images/centos-5/edit-dovecot-conf-sasl.pnghttp://www.linuxmail.info/images/centos-5/edit-dovecot-conf-sasl.png
  • 8/7/2019 MAil Server in Linux

    24/27

    2.

    Edit/etc/postfix/main.cf, find the keys below and change its values as follows or add it at the bottom of the file if the

    key (the word before the = sign) cannot be found.

    mynetworks = 127.0.0.0/8

    smtpd_sasl_type = dovecot

    smtpd_sasl_path = private/auth

    smtpd_sasl_auth_enable = yes

    smtpd_recipient_restrictions = permit_mynetworks,

    permit_sasl_authenticated, reject_unauth_destinationbroken_sasl_auth_clients = yes

    The first line says trust only localhost, meaning only localhost can send email outside the network (relay). The last

    line is there to support old clients like Microsoft Outlook Express 4.0 and Microsoft Exchange 5.0 just in case

    someone is still using it.

    Lines starting with # are comments. Save the file after completing your changes.

    http://www.linuxmail.info/images/centos-5/edit-main-cf-dovecot-sasl.pnghttp://www.linuxmail.info/images/centos-5/edit-main-cf-dovecot-sasl.png
  • 8/7/2019 MAil Server in Linux

    25/27

    3.

    Restart the Dovecot and Postfix service. But if you installed MailScanner, restart MailScanner instead of Postfix.

    Test Postfix

    In

    a Terminal window, type in the highlighted commands below.

    Sample postfix session

    http://www.linuxmail.info/images/centos-5/telnet-smtp-sasl.pnghttp://www.linuxmail.info/images/centos-5/telnet-smtp-sasl.pnghttp://www.linuxmail.info/images/centos-5/service-config-2.pnghttp://www.linuxmail.info/images/centos-5/service-config-2.png
  • 8/7/2019 MAil Server in Linux

    26/27

    [root@mail ~]# telnet mail smtp

    Replace mail with the name of your server. We should not use localhost since localhost is a trusted client ip

    address. And make sure the domain name you specified does not resolve to 127.0.0.1 which is the IP address of

    localhost.

    Trying 192.168.0.1...Connected to mail.acme.local (192.168.0.1).

    Escape character is '^]'.

    220 mail.acme.local ESMTP Postfix

    ehlo localhost

    250-mail.acme.local

    250-PIPELINING

    250-SIZE 10240000

    250-VRFY

    250-ETRN

    250-AUTH LOGIN PLAIN

    250-AUTH=LOGIN PLAIN250-ENHANCEDSTATUSCODES

    250-8BITMIME

    250 DSN

    Note the new250-AUTH lines. See the old SMTP Telnet Test.

    mail from:

    250 2.1.0 Ok

    rcpt to:

    554 5.7.1 : Relay access denied

    It works, now to check if we can send it after authenticating.

    auth plain AGpvaG5kb2UAcGFzc3dvcmQ=

    235 2.0.0 Authentication successful

    rcpt to:

    250 2.1.5 Ok

    quit

    221 2.0.0 Bye

    Connection closed by foreign host.

    [root@mail ~]#

    You can send to email addresses belonging to your domain without authentication. This is normal as it enables

    you to receive mail from the outside.

    The gibberish text afterAUTH PLAIN (http://www.linuxmail.info/postfix-smtp-auth-dovecot-sasl/ ) is

    the base64 encoded value of the user namejohndoe and passwordpassword. You can generate your own base64 text

    using the form below.

    Top of Form

    http://www.linuxmail.info/postfix-smtp-auth-dovecot-sasl/http://www.linuxmail.info/postfix-smtp-auth-dovecot-sasl/http://www.linuxmail.info/postfix-smtp-auth-dovecot-sasl/
  • 8/7/2019 MAil Server in Linux

    27/27

    User Name :

    Password :

    Result :

    Bottom of Form

    If you encounter any problems, check the log file at/var/log/maillog.