Posted by: isaraffee | August 10, 2009

Postfix Configuration

The Postfix MTA

Checking if Postfix services are running

[root@venus /root]# ps -ef|grep postfix
root 1178 1 0 07:30 ? 00:00:00 /usr/lib/postfix/master
postfix 1184 1178 0 07:30 ? 00:00:00 pickup -l -t fifo
postfix 1185 1178 0 07:30 ? 00:00:00 qmgr -l -t fifo -u
postfix 2026 1178 0 07:36 ? 00:00:00 cleanup -t unix -u
postfix 2030 1178 0 07:36 ? 00:00:00 trivial-rewrite -n rewrite -t un
postfix 2034 1178 0 07:36 ? 00:00:00 local -t unix
root 2198 1831 0 07:39 pts/1 00:00:00 grep postfix

Where is Postfix?

[root@venus /root]# whereis postfix
postfix: /usr/sbin/postfix /etc/postfix /usr/lib/postfix /usr/share/man/man1/postfix.1.bz2

Exploring POstfix Configuration Files

[root@venus /root]# cd /etc/postfix

[root@venus postfix]# ll -rt
total 156
-rwxr-xr-x 1 root root 6291 Apr 17 2001 postfix-script*
-rw-r--r-- 1 root root 4344 Apr 17 2001 master.cf
-rw-r--r-- 1 root root 9413 Apr 17 2001 virtual
-rw-r--r-- 1 root root 7106 Apr 17 2001 transport
-rw-r--r-- 1 root root 5137 Apr 17 2001 relocated
-rw-r--r-- 1 root root 7527 Apr 17 2001 canonical
-rw-r--r-- 1 root root 412 Apr 17 2001 aliases
-rw-r--r-- 1 root root 5038 Apr 17 2001 access
-rw-r--r-- 1 root root 19444 May 14 00:50 main.cf.bak
-rw-r--r-- 1 root root 19441 May 14 01:05 main.cf
-rw-r--r-- 1 root root 12288 May 24 07:30 virtual.db
-rw-r--r-- 1 root root 12288 May 24 07:30 transport.db
-rw-r--r-- 1 root root 12288 May 24 07:30 relocated.db
-rw-r--r-- 1 root root 12288 May 24 07:30 canonical.db
-rw-r--r-- 1 root root 12288 May 24 07:30 aliases.db
-rw-r--r-- 1 root root 12288 May 24 07:30 access.db

Tip
Make sure you make a backup copy of the main.cf file and named it like main.cf.bak so that you can fall back to the  original file if you make any errors on the main.cf file.

Find out your full qualified dimain name by typing,

[root@venus /root]# hostname
venus.localdomain

Vi the main.cf file and make the following changes

myhostname = venus.localdomain

myorigin = $mydomain

mydestination = $myhostname, $mydomain

After you have made the changes, make sure you reload postfix

[root@venus postfix]# postfix reload
postfix-script: refreshing the Postfix mail system

Postfix Logging

After strating or reloading Postfix, you should check the log file to see if Postfix reports any problems.

In the directory /var/log/mail#

[root@venus mail]# tail errors

May 24 07:38:01 venus procmail[2196]: Attempt to fake stamp by "nobody" 

[root@venus mail]# tail info
May 24 07:30:41 venus postfix-script: starting the Postfix mail system
May 24 07:30:41 venus postfix/master[1178]: daemon started
May 24 07:31:03 venus postfix/pickup[1184]: EE0757221C: uid=9 from=<news>
May 24 07:31:03 venus postfix/cleanup[1613]: EE0757221C: message-id=<20060523233102.EE0757221C@venus.localdomain>
May 24 07:31:03 venus postfix/qmgr[1185]: EE0757221C: from=<news@venus.localdomain>,
size=386, nrcpt=1 (queue active)
May 24 07:31:04 venus postfix/local[1635]: EE0757221C: to=<news@venus.localdomain>, relay=local, delay=2, status=sent ("|/usr/bin/procmail -o -a $DOMAIN -d $LOGNAME")
May 24 07:36:33 venus postfix/pickup[1184]: 1AF8E7221C: uid=9 from=<news>
May 24 07:36:33 venus postfix/cleanup[2026]: 1AF8E7221C: message-id=<20060523233633.1AF8E7221C@venus.localdomain>
May 24 07:36:33 venus postfix/qmgr[1185]: 1AF8E7221C: from=<news@venus.localdomain>,
size=3851, nrcpt=1 (queue active)
May 24 07:36:33 venus postfix/local[2034]: 1AF8E7221C: to=<news@venus.localdomain>, relay=local, delay=0, status=sent ("|/usr/bin/procmail -o -a $DOMAIN -d $LOGNAME")
May 24 07:38:01 venus postfix/pickup[1184]: 3F6A77221C: uid=0 from=<root>
May 24 07:38:01 venus postfix/cleanup[2026]: 3F6A77221C: message-id=<20060523233801.3F6A77221C@venus.localdomain>
May 24 07:38:01 venus postfix/qmgr[1185]: 3F6A77221C: from=<root@venus.localdomain>,
size=388, nrcpt=1 (queue active)
May 24 07:38:01 venus postfix/local[2034]: 3F6A77221C: to=<root@venus.localdomain>, relay=local, delay=0, status=sent ("|/usr/bin/procmail -o -a $DOMAIN -d $LOGNAME")
May 24 07:54:20 venus postfix-script: refreshing the Postfix mail system
May 24 07:54:23 venus postfix/master[1178]: reload configuration

