{"id":4534,"date":"2015-04-11T08:47:00","date_gmt":"2015-04-11T00:47:00","guid":{"rendered":"http:\/\/rmohan.com\/?p=4534"},"modified":"2015-04-11T19:12:51","modified_gmt":"2015-04-11T11:12:51","slug":"mail-server-on-centos-7-redhat-7","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=4534","title":{"rendered":"mail server on centos 7 Redhat 7"},"content":{"rendered":"<p>Setup mail server on centos 7<\/p>\n<p>This article helps you to install and configure basic mail server on Centos 7. Here i have used Postfix for SMTP, Dovecot for POP\/IMAP and Dovecot SASL for SMTP AUTH.<br \/>\nBefore proceeding please make sure you have assigned static IP for the server and have internet connectivity for installing packages.<\/p>\n<p>Setup mail server on centos 7<br \/>\n1. Installing packages<br \/>\n2. Postfix configuration<br \/>\n3. Dovecot configuration<br \/>\n4. User creation<\/p>\n<p>Installing packages<br \/>\nStep 1 \u00bb Assign hostname for the server using the below command.<br \/>\n[root@rmohan ~]# hostnamectl set-hostname mail.rmohan.com<\/p>\n<p>Step 2 \u00bb Make a host entry with your IP in \/etc\/hosts file.<br \/>\n192.168.1.20 mail.rmohan.com<\/p>\n<p>Step 3 \u00bb Now start installing packages.<br \/>\n[root@rmohan ~]# yum -y install postfix dovecot<\/p>\n<p>After package installation continue with postfix configuration.<\/p>\n<p>Postfix configuration<br \/>\nFirst create SSL certificate for encryption.<br \/>\nStep 4 \u00bb Follow the below steps one by one for creation.<br \/>\n[root@mail ~]# mkdir \/etc\/postfix\/ssl<br \/>\n[root@mail ~]# cd \/etc\/postfix\/ssl<br \/>\n[root@rmohan ssl]# openssl genrsa -des3 -out server.key 2048<br \/>\n[root@rmohan ssl]# openssl rsa -in server.key -out server.key.insecure<br \/>\n[root@rmohan ssl]# mv server.key server.key.secure<br \/>\n[root@rmohan ssl]# mv server.key.insecure server.key<br \/>\nLeave blank for A challenge password [] value in the below step.<br \/>\n[root@rmohan ssl]# openssl req -new -key server.key -out server.csr<br \/>\n[root@rmohan ssl]# openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt<\/p>\n<p>Step 5 \u00bb Now open \/etc\/postfix\/main.cf file for changes.<br \/>\nFind and uncomment the below lines.<br \/>\n#inet_interfaces = localhost #&#8212;&gt; line no 116<br \/>\n#mydestination = $myhostname, localhost.$mydomain, localhost #&#8211;&gt; line no 164<\/p>\n<p>and add below lines at the end of the file. change myhostname and mydomain values with yours and home_mailbox value to your desired directory. Here it will store mails in the users home directory (Eg: \/home\/rmohan\/mail ).<\/p>\n<p>myhostname = mail.rmohan.com<br \/>\nmydomain = rmohan.com<br \/>\nmyorigin = $mydomain<br \/>\nhome_mailbox = mail\/<br \/>\nmynetworks = 127.0.0.0\/8<br \/>\ninet_interfaces = all<br \/>\nmydestination = $myhostname, localhost.$mydomain, localhost, $mydomain<br \/>\nsmtpd_sasl_type = dovecot<br \/>\nsmtpd_sasl_path = private\/auth<br \/>\nsmtpd_sasl_local_domain =<br \/>\nsmtpd_sasl_security_options = noanonymous<br \/>\nbroken_sasl_auth_clients = yes<br \/>\nsmtpd_sasl_auth_enable = yes<br \/>\nsmtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination<br \/>\nsmtp_tls_security_level = may<br \/>\nsmtpd_tls_security_level = may<br \/>\nsmtp_tls_note_starttls_offer = yes<br \/>\nsmtpd_tls_loglevel = 1<br \/>\nsmtpd_tls_key_file = \/etc\/postfix\/ssl\/server.key<br \/>\nsmtpd_tls_cert_file = \/etc\/postfix\/ssl\/server.crt<br \/>\nsmtpd_tls_received_header = yes<br \/>\nsmtpd_tls_session_cache_timeout = 3600s<br \/>\ntls_random_source = dev:\/dev\/urandom<\/p>\n<p>Step 6 \u00bb Open \/etc\/postfix\/master.cf file, add the below lines after \u201csmtp inet n \u2013 n \u2013 \u2013 smtpd\u201d line.<br \/>\nsubmission\u00a0\u00a0\u00a0\u00a0 inet\u00a0 n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8211;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8211;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8211;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 smtpd<br \/>\n-o syslog_name=postfix\/submission<br \/>\n-o smtpd_sasl_auth_enable=yes<br \/>\n-o smtpd_recipient_restrictions=permit_sasl_authenticated,reject<br \/>\n-o milter_macro_daemon_name=ORIGINATING<br \/>\nsmtps\u00a0\u00a0\u00a0\u00a0 inet\u00a0 n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8211;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8211;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8211;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 smtpd<br \/>\n-o syslog_name=postfix\/smtps<br \/>\n-o smtpd_sasl_auth_enable=yes<br \/>\n-o smtpd_recipient_restrictions=permit_sasl_authenticated,reject<br \/>\n-o milter_macro_daemon_name=ORIGINATING<br \/>\nNow check the configuration using postfix check command.<br \/>\nStep 7 \u00bb Now configure Dovecot SASL for SMTP Auth. Open \/etc\/dovecot\/conf.d\/10-master.conf file, find \u201c# Postfix smtp-auth\u201d line ( line no:95 ) and add the below lines.<br \/>\n# Postfix smtp-auth<br \/>\nunix_listener \/var\/spool\/postfix\/private\/auth {<br \/>\nmode = 0660<br \/>\nuser = postfix<br \/>\ngroup = postfix<br \/>\n}<\/p>\n<p>Step 8 \u00bb Open \/etc\/dovecot\/conf.d\/10-auth.conf file, find \u201cauth_mechanisms = plain\u201d ( Line no: 100 ) and add login to the value like below.<br \/>\nauth_mechanisms = plain login<\/p>\n<p>Step 9 \u00bb Postfix configuration is over. Now restart both postfix and dovecot services and enable auto start.<br \/>\n[root@mail ~]# systemctl restart postfix<br \/>\n[root@mail ~]# systemctl enable postfix<br \/>\n[root@mail ~]# systemctl restart dovecot<br \/>\n[root@mail ~]# systemctl enable dovecot<\/p>\n<p>Step 10 \u00bb Add the firewall rules to allow 25, 587 and 465 ports.<br \/>\n[root@mail ~]# firewall-cmd &#8211;permanent &#8211;add-service=smtp<br \/>\n[root@mail ~]# firewall-cmd &#8211;permanent &#8211;add-port=587\/tcp<br \/>\n[root@mail ~]# firewall-cmd &#8211;permanent &#8211;add-port=465\/tcp<br \/>\n[root@mail ~]# firewall-cmd &#8211;reload<br \/>\nNow start testing connectivity for each ports 25,587 and 465 using telnet and make sure you are getting AUTH PLAIN LOGIN line after issuing ehlo mail.rmohan.com command in telnet.<br \/>\n[root@mail ~]# telnet mail.rmohan.com 465<br \/>\nTrying 192.168.1.20&#8230;<br \/>\nConnected to mail.rmohan.com.<br \/>\nEscape character is &#8216;^]&#8217;.<br \/>\n220 mail.rmohan.com ESMTP Postfix<br \/>\nehlo mail.rmohan.com &lt;&#8212;&#8212;- Type this command<br \/>\n250-mail.rmohan.com<br \/>\n250-PIPELINING<br \/>\n250-SIZE 10240000<br \/>\n250-VRFY<br \/>\n250-ETRN<br \/>\n250-STARTTLS<br \/>\n250-AUTH PLAIN LOGIN<br \/>\n250-AUTH=PLAIN LOGIN<br \/>\n250-ENHANCEDSTATUSCODES<br \/>\n250-8BITMIME<br \/>\n250 DSN<\/p>\n<p>Dovecot configuration<br \/>\nStart configuring Dovecot .<br \/>\nStep 11 \u00bb Open \/etc\/dovecot\/conf.d\/10-mail.conf file, find #mail_location = (line no : 30 ) and add the same directory which is given to home_mailbox in the postfix config file ( Step 5).<br \/>\nmail_location = maildir:~\/mail<\/p>\n<p>Step 12 \u00bb Open \/etc\/dovecot\/conf.d\/20-pop3.conf file, find and uncomment the below line ( line no : 50 ) .<br \/>\npop3_uidl_format = %08Xu%08Xv<\/p>\n<p>Step 13 \u00bb Restart dovecot service.<br \/>\n[root@mail ~]# systemctl restart dovecot<\/p>\n<p>Step 14 \u00bb Add firewall rules to allow 110,143,993 and 995.<br \/>\n[root@mail ~]# firewall-cmd &#8211;permanent &#8211;add-port=110\/tcp<br \/>\n[root@mail ~]# firewall-cmd &#8211;permanent &#8211;add-service=pop3s<br \/>\n[root@mail ~]# firewall-cmd &#8211;permanent &#8211;add-port=143\/tcp<br \/>\n[root@mail ~]# firewall-cmd &#8211;permanent &#8211;add-service=imaps<br \/>\n[root@mail ~]# firewall-cmd &#8211;reload<\/p>\n<p>Check the connectivity for the ports 110,143,993 and 995 using telnet.<\/p>\n<p>User creation<br \/>\nNow create user for testing .<br \/>\nStep 15 \u00bb Create user with \/sbin\/nologin shell to restrict login access.<br \/>\n[root@mail ~]# useradd -m rmohan -s \/sbin\/nologin<br \/>\n[root@mail ~]# passwd rmohan<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Setup mail server on centos 7<\/p>\n<p>This article helps you to install and configure basic mail server on Centos 7. Here i have used Postfix for SMTP, Dovecot for POP\/IMAP and Dovecot SASL for SMTP AUTH. Before proceeding please make sure you have assigned static IP for the server and have internet connectivity for installing [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[73],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/4534"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4534"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/4534\/revisions"}],"predecessor-version":[{"id":4535,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/4534\/revisions\/4535"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4534"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4534"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4534"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}