|
Mail Server(Postfix) |
Postfix is a powerful but easy-to-configure mail server
Postfix is a free and open-source mail transfer agent(MTA)that routes and deliver electronic mail
Postfix implements a high-performance parallelized mail-delivery
engine
Postfix implements a limited number of features in the MTA,and relies on third-party extensions for the rest
Server Configuration
To install postfix Mail Server
|
[root@server ~]# yum install -y postfix Loaded plugins: fastestmirror, langpacks base | 2.9 kB 00:00 Loading mirror speeds from cached hostfile Package 2:postfix-2.10.1-6.el7.x86_64 already installed and latest version Nothing to do [root@server ~]#
|
To Add a smtp service to the firewall:
|
[root@server ~]# firewall-cmd --permanent --add-service=smtp success [root@server ~]# firewall-cmd --zone=public --permanent --add-port=25/tcp success
|
To Reload the firewall configuration
|
[root@server ~]# firewall-cmd --reload success
|
To Activate the postfix service at boot:
|
[root@server ~]# systemctl enable postfix
|
To Start the postfix mail server
|
[root@server ~]# systemctl start postfix
|
To check the status of postfix mail server
|
[root@server ~]# systemctl status postfix ? postfix.service - Postfix Mail Transport Agent Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; vendor preset: disabled) Active: active (running) since Mon 2017-10-23 16:47:05 IST; 3min 34s ago Main PID: 1439 (master) CGroup: /system.slice/postfix.service ??1439 /usr/libexec/postfix/master -w ??1449 pickup -l -t unix -u ??1450 qmgr -l -t unix -u
Oct 23 16:46:53 server systemd[1]: Starting Postfix Mail Transport Agent... Oct 23 16:47:05 server postfix/master[1439]: daemon started -- version 2.10.1, configuration /etc/postfix Oct 23 16:47:05 server systemd[1]: Started Postfix Mail Transport Agent.
|
|
Configure a central mail server |
Edit the /etc/postfix/main.cf file and change the following directives:
|
[root@server ~]# vi /etc/postfix/main.cf [root@server ~]# myhostname = server.agoutam.com mydomain = agoutam.com myorigin = $mydomain inet_interfaces = all mydestination = $myhostname,localhost.$mydomain,localhost,$mydomain mynetworks = 192.168.56.0/24,127.0.0.0/8
|
To Check the syntax of postfix main configuration file
|
[root@server ~]# postfix check
|
To Check the non-default configuration :
|
[root@server ~]# postconf -n alias_database = hash:/etc/aliases alias_maps = hash:/etc/aliases command_directory = /usr/sbin config_directory = /etc/postfix daemon_directory = /usr/libexec/postfix data_directory = /var/lib/postfix debug_peer_level = 2 debugger_command = PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin ddd $daemon_ directory/$process_name $process_id & sleep 5 html_directory = no inet_interfaces = all inet_protocols = all mail_owner = postfix mailq_path = /usr/bin/mailq.postfix manpage_directory = /usr/share/man mydestination = $myhostname, localhost.$mydomain, localhost, $mydomainmydomain = agoutam.com myhostname = server.agoutam.com mynetworks = 192.168.56.0/24, 127.0.0.0/8 myorigin = $mydomain newaliases_path = /usr/bin/newaliases.postfix queue_directory = /var/spool/postfix readme_directory = /usr/share/doc/postfix-2.10.1/README_FILES sample_directory = /usr/share/doc/postfix-2.10.1/samples sendmail_path = /usr/sbin/sendmail.postfix setgid_group = postdrop unknown_local_recipient_reject_code = 550
|
To Set the SELinux boolean to "on":
|
[root@server mail]# setsebool -P allow_postfix_local_write_mail_spool on
|
To create User to use for mail Service
|
[root@server mail]# adduser msgoutam [root@server mail]# passwd msgoutam Changing password for user msgoutam. New password: BAD PASSWORD: The password contains the user name in some form Retype new password: passwd: all authentication tokens updated successfully.
|
To Send mail to user msgoutam
|
[root@server mail]# echo testmail |mail -s "Test Mail to Agoutam" msgoutam@agoutam.com
|
To Check Mail account of user msgoutam
|
[root@server mail]# su - msgoutam [msgoutam@server ~]$ mail Heirloom Mail version 12.5 7/5/10. Type ? for help. "/var/spool/mail/msgoutam": 1 message 1 new >N 1 root Mon Oct 23 17:11 18/591 "Test Mail to Agoutam" & 1 Message 1: From root@agoutam.com Mon Oct 23 17:11:14 2017 Return-Path: <root@agoutam.com> X-Original-To: msgoutam@agoutam.com Delivered-To: msgoutam@agoutam.com Date: Mon, 23 Oct 2017 17:11:14 +0530 To: msgoutam@agoutam.com Subject: Test Mail to Agoutam User-Agent: Heirloom mailx 12.5 7/5/10 Content-Type: text/plain; charset=us-ascii From: root@agoutam.com (root) Status: R
testmail
|
Type r to Reply to the mail
|
& r To: msgoutam@agoutam.com root@agoutam.com Subject: Re: Test Mail to Agoutam
root@agoutam.com (root) wrote:
> testmail Got mail ,Thanks
|
Type q to quit from Mail Service
|
& q New mail has arrived. Held 1 message in /var/spool/mail/msgoutam You have mail in /var/spool/mail/msgoutam [msgoutam@server ~]$ su root
|
Configure a Client to forward all email to a central mail server
Null-client configuration
To Install postfix Mail Server in Client machine
|
[root@client ~]# yum install -y postfix Loaded plugins: fastestmirror, langpacks base | 2.9 kB 00:00 Loading mirror speeds from cached hostfile Package 2:postfix-2.10.1-6.el7.x86_64 already installed and latest version Nothing to do [root@client ~]#
|
To Add service smtp in firewall
|
[root@client ~]# firewall-cmd --permanent --add-service=smtp success [root@client ~]# firewall-cmd --zone=public --permanent --add-port=25/tcp success
|
To Reload firewall configuration
|
[root@client ~]# firewall-cmd --reload success
|
To enable Postfix Mail Server during Boot Time.
|
[root@client ~]# systemctl enable postfix
|
To Restart postfix Mail server
|
[root@client ~]# systemctl restart postfix
|
Edit the /etc/postfix/main.cf file:
|
[root@client ~]# vi /etc/postfix/main.cf myhostname = client.agoutam.com mydomain = agoutam.com myorigin = $mydomain inet_interfaces = loopback-only relayhost = 192.168.56.101
|
To Check the Postfix syntax of main.cf configuration file
|
[root@client ~]# postfix check
|
To Check the non-default configuration:
|
[root@client ~]# postconf -n html_directory = no inet_interfaces = all inet_protocols = all mail_owner = postfix mailq_path = /usr/bin/mailq.postfix manpage_directory = /usr/share/man mydestination = $myhostname, localhost.$mydomain, localhost mydomain = agoutam.com myhostname = client.agoutam.com myorigin = $mydomain
|
To Restart postfix Mail Server
|
[root@client ~]# systemctl restart postfix [root@client ~]# systemctl enable postfix
|
To Send mail to user msgoutam ,user presents in Server Machine
|
[root@client ~]# echo "testmail" | mail -s "Testing relayhost " msgoutam@agoutam.com
|
To Check Maillog for mail msgoutam@agoutam.com
|
[root@client ~]# tail -10 /var/log/maillog Oct 23 17:32:44 client postfix/smtp[2306]: 7B6C33098B13: to=<msgoutam@agoutam.com>, relay=192.168.56.101[192.168.56.101]:25, delay=0.17, delays=0.09/0.01/0.01/0.07, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as C86AC199FA1B)
|
To Check Mail for user msgoutam login as msgoutam
[root@server home]# su - msgoutam
Last login: Mon Oct 23 17:12:00 IST 2017 on pts/0
To check mail for user msgoutam ,using command mail:
|
[msgoutam@server ~]$ mail Heirloom Mail version 12.5 7/5/10. Type ? for help. "/var/spool/mail/msgoutam": 3 messages 2 new A 1 root Mon Oct 23 17:11 20/614 "Test Mail to Agoutam" >N 2 msgoutam@agoutam.com Mon Oct 23 17:13 24/796 "Re: Test Mail to Agou" N 3 root Mon Oct 23 17:32 21/788 "Testing relayhost"
|
Type 3 to check Third mail from mail service .
|
& 3 Message 3: From root@agoutam.com Mon Oct 23 17:32:44 2017 Return-Path: <root@agoutam.com> X-Original-To: msgoutam@agoutam.com Delivered-To: msgoutam@agoutam.com Date: Mon, 23 Oct 2017 17:32:44 +0530 To: msgoutam@agoutam.com Subject: Testing relayhost User-Agent: Heirloom mailx 12.5 7/5/10 Content-Type: text/plain; charset=us-ascii From: root@agoutam.com (root) Status: R
testmail
|
Configure a system to forward all email to a central mail server
Mail gateway configuration
Edit the /etc/postfix/main.cf file:
|
[root@client ~]# vi /etc/postfix/main.cf myhostname = client.agoutam.com mydomain = agoutam.com myorigin = $mydomain inet_interfaces = all mydestination = $myhostname,localhost.$mydomain,localhost,$mydomain mynetworks = 192.168.56.0/24,127.0.0.0/8 relayhost = 192.168.56.101
|
To Check the syntax of main configuration file main.cf
|
[root@client ~]# postfix check
|
To Check the non-default configuration:
|
[root@client ~]# postconf -n alias_database = hash:/etc/aliases alias_maps = hash:/etc/aliases command_directory = /usr/sbin config_directory = /etc/postfix daemon_directory = /usr/libexec/postfix data_directory = /var/lib/postfix debug_peer_level = 2 debugger_command = PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin ddd $daemon_ directory/$process_name $process_id & sleep 5 html_directory = no inet_interfaces = all inet_protocols = all mail_owner = postfix mailq_path = /usr/bin/mailq.postfix manpage_directory = /usr/share/man mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain mydomain = agoutam.com myhostname = client.agoutam.com mynetworks = 192.168.56.0/24, 127.0.0.0/8 myorigin = $mydomain newaliases_path = /usr/bin/newaliases.postfix queue_directory = /var/spool/postfix readme_directory = /usr/share/doc/postfix-2.10.1/README_FILES relayhost = 192.168.56.101 sample_directory = /usr/share/doc/postfix-2.10.1/samples sendmail_path = /usr/sbin/sendmail.postfix setgid_group = postdrop unknown_local_recipient_reject_code = 550
|
To send Mail to user agoutam@agoutam.com
|
[root@client ~]# echo "test Gateway Configuration" | mail -s "Testing Gateway Configurationrelayhost " agoutam@agoutam.com
|
To Verify Mail sent by viewing Mail log
|
[root@client ~]# tail -10 /var/log/maillog Oct 23 18:10:25 client postfix/cleanup[3151]: 54BBE3098B13: message-id=<20171023124025.54BBE3098B13@client.agoutam.com> Oct 23 18:10:25 client postfix/qmgr[3136]: 54BBE3098B13: from=<root@agoutam.com>, size=488, nrcpt=1 (queue active) Oct 23 18:10:25 client postfix/local[3153]: 54BBE3098B13: to=<agoutam@agoutam.com>, relay=local, delay=0.09, delays=0.07/0.01/0/0.01, dsn=2.0.0, status=sent (delivered to mailbox) Oct 23 18:10:25 client postfix/qmgr[3136]: 54BBE3098B13: removed
|
To check Mail login as agoutam
|
[root@client ~]# su - agoutam Last login: Mon Oct 23 07:52:49 IST 2017 on pts/0
|
To Check mail type command mail logging as agoutam
|
[agoutam@client ~]$ mail Heirloom Mail version 12.5 7/5/10. Type ? for help. "/var/spool/mail/agoutam": 2 messages 2 new >N 1 root Mon Oct 23 17:47 18/625 "Testing Gateway Configuration relayhost" N 2 root Mon Oct 23 18:10 18/625 "Testing Gateway Configuration relayhost" & q Held 2 messages in /var/spool/mail/agoutam [agoutam@client ~]$
|
To Install NMAP Tool for Verifying Services.
|
[root@server ~]# yum install -y nmap Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package nmap.x86_64 2:6.40-7.el7 will be installed --> Finished Dependency Resolution
Dependencies Resolved
================================================================== Package Arch Version Repository Size =================================================================Installing: nmap x86_64 2:6.40-7.el7 base 4.0 M
Transaction Summary =================================================================== Install 1 Package
Total download size: 4.0 M Installed size: 16 M Downloading packages: nmap-6.40-7.el7.x86_64.rpm | 4.0 MB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : 2:nmap-6.40-7.el7.x86_64 Verifying : 2:nmap-6.40-7.el7.x86_64 Installed: nmap.x86_64 2:6.40-7.el7
Complete! [root@server ~]#
|
To Verify SMTP Service and Port is running using NMAP tool
|
[root@server ~]# nmap server.agoutam.com
Starting Nmap 6.40 ( http://nmap.org ) at 2017-10-23 18:15 IST Nmap scan report for server.agoutam.com (192.168.56.101) Host is up (0.000023s latency). Not shown: 987 closed ports PORT STATE SERVICE 21/tcp open ftp 22/tcp open ssh 25/tcp open smtp 53/tcp open domain 80/tcp open http 88/tcp open kerberos-sec 111/tcp open rpcbind 2049/tcp open nfs
Nmap done: 1 IP address (1 host up) scanned in 0.18 seconds [root@server ~]#
|
No comments:
Post a Comment