Configuring Linux Mail Servers: - Objectives - Contents
Configuring Linux Mail Servers: - Objectives - Contents
• Objectives
– This chapter will show you how to install and use Mailservers
• Contents
– An Overview Of How Sendmail Works
– Sendmail configruation files
– Relaying
– Sendmail Masquerading
– Using Sendmail to Change the Sender's Email Address
• Practical
– Setting up mailserver
Introduction
• MTA Mail transport agents
– transfer mail with SMTP protocol to other MTA based on DNS MX record
Popular agents: Sendmail Exim Postfix
• MUA Mail user agents
– Accesses users mailboxes for reading and writing
Popular agents: Fetchmail (POP & IMP) IMAP Qpopper
Courier IMAPD (POP & IMP) –server Cyrus IMAPD (POP & IMP) –server
• Mailbox processing
– Various mechanismes to process users mail when arrived to mailboxes
Procmail Spamassasin Vacation Amavisd
• SMTP trusts the user
– Everyone who have is allowed to login a computer is trusted for e-mail sending
• SMTP needs DNS
– MX entry for domains is needed if not only local mail
• Sendmail lives in smrsh chroot-jail
How sendmail works, incoming mail
• How Sendmail Works
– As stated before, sendmail can handle both incoming and outgoing mail for
your domain. Take a closer look
• Incoming Mail
– Sendmail processes it and deposits it in the mailbox file of the user's Linux
account (var/spool/mail)
– Mail isn't actually sent directly to the user's PC
– Users retrieve their mail from the mail server using client software that supports
imap and pop
– Linux users logged into the mail server can read their mail directly using a text-
based client, such as mail, or a GUI client
• Sendmail belong to what we call MTA
– MTA is responcible to encapsulate the message with header and trailer.
– MTA need DNS MX record to recognize mailserver that serves recieving domain.
– Header contain destination e-mail and source e-mail
– Header contain also the path email traverses throughout the network
– Trailer contain error correction code
How sendmail works, outgoing mail
• Outgoing Mail
– PC and Linux workstation users configure their e-mail software to make the mail
server their outbound SMTP mail server, e.g the user MTA.
• Local mail
If sendmail consider email local and places it directly in the destination users
mailbox (var/spool/mail) (it can be any nfs store to or database)
– If destination is localdomain (my-site.com).
– Virtual hosted domain in same server.
– If destination is localuser or virtualuser at same host.
• Mail to another domain
If sendmail consider the email to have destination outside localdomain it schedule
the mail for delivery within 15 minutes and temporary places it in
(/var/spool/mqueue)
– Sendmail uses DNS to get the MX record for the other domain
– Attempts to relay the mail using SMTP
– Relaying only for trustful domains that sendmail serves must be allowed
– Localhost/Localdomain must be allowed to relay.
How sendmail works, mail processing
• Sendmail main configuration /etc/sendmail.cf
– Using a series of highly complicated regular expressions
– The mail header contain mail routing information, sendmail inspects this header and
then acts accordingly.
– Sendmail configuration is highly configurable
• Simplified configuration /etc/sendmail.mc or /etc/mail/linux.mc
– Contains more understandable instructions for systems administrators to use
– Interpreted by a number of macro routines to create the sendmail.cf file
– You must always run the macros and restart sendmail for the changes to take effect
• Available macros sit in /usr/share/sendmail
• Sendmail files is in /etc/mail
– SuSE and RedHat also uses /etc/sysconfig/mail
– SuSE and RedHat also uses /etc/sysconfig/sendmail
• Mail is parsed with sendmail.cf
– Header parsing
– Header processing & shaping
– Header rewrite engine rules
– Calls to external processors like anti (spam and virus) appz
• Sendmail logfiles /var/log/mail* and /var/log/messages
How sendmail works, sendmail macros
• Macrofiles
– Macros is found in /usr/share/sendmail/
– There are several macrofiles, they have lastname .mc or .m4
• Macrofiles have keywords to call submacros/dirictives
– They can begin with DOMAIN, FEATURE, or OSTYPE and DNL
– Keywords is usally followed by a keyword
• Macro example with keyword and hashfile command
FEATURE(`virtusertable',`hash
FEATURE(`virtusertable',`hash-o
-o/etc/mail/virtusertable.db')dnl
/etc/mail/virtusertable.db')dnl
– the macro name is /usr/share/sendmail/feature/virtusertable.m4,
– the instruction `\ hash -o /etc/mail/virtusertable.db' is being passed to it.
– hash makes simple database format db
– hash –o means output generated database to the db file taht follows
• Example with only macro FEATURE(`masquerade_envelope')dnl
FEATURE(`masquerade_envelope')dnl
• Use the m4 command to generate /etc/sendmail.cf
##m4
m4/etc/mail/linux.mc
/etc/mail/linux.mc>>/etc/sendmail.cf
/etc/sendmail.cf
Getting SENDMAIL from rpm
• Sendmail you can get as
– Open Source http://www.sendmail.org
– Commersial http://www.sendmail.com
• Installing Sendmail from RPM (SuSE)
– You will need to make sure that the sendmail, and m4 software RPMs are installed.
– You will need to remove/uninstall othermailers like exim and postfix before installing
## rpm
rpm –ivh
–ivh sendmail-8.13.3-5.i386.rpm
sendmail-8.13.3-5.i386.rpm (The
(The client/server)
client/server)
## rpm
rpm –ivh
–ivh sendmail-devel-8.13.3-5.i386.rpm
sendmail-devel-8.13.3-5.i386.rpm (Optional)
(Optional)
## rpm
rpm –ivh
–ivh sendmail-debug-8.13.3-5.i386.rpm
sendmail-debug-8.13.3-5.i386.rpm (Optional)
(Optional)
## rpm
rpm –ivh
–ivh m4-1.4.2-4.i586.rpm
m4-1.4.2-4.i586.rpm (macrocompilator)
(macrocompilator)
## rpm
rpm –ivh
–ivh db-devel-4.3.27-3.1.i586.rpm
db-devel-4.3.27-3.1.i586.rpm (Needed
(Needed if
if compile)
compile)
• Starting/Stopping Sendmail
– You can use the chkconfig or insserv command to get Sendmail configured to start at boot:
## insserv
insserv sendmail
sendmail
– To start/stop/restart sendmail after booting
## rcsendmail
rcsendmail start
start
## rcsendmail
rcsendmail stop
stop
## rcsendmail
rcsendmail restart
restart
– You need to restart sendmail after changing sendmail.cf and reload sendmail if the other files has been
manipulated
SENDMAIL from sources
• Get sendmail tar-ball, here 8.13.5
## cd
cd /usr/local/src
/usr/local/src
wget ftp://ftp.sendmail.org/pub/sendmail/sendmail.8.13.5.tar.gz
## wget ftp://ftp.sendmail.org/pub/sendmail/sendmail.8.13.5.tar.gz
• Unpack the tar-ball and add one group that sendmail needs
## tar xvfz sendmail.8.13.5.tar.gz
tar xvfz sendmail.8.13.5.tar.gz ##groupadd
groupaddsmmsp
smmsp
cd sendmail.8.13.5
## cd sendmail.8.13.5
• You will also have one output directory for all your makes
## ls The directories contain the compiled binaries and extras, ready for mass
ls obj.Linux*
obj.Linux* deployment
Standard sendmail.mc comment & DNS
• If sendmail uses /etc/mail/linux.mc we make some links
– Needed in SuSE and some other RPM distributions
## ln
ln –s
–s /etc/sendmail.cf
/etc/sendmail.cf /etc/mail/sendmail.cf
/etc/mail/sendmail.cf
## ln
ln –s /etc/mail/linux.mc /etc/mail/sendmail.mc
–s /etc/mail/linux.mc /etc/mail/sendmail.mc
• How to Put Comments in sendmail.mc
– The sendmail.mc file doesn't use the "#" for commenting, but instead uses the
string "dnl". dnl Disabled statements due to "dnl" commenting
dnl Disabled statements due to "dnl" commenting
dnl
dnlDAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1,
DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1,Name=MTA')
Name=MTA')
dnl
dnl##DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1,
DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1,Name=MTA')
Name=MTA')
dnl
dnlIncorrectly
Incorrectlydisabled
disabledstatement
statement
##DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1,
DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1,Name=MTA')
Name=MTA')
dnl
dnlActive
Activestatement,
statement,here
heresendmail
sendmailclient
clientdaemon
daemonisisenabled
enabled
DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')
DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')
WARNING:
WARNING: local
local host
host name
name (smallfry)
(smallfry) is
is not
not qualified;
qualified;
fix
fix $j
$j in
in config
config file
file
## netstat
netstat -an
-an || grep
grep :25
:25 || grep
grep tcp
tcp
tcp
tcp 00 00 0.0.0.0:25
0.0.0.0:25 0.0.0.0:*
0.0.0.0:* LISTEN
LISTEN
A General Guide To Using The sendmail.mc File
– The string @my-site.com actually rejects all non local emails with error message
• The /etc/aliases File
.. .. ..
manager: root
manager: root
abuse: root
abuse: root
## trap
trap decode
decode to
to catch
catch security
security attacks
attacks
decode: root
decode: root
## Person
Person who
who should
should get
get root's
root's mail
mail
root: marc,kalle,[email protected]
root: marc,kalle,[email protected]
## My
My mailing
mailing list
list file
file
admin-list: ":include:/home/mailings/admin-list"
admin-list: ":include:/home/mailings/admin-list"
• Logfiles
/var/log/mail
/var/log/mail.info
/var/log/mail.warn
/var/log/mail.err
/var/log/messages
• Other Masquerading Notes
– By default, user "root" will not be masqueraded. This is achieved with the:
– in /etc/mail/sendmail.mc EXPOSED_USER(`root')dnl
EXPOSED_USER(`root')dnl
Using Sendmail to Change the Sender's Email Address
##telnet
telnetmail.my-site.com
mail.my-site.com25 25
Trying
Tryingmail.my-site.com...
mail.my-site.com...
Connected
Connectedto tomail.my-site.com.
mail.my-site.com.
Escape
Escapecharacter
characterisis'^]'.
'^]'.
220
220mail.my-site.com
mail.my-site.comESMTP
ESMTPserver
serverready
ready
Troubleshooting Sendmail 2
• Use the hello command to tell the mail server the domain
you belong to:
HELO
HELOmy-other-site.com
my-other-site.com
250
250mail.my-site.com
mail.my-site.comHello
Hellomail.my-site.com
mail.my-site.com[192.168.3.5],
[192.168.3.5],pleased
pleasedtotomeet
meetyou
you
• You should receive a message with a successful status
250 code at the beginning of the response.
• Inform the mail server from which the test message is
coming with the MAIL FROM: statement:
MAIL
MAILFROM:[email protected]
FROM:[email protected]
250
250 [email protected]...
2.1.0 [email protected]
Senderok
ok