Sending Test Mail

Try to send mails to yourself(root user) and the other users in the localdomain.

[root@venus /root]# mail -s "Heloo users" khadijah@venus.localdomain
Hey guys
DId you watch The Idol?
.
Cc:[#

Tip
When you are done writing your e-mail, press the dot button or Ctrl D.

In this case I have sent an e-mail to one of my users, khadijah. The user had received her e-mail

[root@venus /root]# su - khadijah
sh-2.04$ mail
Mail version 8.1.1 6/6/93. Type ? for help.
"/var/spool/mail/khadijah": 1 message 1 new
>N 1 root@venus.localdoma Wed May 24 08:07 14/454 "Heloo users"
&
Message 1:
From khadijah Wed May 24 08:07:54 2006
Delivered-To: khadijah@venus.localdomain
To: khadijah@venus.localdomain
Subject: Heloo users
Date: Wed, 24 May 2006 08:07:54 +0800 (SGT)
From: root@venus.localdomain (root)

Hey guys
DId you watch The Idol?

&
At EOF
& q

Sending test mail from one user to another

sh-2.04$ mail -s "Meet you tomorrow" aisha@localdomain
Hey Aisha,
What about the project?
Have you start it?
regards,
Khadijah
.
Cc:�

In the example above, notice that I tried to send the e-mail to aisha@localdomain instead of aisha@venus.localdomain. The result is that the mail would not be sent to aisha as shown in the log file

[root@venus mail]# tail /var/log/mail/info

May 24 08:14:36 venus postfix/smtp[2418]: 2CD307221C: to=<aisha@localdomain.venus.localdomain>, relay=none, delay=0, status=deferred (Name service error for localdomain.venus.localdomain: Host not found, try again)

User, aisha does not received the mail as I checked,

sh-2.04$ su - aisha
Password:
sh-2.04$ whoami
aisha
sh-2.04$ mail
No mail for aisha

Alternatively, you can also type the command mailq to check for error and info of mails sent and recived

sh-2.04$ mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
2CD307221C 418 Wed May 24 08:14:36 khadijah@venus.localdomain
(Name service error for localdomain.venus.localdomain: Host not found, try again)
aisha@localdomain.venus.localdomain

-- 0 Kbytes in 1 Request.

Another test

I tested again sending mail from user khadijah to aisha. This time I use aisha@venus, and I have expected the mail was not received by aisha as shown in the mailq 

sh-2.04$ mail -s "Have you recived my mail?" aisha@venus
Just checking with u
Have you received my mail together with the attachments?
.
Cc:
sh-2.04$ mail
No mail for khadijah
sh-2.04$ mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
2CD307221C 418 Wed May 24 08:14:36 khadijah@venus.localdomain
(Name service error for localdomain.venus.localdomain: Host not found, try again)
aisha@localdomain.venus.localdomain

06B357221D 422 Wed May 24 08:26:52 khadijah@venus.localdomain
(Name service error for venus.venus.localdomain: Host not found, try again)
aisha@venus.venus.localdomain

-- 1 Kbytes in 2 Requests.

The /var/log/mail/info logs below also shows the error message, suggesting that the host was not found

May 24 08:26:53 venus postfix/pickup[2268]: 06B357221D: uid=504 from=<khadijah>
May 24 08:26:53 venus postfix/cleanup[2487]: 06B357221D: message-id=<20060524002652.06B357221D@venus.localdomain>
May 24 08:26:53 venus postfix/qmgr[2267]: 06B357221D: from=<khadijah@venus.localdomain>, size=422, nrcpt=1 (queue active)
May 24 08:26:53 venus postfix/smtp[2489]: 06B357221D: to=<aisha@venus.venus.localdomain>, relay=none, delay=1, status=deferred (Name service error for venus.venus.localdomain: Host not found, try again)

Note
When you sent e-mail, observe the info logs. You will see that the first three lines shows that Postfix pickup the mail from the user (in this case khadijah). Then Potfix will do some cleanup. And finally Postfix will put the mail in the qmgr( queue manager) from user, khadijah just before sending the mail.
The forth line shows that Postfix uses the SMTP to send the mail to user, aisha and in this case Postfix reported that the host could not be found

Mail testing (this time it work)

sh-2.04$ whoami
khadijah
sh-2.04$ mail -s "This time mail will work" aisha@venus.localdomain
Hey I promise that this time this mail will reache u
.
Cc:

Yes, user aisha finally received the mail. This is after I type the correct receipient address, aisha@venus.localdomain

sh-2.04$ su - aisha
Password:
sh-2.04$ whoami
aisha
sh-2.04$ mail
Mail version 8.1.1 6/6/93. Type ? for help.
"/var/spool/mail/aisha": 1 message 1 new
>N 1 khadijah@venus.local Wed May 24 08:40 13/498 "This time mail will work"
&
Message 1:
From aisha Wed May 24 08:40:33 2006
Delivered-To: aisha@venus.localdomain
To: aisha@venus.localdomain
Subject: This time mail will work
Date: Wed, 24 May 2006 08:40:33 +0800 (SGT)
From: khadijah@venus.localdomain (new Samba user)

Hey I promise that this time this mail will reache u

&

Looking at mailq,

There is no entry in the mailq for successful mail transactions

Now let's look at the info logs,

May 24 08:40:33 venus postfix/pickup[2268]: 4468D7221E: uid=504 from=<khadijah>
May 24 08:40:33 venus postfix/cleanup[2527]: 4468D7221E: message-id=<20060524004033.4468D7221E@venus.localdomain>
May 24 08:40:33 venus postfix/qmgr[2267]: 4468D7221E: from=<khadijah@venus.localdomain>, size=389, nrcpt=1 (queue active)
May 24 08:40:34 venus postfix/local[2529]: 4468D7221E: to=<aisha@venus.localdomain>,
relay=local, delay=1, status=sent ("|/usr/bin/procmail -o -a $DOMAIN -d $LOGNAME")

Testing Mail to other domain

[root@venus /root]# mail -s "Sending Mail to Mercury" root@mercury.localdomain
HI mercury
I am sending from venus
Do you receive this mail?
.
Cc:

Looking at mailq

386A17221E 383 Wed May 24 08:55:36 root@venus.localdomain
(Name service error for mercury.localdomain: Host not found, try again)
root@mercury.localdomain#

Looking at the info logs

May 24 08:55:36 venus postfix/pickup[2268]: 386A17221E: uid=0 from=<root>
May 24 08:55:36 venus postfix/cleanup[2600]: 386A17221E: message-id=<20060524005536.386A17221E@venus.localdomain>
May 24 08:55:36 venus postfix/qmgr[2267]: 386A17221E: from=<root@venus.localdomain>,
size=383, nrcpt=1 (queue active)
May 24 08:55:36 venus postfix/smtp[2602]: 386A17221E: to=<root@mercury.localdomain>,
relay=none, delay=0, status=deferred (Name service error for mercury.localdomain: Host not found, try again)#�#

As expected, the user (root@mercury.localdomain) on the other domain did not received the mail.
This is because I have not configure the DNS on the host.

NEW DAY

I edited the /etc/named.conf file and added the following

zone "venus.localdomain" {
type master;
file "named.venus.localdomain";
};

Edit the named.venus.localdomain configuration file,

[root@venus named]# vi named.venus.localdomain

$TTL 3D
@ IN SOA ns.venus.localdomain. hostmaster.venus.localdomain. (
199802151
8H
2H
4W
1D )
MX 10 mail.venus.localdomain.
NS ns
localhost A 127.0.0.1
ns A 169.254.34.253
www CNAME ns
mail A 169.254.34.253

In case you have not start named services, type

[root@venus init.d]# ./named start
Starting named: [ OK ]

And if you have started named services you can reload named ny running rndc reload 

[root@venus init.d]# rndc reload
rndc: reload command successful

Examine the results with the dig command

[root@venus /root]# dig any venus.localdomain

; <<>> DiG 9.1.1 <<>> any venus.localdomain
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 19118
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 1, ADDITIONAL: 2

;; QUESTION SECTION:
;venus.localdomain. IN ANY

;; ANSWER SECTION:
venus.localdomain. 259200 IN SOA ns.venus.localdomain. hostmaster.venus.localdomain. 199802151 28800 7200 2419200 86400
venus.localdomain. 259200 IN MX 10 mail.venus.localdomain.
venus.localdomain. 259200 IN NS ns.venus.localdomain.

;; AUTHORITY SECTION:
venus.localdomain. 259200 IN NS ns.venus.localdomain.

;; ADDITIONAL SECTION:
mail.venus.localdomain. 259200 IN A 169.254.34.253
ns.venus.localdomain. 259200 IN A 169.254.34.253

;; Query time: 18 msec
;; SERVER: 169.254.34.253#53(169.254.34.253)
;; WHEN: Thu May 25 07:51:37 2006
;; MSG SIZE rcvd: 166

Testing Mail

[root@venus /root]# mail -s "It's a new Day" aisha@venus.localdomain
Hello there
.
Cc:
[root@venus /root]# mailq

Mailq does not show any errors

Checking the mail of user,aisha

[root@venus /root]# su - aisha
sh-2.04$ mail
Mail version 8.1.1 6/6/93. Type ? for help.
"/var/spool/mail/aisha": 1 message 1 new
>N 1 root@venus.localdoma Thu May 25 07:53 13/427 "It's a new Day"
&
Message 1:
From aisha Thu May 25 07:53:10 2006
Delivered-To: aisha@venus.localdomain
To: aisha@venus.localdomain
Subject: It's a new Day
Date: Thu, 25 May 2006 07:53:09 +0800 (SGT)
From: root@venus.localdomain (root)

Hello there

&

The mail was received

Reload Postfix

[root@venus init.d]# ./postfix reload
postfix-script: refreshing the Postfix mail system`

On host mercury.localdomain,

I wrote a mail from host mercury.localdomain , subject "American Idol"

I ran the command, mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
06B357221D 422 Thu May 25 08:26:52 root@mercury.localdomain
                                                                  root@venus.localdomain
0 kbytes in 1 Request

Looking at the mercury's /var/log/mail/info logs,

May 25 08:34:41 mercury postfix/pickup[6328]: 9780B6830F: uid=0 from=<root>
May 25 08:34:41 mercury postfix/cleanup[6360]: 9780B6830F: message-id=<20060525003441.9780B6830F@mercury.localdomain>
May 25 08:34:41 mercury postfix/qmgr[948]: 9780B6830F: from=<root@mercury.localdomain>, size=347, nrcpt=1 (queue active)
May 25 08:35:21 mercury postfix/smtp[6362]: 9780B6830F: to=<root@venus.localdomain>,
relay=mail.venus.localdomain[169.254.34.253], delay=40, status=sent (250 Ok: queued as C6D617221B)

On host venus.localdomain,

I received the mail (subject:American Idol) that was sent from mercury.localdomain
[root@venus /root]# mail
Mail version 8.1.1 6/6/93. Type ? for help.
"/var/spool/mail/root": 4 messages 1 new 4 unread
U 1 root@venus.localdoma Wed May 24 09:01 21/785 "Cron <root@venus> run-part"
U 2 root@venus.localdoma Thu May 25 07:24 14/503 "Anacron job 'cron.daily'"
U 3 root@venus.localdoma Thu May 25 08:01 21/785 "Cron <root@venus> run-part"
>N 4 root@mercury.localdo Thu May 25 08:23 16/637 "American Idol"
&

Another successful mail sent from mercury to venus

Message 5:
From nobody Thu May 25 08:35:25 2006
Delivered-To: root@venus.localdomain
To: root@venus.localdomain
Subject: My Sister's BIrthday
Date: Thu, 25 May 2006 08:34:41 +0800 (SGT)
From: root@mercury.localdomain (root)

Today is Siti's Birthday!#

Looking at the /var/log/mail/info logs,

May 25 08:23:12 venus postfix/smtpd[2632]: DEE727221B: client=mercury.localdomain[169.254.34.254]
May 25 08:23:12 venus postfix/cleanup[2635]: DEE727221B: message-id=<20060524035643.5FED668309@mercury.localdomain>
May 25 08:23:12 venus postfix/smtpd[2632]: disconnect from mercury.localdomain[169.254.34.254]
May 25 08:23:12 venus postfix/qmgr[2629]: DEE727221B: from=<root@mercury.localdomain>, size=533, nrcpt=1 (queue active)
May 25 08:23:12 venus postfix/local[2637]: DEE727221B: to=<root@venus.localdomain>, relay=local, delay=0, status=sent ("|/usr/bin/procmail -o -a $DOMAIN -d $LOGNAME")

It showed that the mail from user root of host mercury was sent successfully to user root of venus

Test mail to other users of venus (user, aisha and cc to khadijah)

Yes both users received the mail,

[root@venus /etc]# su - aisha
sh-2.04$ mail
Mail version 8.1.1 6/6/93. Type ? for help.
"/var/spool/mail/aisha": 1 message 1 new
>N 1 root@mercury.localdo Thu May 25 08:48 17/670 "Next Year I am joining IDO"
&
Message 1:
From aisha Thu May 25 08:48:52 2006
Delivered-To: aisha@venus.localdomain
To: aisha@venus.localdomain
Subject: Next Year I am joining IDOL
Cc: khadijah@venus.localdomain
Date: Thu, 25 May 2006 08:48:08 +0800 (SGT)
From: root@mercury.localdomain (root)

WAnt to join me IDOL next time?

&

Checking khadijah mail

From khadijah Thu May 25 08:48:52 2006
Return-Path: <root@mercury.localdomain>
Delivered-To: khadijah@venus.localdomain
Received: from mercury.localdomain (mercury.localdomain [169.254.34.254])
by venus.localdomain (Postfix) with ESMTP
id 389217221B; Thu, 25 May 2006 08:48:52 +0800 (SGT)
Received: by mercury.localdomain (Postfix, from userid 0)
id 1759B6830F; Thu, 25 May 2006 08:48:08 +0800 (SGT)
To: aisha@venus.localdomain
Subject: Next Year I am joining IDOL
Cc: khadijah@venus.localdomain
Message-Id: <20060525004808.1759B6830F@mercury.localdomain>
Date: Thu, 25 May 2006 08:48:08 +0800 (SGT)
From: root@mercury.localdomain (root)
Status: RO
WAnt to join me IDOL next time?F

LOoking at the /var/log/mail/info logs

May 25 08:48:12 venus postfix/smtpd[2753]: connect from mercury.localdomain[169.254.34.254]
May 25 08:48:52 venus postfix/smtpd[2753]: 389217221B: client=mercury.localdomain[169.254.34.254]
May 25 08:48:52 venus postfix/cleanup[2756]: 389217221B: message-id=<20060525004808.1759B6830F@mercury.localdomain>
May 25 08:48:52 venus postfix/smtpd[2753]: disconnect from mercury.localdomain[169.254.34.254]
May 25 08:48:52 venus postfix/qmgr[2629]: 389217221B: from=<root@mercury.localdomain>, size=567, nrcpt=2 (queue active)
May 25 08:48:52 venus postfix/local[2758]: 389217221B: to=<aisha@venus.localdomain>,
relay=local, delay=0, status=sent ("|/usr/bin/procmail -o -a $DOMAIN -d $LOGNAME")
May 25 08:48:52 venus postfix/local[2759]: 389217221B: to=<khadijah@venus.localdomain>, relay=local, delay=0, status=sent ("|/usr/bin/procmail -o -a $DOMAIN -d $LOGNAME")

Conclusion is I do not have to edit
the /etc/postfix/main.cf file
/var/named/named.mercury.localdomain
/etc/named.conf of host mercury

Test Mail from Venus to Mercury

Now I tried to sent mail from venus to mercury. Well it failed. BElow are the logs from venus

On host venus

[root@venus mail]# mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
B05D77221C 351 Thu May 25 08:43:00 root@venus.localdomain
(Name service error for mercury.localdomain: Host not found, try again)
root@mercury.localdomain

Looking at the /var/log/mail/info logs

May 25 08:43:00 venus postfix/pickup[2630]: B05D77221C: uid=0 from=<root>
May 25 08:43:00 venus postfix/cleanup[2734]: B05D77221C: message-id=<20060525004300.B05D77221C@venus.localdomain>
May 25 08:43:00 venus postfix/qmgr[2629]: B05D77221C: from=<root@venus.localdomain>,
size=351, nrcpt=1 (queue active)
May 25 08:43:20 venus postfix/smtp[2736]: B05D77221C: to=<root@mercury.localdomain>,
relay=none, delay=20, status=deferred (Name service error for mercury.localdomain: Host not found, try again)#
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: