*以伺服器位址120.79.254.2為例,伺服器具體位址數值僅為示範所需,并非真實所用位址,如有冒犯,請聯系更改。
1. 切換權限
sudo su root
2.安裝DNS伺服器軟體包
yum install bind -y
yum install bind-libs -y
3.配置/etc/named.conf檔案
vim /etc/named.conf
修改:
listen-on port 53 { any; };
allow-query { any; };
增加:
zone "uc-knight.top" IN{
type master;
file "uc-knight.top.zone";
};
zone "254.79.120.in-addr.arpa" IN{
type master;
file "254.79.120.zone";
};
4.配置 /var/named/uc-knight.top.zone 檔案
vim /var/named/uc-knight.top.zone
$ttl 600
@ IN SOA lance.uc-knight.top. lance.www.uc-knight.top.(
2018060601 10800 3600 604800 38400 )
; Serial Refresh Retry Expire MinumumTTL
; Serial<2^32 Refresh>=Retry*2 Refresh+Retry<Expire
; Expire>=Retry*10
@ IN NS lance.uc-knight.top.
lance.uc-knight.top. IN A 120.79.254.2
@ IN MX 5 www.uc-knight.top.
www.uc-knight.top. IN A 120.79.254.2
5.配置 /var/named/254.79.120.zone 檔案
vim /var/named/254.79.120.zone
$ttl 600
@ IN SOA lance.uc-knight.top. lance.www.uc-knight.top.(
2018060601 10800 3600 604800 38400 )
; Serial Refresh Retry Expire MinumumTTL
; Serial<2^32 Refresh>=Retry*2 Refresh+Retry<Expire
; Expire>=Retry*10
@ IN NS lance.uc-knight.top.
2 IN PTR lance.uc-knight.top.
6.啟動named服務,并設為開機自啟
systemctl start named
systemctl enable named
*7.DNS用戶端配置(注意不是伺服器端)
Linux: yum install bind-utils -y 然後編輯 vim /etc/resolv.conf
本例中為 nameserver 120.79.254.2
Windows: 本地連接配接/網絡擴充卡-ipv4協定-手動配置輸入dns位址
本例中為 使用下面的DNS伺服器位址- 120.79.254.2
**額外小内容:web伺服器配置(基于完成以上DNS配置步驟)
a.安裝web伺服器軟體包
yum install httpd -y
yum install httpd-tools -y
yum install http-manual -y
b.修改/etc/httpd/conf/httpd.conf 檔案
vim /etc/httpd/conf/httpd.conf
修改以下内容
ServerAdmin [email protected]
ServerName www.uc-knight.top
c.将網頁儲存到/var/www/html目錄中
本例使用echo指令生成index.html檔案
echo "Welcome to uc-knight.top! " >/var/www/html/index.html
d.啟動httpd服務,設為開機自啟
systemctl start httpd
systemctl enable httpd
8.安裝Sendmail伺服器軟體包(sendmail, sendmail-cf, procmail, m4)
yum install sendmail -y
yum install sendmail-cf -y
9.驗證郵件交換器設定(通過配置好DNS的用戶端,即完成了執行第7點的用戶端)
nslookup -q=mx uc-knight.top
輸出為:
Server: 120.79.254.2
Address: 120.79.254.2#53
uc-knight.top mail exchanger = 5 www.uc-knight.top.
10.配置 /etc/mail/sendmail.mc 檔案
vim /etc/mail/sendmail.mc
修改:
dnl # DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl
LOCAL_DOMAIN(`uc-knight.top')dnl
11.使用m4進行重定向/etc/mail/sendmail.cf
m4 /etc/mail/sendmail.mc >/etc/mail/sendmail.cf
12.vim /etc/mail/local-host-names
增加:
uc-knight.top <--域
www.uc-knight.top <--郵件主機名
13.vim /etc/hosts
增加:
120.79.254.2 lance www.uc-knight.top
伺服器ip位址;主機名;郵箱主機名
**.修改主機名(靜态 瞬态 靈活主機名同時修改)
hostnamectl set-hostname <hostname>
**查詢主機名 hostname -f
或 vim /etc/hostname
*14.vim /etc/mail/access
120.79.254 RELAY
uc-knight.top RELAY
修改後重定向:
makemap hash /etc/mail/access.db </etc/mail/access
*15.編輯/etc/aliases檔案
編輯後使用newaliases生成/etc/aliases.db資料庫
16.運作sendmail服務,設定開機自啟
systemctl start sendmail
systemctl enable sendmail
*可使用 systemctl status sendmail 檢視是否已啟動
*可使用 systemctl status sendmail -l 檢視服務具體啟動情況
*可使用 systemctl is-enabled sendmail 查詢是否已設定為開機啟動
17.安裝dovecot軟體包
yum install dovecot -y
18.vim /etc/dovecot/dovecot.conf
修改:
protocols = imap pop3 lmtp
listen = *
base_dir = /var/run/dovecot/
19.運作dovecot服務,設為開機自啟
systemctl start dovecot
systemctl enable dovecot
開始測試 在配置好dns的用戶端上 遠端登陸pop3端口110
*SMTP 端口 TCP 25
*POP3 端口 TCP 110
*IMAP 端口 TCP 143
telnet 120.79.254.2 110
user test
pass test
(使用者自己在系統中添加)
問題一:輸入user test 回車後出現
-ERR [AUTH] Plaintext authentication disallowed on non-secure (SSL/TLS) connections.
解決:
vim /etc/dovecot/conf.d/10-auth.conf
修改
disable_plaintext_auth = no
vim /etc/dovecot/conf.d/10-ssl.conf
修改
ssl = no
重新開機dovecot服務
systemctl restart dovecot
問題二:修改問題一後,輸入pass test,出現
-ERR [SYS/TEMP] Internal error occurred. Refer to server log for more information.
Connection closed by foreign host.
使用指令檢視log
tail /var/log/maillog
Jun 6 23:43:29 iz6yiqbo5vklydz dovecot: pop3(test): Error: user test: Initialization failed: Namespace '': Mail storage autodetection failed with home=/home/test
Jun 6 23:43:29 iz6yiqbo5vklydz dovecot: pop3(test): Error: Invalid user settings. Refer to server log for more information.
解決: vim /etc/dovecot/conf.d/10-mail.conf
設定mail_location參數
mail_location = mbox:~/mail:INBOX=/var/mail/%u
問題三:接着修改完問題二後,繼續登入,出現
-ERR [SYS/PERM] Permission denied
Connection closed by foreign host.
檢視日志 tail /var/log/maillog
Error: chown(/home/test/mail/.imap, group=12(mail)) failed: Operation not permitted (egid=1002(test), group based on /var/mail/test - see http://wiki2.dovecot.org/Errors/ChgrpNoPerm)
Jun 6 23:51:12 iz6yiqbo5vklydz dovecot: pop3(test): Error: Couldn't open INBOX: Permission denied
Jun 6 23:51:12 iz6yiqbo5vklydz dovecot: pop3(test): Couldn't open INBOX top=0/0, retr=0/0, del=0/0, size=0
解決方案
更改權限 chmod 0600 /var/mail/* (或者權限改為777等)
本例中為test使用者 故指令為 chmod 0600 /var/mail/test
**使用指令檢視日志檔案
cat /var/log/maillog
tail /var/log/maillog
**不要用root使用者遠端登入郵箱伺服器
WINDOWS用戶端登入示例(需要先配置DNS)
1.FOXMAIL
或者 直接輸入郵件伺服器IP位址 則不需要配置DNS
2.THUNDERBIRD
參考自:http://linux.vbird.org/linux_server/0350dns.php (DNS相關知識和設定)
https://wenku.baidu.com/view/09ada240a32d7375a5178006.html (配置dovecot常見錯誤問題 問題一二解決方案)
https://wiki2.dovecot.org/Errors/ChgrpNoPerm?spm=5176.10173289.0.0.70742e77HdSTBU(問題三解決方案)