歡迎您光臨本站 註冊首頁

linux22-sendmail,postfix

←手機掃碼閱讀     火星人 @ 2014-03-08 , reply:0

sendmail 單體式結構


qmail


postfix 模塊化設計 參考posft權威指南15,16頁

postfix在本機的發信原理 參考posft權威指南30頁的圖3-2
35頁的圖3-4


postfix


yum install postfix* dovecot system-switch-mail -y

[root@dns ~]# rpm -qi system-switch-mail-0.5.25-12 --查看這個包,說明是一個MTA切換工具


[root@li named]# system-switch-mail --使用這條命令進行MTA的切換
[root@li named]# /etc/init.d/sendmail status --切換過後,默認關閉了sendmail
sendmail is stopped
[root@li named]# /etc/init.d/postfix status --並自動啟動了posftfix
master (pid 4896) is running...

[root@dns ~]# vim /etc/postfix/main.cf


myhostname = dns.cluster.com --只修改主機名,主機名對postfix非常重要,當然如果不改,它自己會調用gethostname()去查詢


[root@dns ~]# /etc/init.d/postfix restart


[root@dns ~]# mail user1 --給本地的user1用戶發郵件

[root@dns ~]# su - user1
[user1@dns ~]$ mail --切換到user1用戶查看,可以收到郵件
Mail version 8.1 6/6/93. Type ? for help.
"/var/spool/mail/user1": 1 message 1 new
>N 1 root@dns.cluster.com Sun May 8 10:26 14/454
& 1

-------------------------------------------------------

兩個sendmail的互發


sendmail ---- sendmail

172.16.57.130 172.16.57.131

li.aaa.com li.bbb.com

回顧一下郵件的配置過程


1,首先配置好主機名,三步, hostname x.x.com vim /etc/hosts vim /etc/sysconfig/network
最好用靜態IP vim /etc/sysconfig/network-scripts/ifcfg-eth0


時間同步 ntpdate x.x.x.x
關閉iptables service iptables stop
selinux vim /etc/selinux/config 確認是否為disabled
配置好yum,為後面裝包方便


2.
我這裡把DNS伺服器做在172.16.57.1上

[root@dns ~]# vim /var/named/chroot/etc/named.conf

options {
directory "/var/named";
};


zone "aaa.com" IN {
type master;
file "data/master.aaa.com.zone";
};

zone "bbb.com" IN {
type master;
file "data/master.bbb.com.zone";
};


[root@dns etc]# vim /var/named/chroot/var/named/data/master.aaa.com.zone


$TTL 86400
@ IN SOA li.cluster.com. root. (
2011081101
60
30
360
86400 )
IN NS li.aaa.com.
IN MX 0 li.aaa.com.
li IN A 172.16.57.130

[root@dns etc]# vim /var/named/chroot/var/named/data/master.bbb.com.zone


$TTL 86400
@ IN SOA li.cluster.com. root. (
2011081101
60
30
360
86400 )
IN NS li.bbb.com.
IN MX 0 li.bbb.com.
li IN A 172.16.57.131


# /etc/init.d/named restart --啟動DNS服務

--然後把兩台郵件伺服器的/etc/resolv.conf的DNS指向DNS伺服器的IP 172.16.57.1
[root@li ~]# nslookup --兩台都要這樣驗證aaa.com和bbb.com兩個域的郵件交換記錄OK


> set type=mx
> aaa.com
Server: 172.16.57.1
Address: 172.16.57.1#53

aaa.com mail exchanger = 0 li.aaa.com.
> bbb.com
Server: 172.16.57.1
Address: 172.16.57.1#53

bbb.com mail exchanger = 0 li.bbb.com.


3,在兩台郵件伺服器上安裝sendmail郵件伺服器相關軟體包
[root@li ~]# yum install sendmail* dovecot m4 -y


4,配置郵件 --兩邊都做

[root@li named]# vim /etc/mail/sendmail.mc --sendmail配置檔

