1. 程式人生 > 其它 >linux搭建內網郵件伺服器

linux搭建內網郵件伺服器

一、配置發件伺服器

1.1 根據現場IP,配置主機名

vi /etc/hosts
192.168.40.133 mail.test.com

將主機名更改為郵件伺服器域名mail.test.com

1.2 關閉防火牆,禁止開機啟動

systemctl stop firewalld
systemctl disable firewalld

1.3 關閉selinux

vi /etc/selinux/config

將未註釋的SELINUX值改為disabled

1.4 安裝/配置postfix伺服器

(1)檢查系統是否已經安裝了postfix伺服器

rpm -q postfix

(2) 如果沒有就安裝,安裝了就跳過

 yum -y install postfix

(3) 編輯postfix的配置檔案,查詢並修改對應配置項

vi /etc/postfix/main.cf

在檔案最後新增如下內容

myhostname = mail.test.com                 
mydomain = test.com                        
myorigin = $mydomain                      
inet_interfaces = all                         
inet_protocols = all                         
mydestination = $myhostname, $mydomain    
home_mailbox = Maildir/                    
mynetworks = 0.0.0.0,127.0.0.0/8,60.60.60.0/24  // 網路許可權(根據現場IP配置,貼上進去的時候去掉//後面的所有內容)

(4) 檢查配置檔案是否有語法錯誤

postfix check

(5) 重新啟動postfix伺服器

systemctl restart postfix

1.5 發件測試

(1) 新增郵件賬號組

 groupadd mailusers

(2)新增郵箱賬號

 useradd -g mailusers -s /sbin/nologin dkycs
passwd dkycs
useradd -g mailusers -s /sbin/nologin dfc
passwd dfc

(3) 安裝遠端登入外掛

 yum install -y telnet

(4) 遠端登入25埠,如報錯連線不上,重啟postfix

 telnet mail.test.com 25

(確認現場25埠是否開放)

(5)測試郵件傳送

[root@localhost new]# telnet mail.test.com 25  //
Trying 192.168.40.133...
Connected to mail.test.com.
Escape character is '^]'.
220 mail.test.com ESMTP Postfix
#顯示上面 表示telnet連線成功

mail from:<[email protected]>
#郵件傳送者

250 2.1.0 Ok
rcpt to:[email protected]
#郵件接收者

250 2.1.5 Ok
data

#data加回車開始編寫郵件
354 End data with <CR><LF>.<CR><LF>
Subject:test mail
#郵件主題

hello serva 3D_city_wprl^H
hello serva 3FD
hello 3D!thanks!
#郵件內容

.
#.表示編寫結束 傳送郵件

250 2.0.0 Ok: queued as 21C5340F1992
#傳送成功

quit
#退出telnet



221 2.0.0 Bye
Connection closed by foreign host.

如果報錯就修改下列檔案:

vi /etc/postfix/main.cf
mynetworks = all
systemctl restart postfix

(6)接收檢視郵件內容

cd /home/收件人/Maildir/new目錄下,所有新收的郵件都在這個下面:

二、配置收件伺服器

2.1 安裝dovecot

yum -y install dovecot

安裝完,檢視版本:

dovecot --version

2.2 修改配置檔案

(1)執行vi /etc/dovecot/dovecot.conf

修改如下:

protocols = imap pop3
listen = *, ::
login_trusted_networks = 0.0.0.0,127.0.0.0/8,60.60.60.0/24   (根據現場配置填寫)
!include conf.d/*.conf
!include_try local.conf

(2)執行vi /etc/dovecot/conf.d/10-ssl.conf

修改如下:

ssl = no

(3)執行vi /etc/dovecot/conf.d/10-auth.conf

修改如下:

disable_plaintext_auth = no
auth_mechanisms = plain login
!include auth-system.conf.ext

(4)執行vi /etc/dovecot/conf.d/10-logging.conf

修改如下:

info_log_path = /var/log/dovecot_info.log
debug_log_path = /var/log/dovecot_debug.log

(5)執行vi /etc/dovecot/conf.d/10-mail.conf

修改如下:

mail_location = maildir:~/Maildir

2.3 啟動服務

systemctl start dovecot
systemctl enable dovecot

2.3 檢視服務狀態

systemctl status dovecot

檢視埠:

yum -y install net-tools
netstat -tlnp |grep dovecot

三、配置DNS

安裝:

yum install rng-tools -y
service rngd start

安裝/配置:

yum install bind-utils -y
yum install dnsmasq -y

vi /etc/hosts 新增 127.0.0.1 test.com

vi /etc/dnsmasq.conf

新增 address=/test.com/127.0.0.1, 新增 listen-address=127.0.0.1,192.168.40.133(本機ip)

service dnsmasq start

測試 nslookup

test.com

Server: 127.0.0.1

Address: 127.0.0.1#53

Name: test.com

Address: 60.60.60.42

Name: test.com

Address: 127.0.0.1

四、配置Foxmail客戶端

Foxmail官方下載地址:http://fox.foxmail.com.cn/

賬號配置: