客户端发送邮件给自己的服务器a,服务器a通过smtpd服务的25号端口将邮件接收进来,此时服务器a通过dns服务器解析:如果是自己域中的邮件将交给邮件投递服务器将邮件投递到缓存区,不是发给自己域中的邮件,此时服务器a将作为客户端将通过smtp协议将邮件转发给服务器b,服务器b通过smtpd协议的25端口接收邮件并通过邮件投递服务器将邮件发送到缓冲区。
2)pop3-Post Office Protol 邮局协议,基于tcp-110端口;
3)imap4-Internet Mail Access Protocol互联网邮件访问协议,基于tcp-143端口;
4)smtp-Simple Mail Transfer Protocol 简单邮件传输协议,纯文本的且是明文传 送,基于tcp-25号端口;
1)Exchange;
2)Lotus Notes Domino;
3)sendmail;
4)postfix;
5)qmail;
6)exim;
2、MDA-Mail Delivery Agent(邮件投递代理);
1)procmail;
2)maildrop;
3、MRA-Mail Retrieval Agent(邮件取回/检索代理);
1)courier-imap;
2)cyrus-imap;
3)dovecot;
4、MUA-Mail User Agent(邮件用户代理);
1)OE;
2)foxmail;
3)mutt;
5、webmail-动态服务器界面;
6、MSA-Mail Submission Agent(邮件提交代理);
1)关闭开放式中继open relay;
2)认证:(1)基于IP的认证,只允许给某网段转发,会给出差的员工带来麻烦;
(2)基于用户的认证,这里最常用的就是SASL认证机制SASL-simple authentication secure layer简单认证安全层/库(用于为其它没有认证能力的服务提供认证功能),sasl是认证框架,本身不提供认证,saslauthd提供SASL认证服务,而提供saslauthd服务的软件有cyrus-sasl和dovecot,常用的认证机制有plain、login、mysql和ldap,cyrus-sasl的加密库为courier-authlib;
(1)垃圾邮件过滤器或邮件内容过滤器,根据邮件的内容对邮件进行检查,需依靠
spam assassin(垃圾邮件刺客)工具;
(2)病毒防护软件:clamav(著名病毒邮件网关-开源的);
通过caller呼叫器调用垃圾邮件过滤器或病毒防护软件;
caller比较常用的有:mailscanner、rnimedefang、amavisd-new;
4)DNS-RBL(DNS实时黑名单),当某服务客户端大量发送垃圾邮件时,在DNS服务器上 会记录该客户端为垃圾邮件客户端,mail服务器接收服务客户端的邮件前先去反解 服务客户端的ip地址,如果与DNS服务器实时黑名单上记录匹配就拒绝接收这个服 务客户端发来的邮件;
我们知道smtp和pop3、imap4接收个发送邮件都是以明文的方式进行传递的,所以数据的安全性就受到了很大的挑战,这就需要对邮件进行加密处理.
1)S/MIME,需要证书及公钥等来实现;
2)GPG(GNU Privacy Guard), 是PGP的一种实现,需要证书及公钥等来实现;
2、pop3加密:不需要在互联网上进行传输数据,使用ssl加密;
基于ssl加密,pop3s监听在tcp的995端口;
3、imap4加密:不需要在互联网上进行传输数据,使用ssl加密;
基于ssl加密,imaps监听在tcp的993端口;
通过以上的讲解应该对邮件服务器有了一个全局的了解了,下面我们就来演示一个具体的实现过程:
#yum -y install bind97 bind97-libs bind97-utils
options {- directory "/var/named";
- dump-file "/var/named/data/cache_dump.db";
- statistics-file "/var/named/data/named_stats.txt";
- memstatistics-file "/var/named/data/named_mem_stats.txt";
- recursion yes;
- };
- logging {
- channel default_debug {
- file "data/named.run";
- severity dynamic;
- };
- };
- zone "." IN {
- type hint;
- file "named.ca";
- };
- include "/etc/named.rfc1912.zones";
- #vim /etc/named.rfc1912.zones
zone "magedu.com" IN { type master; file "magedu.com.zone"; }; zone "16.172.in-addr.arpa" IN { type master; file "172.16.zone"; };
- $TTL 600
- $ORIGIN magedu.com.
- @ IN SOA ns.magedu.com. admin.magedu.com. (
- 2012071301
- 1H
- 10M
- 7D
- 1D )
- @ IN NS ns
- @ IN MX 10 mail
- ns IN A 172.16.11.1
- mail IN A 172.16.11.1
- www IN A 172.16.11.1
- pop3 IN CNAME mail
- $TTL 600
- @ IN SOA ns.magedu.com. admin.magedu.com. (
- 2012071301
- 1H
- 10M
- 7D
- 1D )
- @ IN NS ns.magedu.com.
- @ IN MX 10 mail.magedu.com.
- 1.11 IN PTR ns.magedu.com.
- 1.11 IN PTR mail.magedu.com.
- 1.11 IN PTR www.magedu.com.
- # named-checkzone "magedu.com" magedu.com.zone
- # named-checkzone "16.172.in-addr.arpa" 172.16.zone
- # service named start
二、卸载linux自带的sendmail软件并安装postfix以及对postfix的配置文件进行修改:
- [root@localhost named]# netstat -tnulp
- Active Internet connections (only servers)
- Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
- tcp 0 0 127.0.0.1:2208 0.0.0.0:* LISTEN 3310/./hpiod
- tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 2956/portmap
- tcp 0 0 172.16.11.1:53 0.0.0.0:* LISTEN 3853/named
- tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN 3853/named
- tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 3350/sshd
- tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 3366/cupsd
- tcp 0 0 127.0.0.1:953 0.0.0.0:* LISTEN 3853/named
- tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 3422/sendmail
- tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 3702/sshd
- tcp 0 0 0.0.0.0:638 0.0.0.0:* LISTEN 3000/rpc.statd
- tcp 0 0 127.0.0.1:2207 0.0.0.0:* LISTEN 3315/python
- udp 0 0 172.16.11.1:53 0.0.0.0:* 3853/named
- udp 0 0 127.0.0.1:53 0.0.0.0:* 3853/named
- udp 0 0 0.0.0.0:5353 0.0.0.0:* 3571/avahi-daemon
- udp 0 0 0.0.0.0:111 0.0.0.0:* 2956/portmap
- udp 0 0 0.0.0.0:631 0.0.0.0:* 3366/cupsd
- udp 0 0 0.0.0.0:632 0.0.0.0:* 3000/rpc.statd
- udp 0 0 0.0.0.0:635 0.0.0.0:* 3000/rpc.statd
- udp 0 0 0.0.0.0:52221 0.0.0.0:* 3571/avahi-daemon
- #rpm -e sendmail --nodeps
- #yum -y install postfix
- #service postfix start
- # netstat -tnulp
- Active Internet connections (only servers)
- Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
- tcp 0 0 127.0.0.1:2208 0.0.0.0:* LISTEN 3310/./hpiod
- tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 2956/portmap
- tcp 0 0 172.16.11.1:53 0.0.0.0:* LISTEN 3853/named
- tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN 3853/named
- tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 3350/sshd
- tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 3366/cupsd
- tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 5111/master
- tcp 0 0 127.0.0.1:953 0.0.0.0:* LISTEN 3853/named
- tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 3702/sshd
- tcp 0 0 0.0.0.0:638 0.0.0.0:* LISTEN 3000/rpc.statd
- tcp 0 0 127.0.0.1:2207 0.0.0.0:* LISTEN 3315/python
- udp 0 0 172.16.11.1:53 0.0.0.0:* 3853/named
- udp 0 0 127.0.0.1:53 0.0.0.0:* 3853/named
- udp 0 0 0.0.0.0:5353 0.0.0.0:* 3571/avahi-daemon
- udp 0 0 0.0.0.0:111 0.0.0.0:* 2956/portmap
- udp 0 0 0.0.0.0:631 0.0.0.0:* 3366/cupsd
- udp 0 0 0.0.0.0:632 0.0.0.0:* 3000/rpc.statd
- udp 0 0 0.0.0.0:635 0.0.0.0:* 3000/rpc.statd
- udp 0 0 0.0.0.0:52221 0.0.0.0:* 3571/avahi-daemon
myhostname= …定义自己的主机名;
mynetworks = …定义允许中继邮件的客户端来源;
myorigin = …发件人地址伪装;
mydestination = …定义本机负责接收邮件所在的域;
inet_interfaces = …定义监听的ip地址;
- myhostname = mail.magedu.com -----定义自己的主机名
- mydomain = magedu.com----定义自己所属的域
- myorigin = $mydomain----定义自己所属的域
- inet_interfaces = $myhostname,localhost--定义监听的ip地址
- myhostname = mail.magedu.com---定义允许中继邮件的客户端来源
- mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain, mail.$mydomain, www.$mydomain
- -----------定义本机负责接收邮件所在的域
- mynetworks = 192.168.0.0/24, 172.16.0.0/16, 127.0.0.0/8----定义允许中继邮件的客户端来源(这里我物理机的客户端是192.168.0.216)
- (注:postfixd的主配置文件很独特,如果某一行以空白字符开头的行表示是上一行的延续,如果不是空白开头的行表示独立的指令)
- # service postfix reload
- # netstat -tnlp
- Active Internet connections (only servers)
- Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
- tcp 0 0 127.0.0.1:2208 0.0.0.0:* LISTEN 3340/./hpiod
- tcp 0 0 0.0.0.0:641 0.0.0.0:* LISTEN 3003/rpc.statd
- tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 2959/portmap
- tcp 0 0 172.16.11.1:53 0.0.0.0:* LISTEN 3283/named
- tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN 3283/named
- tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 3365/sshd
- tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 3381/cupsd
- tcp 0 0 172.16.11.1:25 0.0.0.0:* LISTEN 4466/master
- tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 4466/master
- tcp 0 0 127.0.0.1:953 0.0.0.0:* LISTEN 3283/named
- tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 3702/sshd
- tcp 0 0 127.0.0.1:6011 0.0.0.0:* LISTEN 3738/sshd
- tcp 0 0 127.0.0.1:2207 0.0.0.0:* LISTEN 3345/python
- # useradd redhat
- # useradd gentoo
- # tail /var/log/maillog
- Jul 13 16:33:42 localhost postfix/smtpd[4862]: disconnect from unknown[192.168.0.216]
- Jul 13 16:34:01 localhost postfix/smtpd[4862]: connect from unknown[192.168.0.216]
- Jul 13 16:34:12 localhost postfix/smtpd[4862]: disconnect from unknown[192.168.0.216]
- Jul 13 16:34:26 localhost postfix/smtpd[4862]: connect from unknown[192.168.0.216]
- Jul 13 16:34:42 localhost postfix/smtpd[4862]: 531863756C4: client=unknown[192.168.0.216]
- Jul 13 16:34:59 localhost postfix/cleanup[4867]: 531863756C4: message-id=<20120713083442.531863756C4@mail.magedu.com>
- Jul 13 16:34:59 localhost postfix/qmgr[4861]: 531863756C4: from=<redhat@magedu.com>, size=358, nrcpt=1 (queue active)
- Jul 13 16:34:59 localhost postfix/local[4868]: 531863756C4: to=<gentoo@magedu.com>, orig_to=<gentoo>, relay=local, delay=23, delays=23/0.03/0/0.01, dsn=2.0.0, status=sent (delivered to mailbox)
- Jul 13 16:34:59 localhost postfix/qmgr[4861]: 531863756C4: removed
- Jul 13 16:35:01 localhost postfix/smtpd[4862]: disconnect from unknown[192.168.0.216]
- [gentoo@mail ~]$ mail
- Mail version 8.1 6/6/93. Type ? for help.
- "/var/spool/mail/gentoo": 1 message 1 new
- >N 1 redhat@magedu.com Fri Jul 13 16:34 15/485 "Hello"
- & 1
- Message 1:
- From redhat@magedu.com Fri Jul 13 16:34:59 2012
- X-Original-To: gentoo
- Delivered-To: gentoo@magedu.com
- Subject:Hello
- Date: Fri, 13 Jul 2012 16:34:36 +0800 (CST)
- From: redhat@magedu.com
- To: undisclosed-recipients:;
- Hoa are you ?
& ---------------------------------------邮件接收成功
[gentoo@mail ~]$ cat /etc/fstab | mail -s "Hello" redhat
- # tail /var/log/maillog
- Jul 13 16:41:50 localhost postfix/pickup[4860]: 451B93756C7: uid=503 from=<gentoo>
- Jul 13 16:41:50 localhost postfix/cleanup[4908]: 451B93756C7: message-id=<20120713084150.451B93756C7@mail.magedu.com>
- Jul 13 16:41:50 localhost postfix/qmgr[4861]: 451B93756C7: from=<gentoo@magedu.com>, size=898, nrcpt=1 (queue active)
- Jul 13 16:41:50 localhost postfix/local[4910]: 451B93756C7: to=<redhat@magedu.com>, orig_to=<redhat>, relay=local, delay=0.06, delays=0.06/0/0/0.01, dsn=2.0.0, status=sent (delivered to mailbox)
- Jul 13 16:41:50 localhost postfix/qmgr[4861]: 451B93756C7: removed
- [redhat@mail ~]$ mail
- Mail version 8.1 6/6/93. Type ? for help.
- "/var/spool/mail/redhat": 2 messages 2 new
- >N 1 gentoo@magedu.com Fri Jul 13 16:40 14/422 "Hello"
- N 2 gentoo@magedu.com Fri Jul 13 16:41 21/1019 "Hello"
- & 2
- Message 2:
- From gentoo@magedu.com Fri Jul 13 16:41:50 2012
- X-Original-To: redhat
- Delivered-To: redhat@magedu.com
- To: redhat@magedu.com
- Subject: Hello
- Date: Fri, 13 Jul 2012 16:41:50 +0800 (CST)
- From: gentoo@magedu.com
- /dev/vol0/root / ext3 defaults 1 1
- /dev/vol0/home /home ext3 defaults 1 2
- LABEL=/boot /boot ext3 defaults 1 2
- tmpfs /dev/shm tmpfs defaults 0 0
- devpts /dev/pts devpts gid=5,mode=620 0 0
- sysfs /sys sysfs defaults 0 0
- proc /proc proc defaults 0 0
- LABEL=SWAP-sda3 swap swap defaults 0 0
- & --------------------邮件发送成功:
- # Person who should get root's mail
- #root: marc
- redhat: gentoo --------表示发送给redhat用户的邮件让gentoo用户接收;
- [root@mail ~]# telnet mail.magedu.com 25
- Trying 172.16.11.1...
- Connected to mail.magedu.com (172.16.11.1).
- Escape character is '^]'.
- 220 mail.magedu.com ESMTP Postfix
- helo mail.magedu.com
- 250 mail.magedu.com
- mail from:root
- 250 2.1.0 Ok
- rcpt to:redhat
- 250 2.1.5 Ok
- data
- 354 End data with <CR><LF>.<CR><LF>
- Subject:To redhat
- Mail from:root
- Rcpt to:redhat
- Hello redhat?
- .
- 250 2.0.0 Ok: queued as 747EA375690
- quit
- 221 2.0.0 Bye
- Connection closed by foreign host.
- [root@mail ~]# tail /var/log/maillog
- Jul 13 18:48:50 localhost postfix/local[5985]: 747EA375690: to=<tom@magedu.com>, orig_to=<redhat>, relay=local, delay=74, delays=74/0.02/0/0.01, dsn=2.0.0, status=sent (delivered to mailbox)
- Jul 13 18:48:50 localhost postfix/qmgr[4861]: 747EA375690: removed
- Jul 13 18:48:52 localhost postfix/smtpd[5979]: disconnect from www.magedu.com[172.16.11.1]
- Jul 13 18:51:31 localhost postfix/smtpd[6000]: connect from ns.magedu.com[172.16.11.1]
- Jul 13 18:51:57 localhost postfix/smtpd[6000]: 15789375690: client=ns.magedu.com[172.16.11.1]
- Jul 13 18:52:50 localhost postfix/cleanup[6005]: 15789375690: message-id=<20120713105157.15789375690@mail.magedu.com>
- Jul 13 18:52:50 localhost postfix/qmgr[4861]: 15789375690: from=<root@magedu.com>, size=396, nrcpt=1 (queue active)
- Jul 13 18:52:50 localhost postfix/local[6006]: 15789375690: to=<gentoo@magedu.com>, orig_to=<redhat>, relay=local, delay=59, delays=59/0.02/0/0.01, dsn=2.0.0, status=sent (delivered to mailbox)
- Jul 13 18:52:50 localhost postfix/qmgr[4861]: 15789375690: removed
- Jul 13 18:52:51 localhost postfix/smtpd[6000]: disconnect from ns.magedu.com[172.16.11.1]
- [redhat@mail ~]$ mail
- No mail for redhat --------redhat用户没有接收到任何邮件;
- [redhat@mail ~]$
- [gentoo@mail ~]$ mail
- Mail version 8.1 6/6/93. Type ? for help.
- "/var/spool/mail/gentoo": 2 messages 2 new
- >N 1 MAILER-DAEMON@magedu Fri Jul 13 18:22 68/2147 "Undelivered Mail Returned to Sender"
- N 2 root@magedu.com Fri Jul 13 18:52 17/517 "To redhat"
- & 2
- Message 2:
- From root@magedu.com Fri Jul 13 18:52:50 2012
- X-Original-To: redhat
- Delivered-To: redhat@magedu.com
- Subject:To redhat
- Date: Fri, 13 Jul 2012 18:51:51 +0800 (CST)
- From: root@magedu.com
- To: undisclosed-recipients:;
- Mail from:root
- Rcpt to:redhat
- Hello redhat?
- & --------------------root用户发送给redhat用户的邮件同过邮件别名将邮件转发给了gentoo用户接收了;