Sendmail
簡單配置(3)
RHEL5.1
基本網絡配置
1、
1
、RHEL5 U1:如圖1
(如圖1)
2
、#hostname //查看當前主機的主機名:如圖2
(如圖2)
3
、#vi /etc/sysconfig/network-scripts/ifcfg-eth0 編輯指定網絡接口配置文件:如圖3
(如圖3)
4
、#vi /etc/sysconfig/network 經過配置文件修改主機名:如圖4
(如圖4)
5
、在終端字符界面修改其字體和中文字體大小:如圖5
(如圖5)
6
、掛載光盤:如圖6
(如圖6)
7
、查看OpenSSH是否安裝:如圖7
(如圖7)
8
、
#vi /etc/hosts
設置本地
DNS
解析文件:
如圖8
(如圖8)
9
、
#vi /etc/resolv.conf
指定當前主機的
DNS
服務器,最多可指定三個:
如圖9
(如圖9)
10
、關閉iptables防火牆:如圖10
(如圖10)
2、DNS簡單配置
1
、vim /etc/named.conf
2
、vim /var/named/benet.com.zone
3
、vim /var/named/1.168.192.in-addr.arpa.zone
4
、重啓named服務
[root@dns ~]# service named restart
中止 named: [失敗]
啓動 named: [肯定]
[root@dns ~]# chkconfig --list named
named 0:關閉 1:關閉 2:關閉 3:關閉 4:關閉 5:關閉 6:關閉
[root@dns ~]# chkconfig --level 2345 named on
[root@dns ~]# chkconfig --list named
named 0:關閉 1:關閉 2:啓用 3:啓用 4:啓用 5:啓用 6:關閉
5
、nslookup查看
3、sendmail簡單配置
1
、
修改
local-host-names
文件添加域名及主機名
vim /etc/mail/local-host-names
[root@dns Server]# m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
[root@dns Server]# vim /etc/mail/local-host-names
# local-host-names - include all aliases for your machine here.
benet.com.
mail.benet.com.
~
~
~
"/etc/mail/local-host-names" 3L, 91C 已寫入
[root@dns Server]#
2
、確保
sasl
庫已經安裝
[root@dns Server]# rpm -qa | grep cyrus-sasl
cyrus-sasl-lib-2.1.22-4
cyrus-sasl-2.1.22-4
cyrus-sasl-plain-2.1.22-4
cyrus-sasl-devel-2.1.22-4
[root@dns Server]# rpm -qa cyrus-sasl
cyrus-sasl-2.1.22-4
[root@dns Server]# rpm -qa cyrus-sasl-lib
cyrus-sasl-lib-2.1.22-4
3
、安裝sendmail
root@dns ~]# mount /dev/hdc /mnt/dvd/
mount: block device /dev/hdc is write-protected, mounting read-only
[root@dns ~]# cd /mnt/dvd/Server/
[root@dns Server]# rpm -qa | grep sendmail
sendmail-8.13.8-2.el5
[root@dns Server]# ls sendmail*
sendmail-8.13.8-2.el5.i386.rpm sendmail-devel-8.13.8-2.el5.i386.rpm
sendmail-cf-8.13.8-2.el5.i386.rpm sendmail-doc-8.13.8-2.el5.i386.rpm
[root@dns Server]# rpm -ivh --aid sendmail-cf-8.13.8-2.el5.i386.rpm
warning: sendmail-cf-8.13.8-2.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing... ########################################### [100%]
1:sendmail-cf ########################################### [100%]
[root@dns Server]# rpm -ivh --aid sendmail-devel-8.13.8-2.el5.i386.rpm
warning: sendmail-devel-8.13.8-2.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing... ########################################### [100%]
1:sendmail-devel ########################################### [100%]
[root@dns Server]# rpm -ivh --aid sendmail-doc-8.13.8-2.el5.i386.rpm
warning: sendmail-doc-8.13.8-2.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing... ########################################### [100%]
1:sendmail-doc ########################################### [100%]
[root@dns Server]#
[root@dns Server]# rpm -qa | grep sendmail
sendmail-devel-8.13.8-2.el5
sendmail-doc-8.13.8-2.el5
sendmail-cf-8.13.8-2.el5
sendmail-8.13.8-2.el5
[root@dns Server]# rpm -qa | grep m4
m4-1.4.5-3.el5.1
4
、修改
開啓sendmai認證
(
vim /etc/mail/sendmail.mc
)
去掉如下三行的
dnl字段開啓sendmail認證功能
52行
TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
53行
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
123行
DAEMON_OPTIONS(`Port=submission, Name=MSA, M=Ea')dnl
修改
52
行和
53
行
修改
123
行
5
、修改
116
行
第
116行
將smtp偵聽範圍從127.0.0.1改成0.0.0.0
6
、修改第
155
行
第
155行修改爲本身域:
LOCAL_DOMAIN(`benet.com')dnl
7
、默認
175
行
8
、
設置用戶用戶郵件的大小限制(
187
行)
在sendmail.mc中沒有這個選項,這個要在sendmail.cf中設置
vim /etc/mail/sendmail.cf
默認不限制:
# maximum message size
#O MaxMessageSize=0
咱們能夠設置成郵件最大不超過20MB
# maximum message size
O MaxMessageSize=20971520
意思爲每次收發郵件最大爲20MB,任何超過這個值的郵件將被拒絕。
9
、
使用
m4
命令生成
sendmail.cf
文件
m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
10
、郵件用戶帳戶的設置
[root@dns Server]# groupadd gongchengbu
[root@dns Server]# adduser -g gongchengbu -s /sbin/nologin honglin1
[root@dns Server]# adduser -g gongchengbu -s /sbin/nologin honglin2
[root@dns Server]# passwd honglin1
Changing password for user honglin1.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@dns Server]# passwd honglin2
Changing password for user honglin2.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@dns Server]# useradd zhangsan
[root@dns Server]# passwd zhangsan
Changing password for user zhangsan.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@dns Server]# useradd lisi
[root@dns Server]# passwd lisi
Changing password for user lisi.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@dns Server]# useradd wangwu
[root@dns Server]# passwd wangwu
Changing password for user wangwu.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
11
、設置郵件別名和郵件羣發功能
[root@dns Server]# ls /etc/aliases
/etc/aliases
[root@dns Server]# ls /etc/aliases*
/etc/aliases /etc/aliases.db
[root@dns Server]# vim /etc/aliases
ftp-admin: ftp
www: webmaster
webmaster: root
noc: root
security: root
hostmaster: root
info: postmaster
marketing: postmaster
sales: postmaster
support: postmaster
gongchengbu: honglin1,honglin2
# trap decode to catch security attacks
decode: root
# Person who should get root's mail
"/etc/aliases" 97L, 1546C 已寫入
[root@dns Server]#
12
、經過
newaliases
生成
aliases.db
文件
[root@dns Server]# newaliases
/etc/aliases: 77 aliases, longest 17 bytes, 793 bytes total
13
、修改
vim /etc/mail/access
14
、經過
「makemap hash access.db < access」
生成數據庫文件
[root@dns Server]# makemap hash /etc/mail/access.db < /etc/mail/access
[root@dns Server]#
[root@dns Server]# service sendmail restart
關閉 sm-client: [肯定]
關閉 sendmail: [肯定]
啓動 sendmail: [肯定]
啓動 sm-client: [肯定]
4、配置磁盤配額
1
、
vim /etc/fstab
添加/var文件系統參數
LABEL=/var /var ext3 defaults,usrquota,grpquota 1 2
usrquota
爲用戶的配額參數,
grpquota
爲組的配額參數
[root@dns Server]# vim /etc/fstab
LABEL=/ / ext3 defaults 1 1
LABEL=/tmp /tmp ext3 defaults 1 2
LABEL=/var /var ext3 defaults,usrquota,grpquota 1
2
LABEL=/usr /usr ext3 defaults 1 2
LABEL=/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
~
~
"/etc/fstab" 11L, 854C 已寫入
2
、建立配額文件
由於存放郵件信息的/var目錄在獨立的分區哈~因此咱們使用
quotachek命令在/var目錄下分別爲用戶和組建立配額文件
quotacheck -cugm /var
3
、設置磁盤配額
爲用戶和組設置詳細的配額限制,咱們可使用
edquota命令進行磁盤配額的設置哈~
edquota
命令格式:
edquota -u
用戶名
edquota -g
組名
好比爲用戶
zhangsan配置磁盤配額限制,執行
edquota命令,打開用戶配額配置文件
edquota -u zhangsan
4
、使磁盤配額生效
命令:
quotaon -augv
目錄名
參數:
-a 開啓在/ect/fstab文件裏,有加入quota設置的分區的空間限制。
-g 開啓羣組的磁盤空間限制。
-u 開啓用戶的磁盤空間限制。
-v 顯示指令指令執行過程。
quotaon -av
五、
查看磁盤配額狀態
Repquota -a
6
、
注意:
若是企業員工較多,那麼像這樣一個個爲每一個員工單獨配置磁盤配額將會增長咱們管理的難度哈~這裏咱們能夠創建一個樣簡單的腳本,將全部用戶的磁盤空間科學硬限制爲200MB。
在/etc/mail/目錄下建立一個quota.sh磁盤配額腳本文件
vim /etc/mail/quota.sh
[root@dns ~]#
vim /etc/mail/quota.sh
#!/bin/bash
for i in zhangsan lisi wangwu honglin1 honglin2
do
setquota -u $i 0 200000 0 0 /var
done
~
~
~
"/etc/mail/quota.sh" [新] 5L, 101C 已寫入
[root@dns ~]#
. /etc/mail/quota.sh
七、
. /etc/mail/quota.sh執行此腳本並查看
八、執行
quotaoff -av後執行
quotaon -av使設置的磁盤配額生效
5、安裝
Dovecot
軟件包(
POP3
和
IMAP
)
1
、安裝
dovecot
[root@dns Server]# rpm -ivh --aid mysql-5.0.45-7.el5.i386.rpm
warning: mysql-5.0.45-7.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
error: Failed dependencies:
perl(DBI) is needed by mysql-5.0.45-7.el5.i386
[root@dns Server]# rpm -ivh --aid perl-DBI-1.52-2.el5.i386.rpm
warning: perl-DBI-1.52-2.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing... ########################################### [100%]
1:perl-DBI ########################################### [100%]
[root@dns Server]# rpm -ivh --aid mysql-5.0.45-7.el5.i386.rpm
warning: mysql-5.0.45-7.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing... ########################################### [100%]
1:mysql ########################################### [100%]
[root@dns Server]# rpm -ivh --aid dovecot-1.0.7-7.el5.i386.rpm
warning: dovecot-1.0.7-7.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing... ########################################### [100%]
1:dovecot ########################################### [100%]
2
、生成私鑰和自簽名證書
Mail服務器會使用私鑰加密郵件,客戶端在收取郵件時,則使用Mail服務器證書中的公鑰對郵件進行解密,這樣才能正常讀取郵件哈~,
/etc/pki/tls/certs/Makefile文件保存着生成密鑰和證書的腳本設置,這裏使用make命令製做
dovecot.pem文件,其保存郵件服務器的私鑰和公鑰信息。
make -C /etc/pki/tls/certs/ dovecot.pem
生成證書時,按要求依次填寫國家、省份、城市等等信息
[root@dns Server]# make -C /etc/pki/tls/certs/ dovecot.pem
make: Entering directory `/etc/pki/tls/certs'
umask 77 ; \
PEM1=`/bin/mktemp /tmp/openssl.XXXXXX` ; \
PEM2=`/bin/mktemp /tmp/openssl.XXXXXX` ; \
/usr/bin/openssl req -newkey rsa:1024 -keyout $PEM1 -nodes -x509 -days 365 -out $PEM2 -set_serial 0 ; \
cat $PEM1 > dovecot.pem ; \
echo "" >> dovecot.pem ; \
cat $PEM2 >> dovecot.pem ; \
rm -f $PEM1 $PEM2
Generating a 1024 bit RSA private key
...................................++++++
.++++++
writing new private key to '/tmp/openssl.DW2402'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [GB]:CN
State or Province Name (full name) [Berkshire]:BeiJing
Locality Name (eg, city) [Newbury]:Chaoyang
Organization Name (eg, company) [My Company Ltd]:zhangsan
Organizational Unit Name (eg, section) []:MIS
Common Name (eg, your name or your server's hostname) []:mail.benet.com
Email Address []:zhangsan.benet.com
make: Leaving directory `/etc/pki/tls/certs'
3
、修改
dovecot.conf
配置文件
1
)、修改
17
行,去掉前面
#
2
)、修改
87-88
行,去掉前面
#
,並修改
88
行內容
3
)、重啓
sendmail
、
dovecot
、
saslauthd
服務
[root@dns Server]# service sendmail restart
關閉 sm-client: [肯定]
關閉 sendmail: [肯定]
啓動 sendmail: [肯定]
啓動 sm-client: [肯定]
[root@dns Server]# service dovecot restart
中止 Dovecot Imap: [失敗]
啓動 Dovecot Imap: [肯定]
[root@dns Server]# service saslauthd restart
中止 saslauthd: [失敗]
啓動 saslauthd: [肯定]
[root@dns Server]# chkconfig --list sendmail
sendmail 0:關閉 1:關閉 2:啓用 3:啓用 4:啓用 5:啓用 6:關閉
[root@dns Server]# chkconfig --list dovecot
dovecot 0:關閉 1:關閉 2:關閉 3:關閉 4:關閉 5:關閉 6:關閉
[root@dns Server]# chkconfig --level 2345 dovecot on
[root@dns Server]# chkconfig --list dovecot
dovecot 0:關閉 1:關閉 2:啓用 3:啓用 4:啓用 5:啓用 6:關閉
[root@dns Server]# chkconfig --list saslauthd
saslauthd 0:關閉 1:關閉 2:關閉 3:關閉 4:關閉 5:關閉 6:關閉
[root@dns Server]# chkconfig --level 2345 saslauthd on
[root@dns Server]# chkconfig --list saslauthd
saslauthd 0:關閉 1:關閉 2:啓用 3:啓用 4:啓用 5:啓用 6:關閉
4
)、查看端口狀態
[root@dns Server]# netstat -tupln
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 1893/hpiod
tcp 0 0 0.0.0.0:998 0.0.0.0:* LISTEN 1664/rpc.statd
tcp 0 0 0.0.0.0:587 0.0.0.0:* LISTEN 2448/sendmail: acce
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1629/portmap
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1938/cupsd
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 2448/sendmail: acce
tcp 0 0 127.0.0.1:2207 0.0.0.0:* LISTEN 1898/python
tcp 0 0 :::993 LISTEN 2479/dovecot
tcp 0 0 :::995 LISTEN 2479/dovecot
tcp 0 0 :::110 LISTEN 2479/dovecot
tcp 0 0 :::143 LISTEN 2479/dovecot
tcp 0 0 :::22 LISTEN 1922/sshd
udp 0 0 0.0.0.0:32768 0.0.0.0:* 2117/avahi-daemon:
udp 0 0 0.0.0.0:992 0.0.0.0:* 1664/rpc.statd
udp 0 0 0.0.0.0:995 0.0.0.0:* 1664/rpc.statd
udp 0 0 0.0.0.0:5353 0.0.0.0:* 2117/avahi-daemon:
udp 0 0 0.0.0.0:111 0.0.0.0:* 1629/portmap
udp 0 0 0.0.0.0:631 0.0.0.0:* 1938/cupsd
udp 0 0 :::32769 2117/avahi-daemon:
udp 0 0 :::5353 2117/avahi-daemon:
[root@dns Server]#
6、測試
1
、服務器狀態
eth1網卡192.168.10.200
2
、客戶端測試
1
)、
192.168.1.0/24
位測試
2
)、
192.168.1.0/24
和
192.168.10.0/24
網段測試
3
)、小於
20MB
附件測試
4
)、別名郵件測試
5
)、大於
20MB
附件測試
6)、repquota –a 查看
配置文件在附件裏面:
若有不懂的地方,請call我!qq:357714938 mail:hongwish8es@126.com