DAEMON_OPTIONS(`Port=smtp,Addr=0.0.0.0, Name=MTA')dnl --改為0.0.0.0,監聽所有

[root@li named]# vim /etc/dovecot.conf

protocols = imap imaps pop3 pop3s

[root@li named]# /etc/init.d/sendmail restart

[root@li named]# /etc/init.d/dovecot restart

netstat -ntl 驗證埠 smtp (25) pop3 (110) imap (143)

5,驗證,
自己給自己發 @主機名 @域名 OK
自己給別方發 @主機名 OK
@域名 不行

6,--實現自己給對方發用短域名OK
在li.aaa.com里
vim /etc/mail/local-host-names --加上
li.aaa.com
aaa.com
在li.bbb.com里
vim /etc/mail/local-host-names --加上
li.bbb.com
bbb.com

重啟sendmail /etc/init.d/sendmail restart


再次驗證
使用 @域名 互發 OK

--但注意的是上面的步驟做完后,兩台sendmail之間可以使用mail -s互相跨域發送郵件;但是再用兩個客戶端的話,互相跨域發送郵件會報中繼拒絕的錯誤

SENDMAIL SENDMAIL
li.aaa.com li.bbb.com
172.16.57.130 172.16.57.131

DNS
li.cluster.com
172.16.57.1


claw-mail 172.16.57.1 OUTLOOK 172.16.57.132


zhangsan@aaa.com lisi@bbb.com


如果還要另用MUA客戶端軟體來互相發的話,上面的兩個郵件伺服器還要允許這兩個客戶端的IP進行轉發

vim /etc/mail/access
Connect:172.16.57 RELAY
/etc/init.d/sendmail restart

==================================================================


把上面其中一台換成postfix

postfix sendmail
li.aaa.com li.bbb.com
172.16.57.130 172.16.57.131

DNS
li.cluster.com
172.16.57.1


claw-mail 172.16.57.1 OUTLOOK 172.16.57.132
zhangsan@aaa.com lisi@bbb.com


下面在li.aaa.com上的操作
[root@li ~]# yum install postfix* system-switch-mail -y


[root@li ~]# vim /etc/postfix/main.cf --配置參數格式參考PDF第41頁
--主要參數介紹參考PDF第52頁


[root@li ~]# vim /etc/postfix/main.cf

myhostname = li.aaa.com --定義自己的主機名

[root@li ~]# /etc/init.d/postfix restart

現在就可以自己與自己發送郵件
自己給sendmail發,也可以(sendmail那邊的配置是OK的)
但sendmail給自己發,就不可以(postfix也是默認只監聽127.0.0.1)

[root@li ~]# vim /etc/postfix/main.cf

inet_interfaces = all --表示監聽所有

[root@li ~]# /etc/init.d/postfix restart

現在sendmail給自己發,用長域名就可以了,短域名不可以


[root@li ~]# vim /etc/postfix/main.cf

mydestination = $myhostname, localhost.$mydomain, localhost,aaa.com
--在上面的基礎上把mydestination後面加上aaa.com

[root@li ~]# /etc/init.d/postfix restart

現在sendmail給自己發,用短域名也可以了


把上面幾個小例子綜合配置一個postfix郵件伺服器

vim /etc/postfix/main.cf

myhostname = li.aaa.com --本機主機名
mydomain = aaa.com --本機域名,postfix會自動扣除第一點號前的部分作為域名.如果不是FQDN形式的主機名,就一定要手動配置你的域名
myorigin = $mydomain --當你在li.aaa.com以user1發送郵件,它會自動把你的發信地址改為user1@aaa.com
inet_interfaces = all --監聽所有
mydestination = $myhostname, localhost.$mydomain, localhost ,$mydomain
--加上$mydomain,則表示可以直接以域名來收郵件
mynetworks = 172.16.57.0/24, 127.0.0.0/8 --信任網路,在這裡也可以不配,默認值為subnet,也就是本網段內的都是信任網路

/etc/init.d/postfix restart

===================================

再把另一台sendmail也換成postfix

postfix postfix
li.aaa.com li.bbb.com
172.16.57.130 172.16.57.131

DNS
li.cluster.com
172.16.57.1


claw-mail 172.16.57.1 OUTLOOK 172.16.57.132
zhangsan@aaa.com lisi@bbb.com

做法和上面一樣


然後測試兩台postfix伺服器的互發 長短域名 都OK


==========================================================

postfix 驗證 --參考postfix中文權威指南的173頁
不自帶驗證
需要sasl包來驗證
sasl( simple authention and security layer)

yum install cyrus-sasl


/etc/init.d/saslauthd restart


cat /usr/lib/sasl2/smtpd.conf
pwcheck_method: saslauthd


[root@li ~]# vim /etc/postfix/main.cf --加上下面一段
smtpd_sasl_auth_enable = yes


broken_sasl_auth_clients = yes
smtpd_sasl_security_options = noanonymous
smtpd_recipient_restrictions =
permit_mynetworks,
permit_sasl_authenticated,
reject_non_fqdn_hostname,
reject_unknown_sender_domain,
reject_non_fqdn_sender,
reject_non_fqdn_recipient,
reject_unauth_destination,
reject_unauth_pipelining,
reject_invalid_hostname


/etc/init.d/postfix restart
/etc/init.d/saslauthd restart


--上面一系列的參數就是驗證通過的規則,從上往下匹配,匹配一條后,就不再匹配
--permit_mynetworks
這個參數就表示mynetworks這個參數配置的網段里的主機都是允許的,
也就是說,只要是你配置的信任網段里的主機,不管它們密碼有沒有寫對,還是主
機名不符合FQDN,都是允許的
--permit_sasl_authenticated
這個參數是需要郵件客戶端把驗證打勾,它表示:用戶的密碼要寫對才允許通過


--上面的參數總結起來就是表示:
1,只要是mynetworks配置的信任網段就允許
2,如果不是信任的網段內的主機,則把驗證打勾,然後就匹配第二條,只要用戶名和密碼正確也允許
3,拒絕非FQDN的主機名,拒絕未知的發送域,拒絕......等等


例子1:
有permit_mynetworks此參數
那麼只要是信任的網段,故意把用戶的密碼寫錯,也可以互發郵件


例子2.
註釋permit_mynetworks這個參數,客戶端也不把驗證打勾.
然後發送測試.claws-mail報relay access deny
xp報 helo FQDN的主機名拒絕

解決:
把客戶端驗證打勾
再發送測試: 可以互發.它們是通過了permit_sasl_authenticated的驗證

再把用戶密碼故意寫錯,發送測試,也通過不了

==========================================================

=============================================================

在上面的基礎上加webmail功能

postfix postfix
li.aaa.com li.bbb.com
172.16.57.130 172.16.57.131
--加openwebmail --squirrelmail

DNS
li.cluster.com
172.16.57.1


claw-mail 172.16.57.1 OUTLOOK 172.16.57.132
zhangsan@aaa.com lisi@bbb.com


--在130上做以下操作
openwebmail 一個網頁的郵件收發工具,支持附件,網盤等各種功能

官方網站http://openwebmail.org/


軟體包地址
ls /share/soft/openwebmail/
openwebmail-2.51-20050627.src.rpm openwebmail-data-2.53-1.i386.rpm
openwebmail-2.53-1.i386.rpm perl-Text-Iconv-1.7-2.el5.i386.rpm
openwebmail-2.53.tar.gz

[root@li /]# yum install perl-suidperl httpd httpd-devel -y

[root@li openwebmail]# rpm -ivh perl-Text-Iconv-1.7-2.el5.i386.rpm

[root@li openwebmail]# useradd -s /sbin/nologin tchung --tchung這個用戶是作者名,如果不加這個用戶,下一步會報錯說tchung用戶不存在

[root@li openwebmail]# rpm -ivh openwebmail-data-2.53-1.i386.rpm openwebmail-2.53-1.i386.rpm --這兩個包要一起裝,是互相依賴性的包

Permission and Ownership for openwebmail files have been fixed!

Please execute following tool first as a root:
/var/www/cgi-bin/openwebmail/openwebmail-tool.pl --init

After restarting httpd service, login with non-root account from
http://li.aaa.com/cgi-bin/openwebmail/openwebmail.pl
or http://li.aaa.com/webmail

If SELinux enabled, you may need to set it 'permissive' in


/etc/sysconfig/selinux or system-config-selinux

[root@li openwebmail]# /var/www/cgi-bin/openwebmail/openwebmail-tool.pl --init

初始化后


啟動httpd 服務 /etc/init.d/httpd start

--在131上加squirrelmail(rhel自帶的 rpm 版webmail,基於php的)


[root@li ~]# yum install squirrelmail -y


[root@li ~]# vim /etc/squirrelmail/config.php


$provider_uri = 'http://li.bbb.com/';

$domain = 'bbb.com'; --寫上自己的域,默認為localhost,如果你用lisi發信,在zhangsan那邊收到的發信人為lisi@localhost.改成bbb.com就會正常顯示為lisi@bbb.com了

本文出自 「linuxart」 博客,請務必保留此出處http://linuxart.blog.51cto.com/686203/843981


[火星人 ] linux22-sendmail,postfix已經有508次圍觀

http://coctec.com/docs/linux/show-post-45759.html