Linux配置Sendmail问题排查

安装:

yum install sendmail
#yum install sendmail-cf 
#yum install mailx
systemctl start sendmail
systemctl enable sendmail

修改hostname:

#hostnamectl set-hostname peakchao
$vi /etc/sysconfig/network
# Created by peakchao
hostname=peakchao.com
$vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
127.0.0.1	peakchao.com	peakchao

配置发件人信息:

#vi /etc/mail.rc
set ssl-verify=ignore
set from=admin
set [email protected]
set smtp=smtp.126.com
set smtp-auth-user=peakchao
set smtp-auth-password=1234560
set smtp-auth=login

编辑配置文件:

#vi /etc/mail/sendmail.mc  将127.0.0.1改为0.0.0.0
DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl PLAIN')dnl 
#m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf 重新编译配置文件
#vi /etc/mail/submit.cf
找到行 #Dj$w.Foo.COM,修改为 
Djxxx.com 
#service sendmail restart

sendmail无法启动:

#hostname
izf9t76wjp0zs8z
#vi /etc/hosts  添加如下解析
127.0.0.1	izf9t76wjp0zs8z izf9t76wjp0zs8z.com

重启sendmail后发送测试邮件:

#echo  '内容'  |  mail  -s  '主题'  [email protected]
#mailq 查询队列
		/var/spool/mqueue (4 requests)
-----Q-ID----- --Size-- -----Q-Time----- ------------Sender/Recipient-----------
x69ADipH005938        7 Tue Jul  9 18:13 
                 (Deferred: Connection timed out with mx1.qq.com.)
					 
x69AJwiU006021        7 Tue Jul  9 18:19 
      8BITMIME   (Deferred: Connection timed out with mx2.mail.aliyun.com.)
					 
x69AILsv006007        7 Tue Jul  9 18:18 
      8BITMIME   (Deferred: Connection timed out with mx1.qq.com.)
					 
x69AJGlQ006014        7 Tue Jul  9 18:19 
      8BITMIME   (Deferred: Connection timed out with mx1.qq.com.)
					 
		Total requests: 4
#cat /var/spool/mail/root  查询邮件
--x69EHiiY006219.1562682165/izf9t76wjp0zs8z.com
Content-Type: message/rfc822
Content-Transfer-Encoding: 8bit

Return-Path: 
Received: from izf9t76wjp0zs8z.com (localhost [127.0.0.1])
	by izf9t76wjp0zs8z.com (8.14.7/8.14.7) with ESMTP id x69AJGlQ006014
	for ; Tue, 9 Jul 2019 18:19:16 +0800
Received: (from root@localhost)
	by izf9t76wjp0zs8z.com (8.14.7/8.14.7/Submit) id x69AJGAR006013
	for [email protected]; Tue, 9 Jul 2019 18:19:16 +0800
From: root 
Message-Id: <[email protected]>
Date: Tue, 09 Jul 2019 18:19:16 +0800
To: [email protected]
Subject: =?utf-8?B?5Li76aKY?=
User-Agent: Heirloom mailx 12.5 7/5/10
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

内容

--x69EHiiY006219.1562682165/izf9t76wjp0zs8z.com--
#cat /var/log/maillog  查看邮件log
Jul  9 22:00:28 peakchao sendmail[3409]: STARTTLS=client, relay=mx3.qq.com., version=TLSv1/SSLv3, verify=FAIL, cipher=ECDHE-RSA-AES128-GCM-SHA256, bits=128/128
Jul  9 22:00:29 peakchao sendmail[3409]: x69E0RKo003407: to=, delay=00:00:02, xdelay=00:00:02, mailer=esmtp, pri=120556, relay=mx3.qq.com. [14.215.140.20], dsn=5.0.0, stat=Service unavailable
Jul  9 22:00:29 peakchao sendmail[3409]: x69E0RKo003407: to=, delay=00:00:02, mailer=local, pri=120556, dsn=5.1.1, stat=User unknown
Jul  9 22:00:29 peakchao sendmail[3409]: x69E0RKo003407: x69E0TKo003409: postmaster notify: User unknown

解决Service unavailable和User unknown问题:

邮件记录找到关键信息:
   ----- Transcript of session follows -----
... while talking to mx3.qq.com.:
>>> DATA
<<< 550 SPF check failed [N49JnDql/1/QS1SF8BUKBRZZOJIlT16IGygW3i90uwFLQmrTuKy4IEk=  IP: 171.217.52.232]. http://service.mail.qq.com/cgi-bin/help?subtype=1&&no=1001445&&id=20022.
554 5.0.0 Service unavailable
550 5.1.1 ... User unknown

解决问题

#新增解析
A记录  mail  服务器IP地址
TXT记录  @  v=spf1 include:peakchao.com xx.peakchao.com spf.mxhichina.com -all

用到的一些命令:

yum list | grep sendmail
yum install sendmail
rpm -qa | grep sendmail 
tail  /var/log/maillog
fail2ban-client set ssh unbanip x.x.x.x

你可能感兴趣的:(Linux)