Ubuntu 18.04配置郵箱服務器(局域網)



一、安裝
  Ubuntu 18.04附帶了systemd-resolve,需要禁用它,因為它綁定到53端口,與Dnsmasq端口沖突。
  運行以下命令以禁用已解析的服務:

root@base:$ systemctl disable systemd-resolved
root@base:$ systemctl stop systemd-resolved

  刪除符號鏈接resolv.conf文件

root@base:$ ls -lh /etc/resolv.conf

  53端口占用:

root@base:$ lsof -i:53
root@base:$ kill -9 pid

  安裝:

root@base:$ apt-get install dovecot-common dovecot-imapd dovecot-pop3d
root@base:$ apt-get install postfix
root@base:$ apt-get install dnsmasq

  對應服務:
  Postfix------Smtp(發送郵件)
  Dovecot------POP3/IMAP(接收郵件)
  Dnsmasq------nameserver(域名服務器)

 

二、配置hostname

root@base:$ vim /etc/hostname

  更改為:
  mail.coodyz.com
  重啟后生效:

root@base:$ reboot

 

三、配置dnsmasq
 在hosts文件中增加 本地IP到域名映射

root@mail:$ vim /etc/hosts
192.168.254.128 mail.coodyz.com # `192.168.254.128`更改為Ubuntu本機局域網IP

 啟動服務:

root@mail:$ /etc/init.d/dnsmasq start

  將服務器的DNS服務器指向Dnsmasq服務器:

root@mail:$ vim /etc/resolv.conf
nameserver 127.0.0.1
nameserver 8.8.8.8

  以上只是修改運行時文件,進行持久配置需編輯/etc/network/interfaces

  測試:

root@mail:$ dig A mail.coodyz.com
; <<>> DiG 9.11.3-1ubuntu1.11-Ubuntu <<>> A mail.coodyz.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 47993
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;mail.coodyz.com.    IN    A

;; ANSWER SECTION:
mail.coodyz.com.    0    IN    A    192.168.254.128

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Fri Dec 20 16:42:17 CST 2019
;; MSG SIZE rcvd: 60

 

四、配置postfix

root@mail:$ vim /etc/postfix/main.cf

  參考配置:

home_mailbox = Maildir/

smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

readme_directory = no

# See http://www.postfix.org/COMPATIBILITY_README.html -- default to 2 on
compatibility_level = 2

# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = mail.coodyz.com
mydomain = coodyz.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = $mydomain
mydestination = $myhostname, coodyz.com, mail.coodyz.com, localhost.coodyz.com, localhost
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = ipv4

smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks, reject_unauth_destination
broken_sasl_auth_clients = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth

  啟動服務:

root@mail:$ /etc/init.d/postfix start


五、配置dovecot
  編輯Dovecot主配置文件:

root@mail:# vim /etc/dovecot/dovecot.conf

  取消注釋並配置

listen = *
protocols = pop3 imap
mail_location = maildir:/home/%u/Maildir
pop3_uidl_format = %08Xu%08Xv
disable_plaintext_auth = no

  指定電子郵件客戶端向Dovecot進行身份驗證的方式:

root@mail:# vim /etc/dovecot/conf.d/10-auth.conf
auth_mechanisms = plain login

  指定用於存儲電子郵件的文件夾:

root@mail:# vim /etc/dovecot/conf.d/10-mail.conf
mail_location = maildir:/home/%u/Maildir

  編輯Postfix SMTP身份驗證配置文件:

root@mail:$ vim /etc/dovecot/conf.d/10-master.conf

  注釋文件中的以下幾行

#unix_listener auth-userdb {
#mode = 0600
#user =
#group =
#}

  並確保未注釋以下內容:

# Postfix smtp-auth
unix_listener /var/spool/postfix/private/auth {
mode = 0666
user = postfix
group = postfix
}

  編輯POP3配置文件,並允許一些較舊的電子郵件客戶端正確連接和傳輸::

root@mail:$ vim /etc/dovecot/conf.d/20-pop3.conf
pop3_uidl_format = %08Xu%08Xv
pop3_client_workarounds = outlook-no-nuls oe-ns-eoh

  為了使Dovecot服務與Postfix服務一起使用,我們需要在Postfix配置文件中添加以下幾行:

root@mail:$ vim /etc/postfix/main.cf
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks, reject_unauth_destination
broken_sasl_auth_clients = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth

  重啟服務:

root@mail:$ /etc/init.d/postfix restart
root@mail:$ /etc/init.d/dovecot restart

  測試服務功能:

root@mail:$ telnet localhost 143
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
* OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE STARTTLS 
AUTH=PLAIN AUTH=LOGIN] Dovecot (Ubuntu) ready.
root@mail:$ telnet localhost 110

  服務器啟動時自啟

root@mail:$ update-rc.d dovecot defaults

  建立郵箱賬戶:

root@mail:$ adduser ted
Enter new UNIX password: ted
Retype new UNIX password: ted
passwd: password updated successfully
Changing the user information for test
Enter the new value, or press ENTER for the default
Full Name []: 
Room Number []: 
Work Phone []: 
Home Phone []: 
Other []: 
Is the information correct? [Y/n] Y

  重啟服務:

root@mail:$ /etc/init.d/dovecot restart

六、使用測試
 注意:請確保兩者在同一網段
 郵件服務器IP 192.168.254.128
 Windows XP 客戶端IP 192.168.254.130

 使用outlook測試:
 工具->賬戶->添加

 

 

 

 

 

 

 

 

 

在Ubuntu端查看:

ted@mail:~$ cd ~/Maildir/new/
ted@mail:~/Maildir/new$ ls
1576825940.V801I10053cM500622.mail.coodyz.com
1576826245.V801I100544M69814.mail.coodyz.com
1576826459.V801I10054bM4159.mail.coodyz.com
1576833962.V801I10055bM300307.mail.coodyz.com
ted@mail:~/Maildir/new$ vim 1576833962.V801I10055bM300307.mail.coodyz.com

 

參考鏈接https://www.linuxidc.com/Linux/2017-03/141392.htm

     https://computingforgeeks.com/install-and-configure-dnsmasq-on-ubuntu-18-04-lts/

     https://kyup.com/tutorials/install-dovecot/

     https://tecadmin.net/install-dovecot-on-ubuntu/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM