1. 程式人生 > >基於CentOS搭建SMTP伺服器

基於CentOS搭建SMTP伺服器

1環境

[[email protected]]# uname –a


[[email protected]]# cat /etc/issue


2安裝posfix

檢視posfix的版本

[[email protected]]# postconf mail_version

一般是預設就安裝了posfix的,如果沒有暗轉的話,是用yum -yinstall postfix安裝

[[email protected]]# yum -y install postfix


3更改預設郵件傳輸代理(MTA)

檢視預設的mta

[[email protected]]# alternatives --display mta

我們可以看到預設的mta就是postfix,也許是sendmail,如果不是postfix,則修改為postfix

[[email protected]]# alternatives --config mta

There is1 program that provides 'mta'.

  Selection   Command

-----------------------------------------------

*+1           /usr/sbin/sendmail.postfix

Enter to keepthe current selection[+], or type selection number: 1

4配置postfix

Postfix的配置檔案主要有:/etc/postfix/main.cf和/etc/postfix/master.cf

我們主要修改/etc/postfix/main.cf

[[email protected] postfix]# vim /etc/postfix/main.cf

將#myhostname =virtual.domain.tld前面的‘#’去掉,改為

myhostname = localhost //系統的主機名稱

將#mydomain = domain.tld前面的‘#’去掉,改為

mydomain = 51cs8.com //email的地址,為可用的域名

將#myorigin = $mydomain前面的‘#’去掉,改為

myorigin = $mydomain //指定本地傳送郵件中來源和傳遞顯示的域名

將#inet_interfaces =localhost前的‘#’去掉,改為

inet_interfaces = all //設定網路介面以便Postfix能接收到郵件

將#mydestination =$myhostname, localhost.$mydomain, localhost前面的‘#’去掉,改為

mydestination = $myhostname, localhost.$mydomain, localhost,$mydomain //指定哪些郵件地址允許在本地傳送郵件

將#local_recipient_maps = 前面的‘#’去掉,改為

local_recipient_maps =

將#mynetworks =168.100.189.0/28, 127.0.0.0/8前面的‘#’去掉,改為

mynetworks = 10.47.200.0/21, 127.0.0.0/8 //根據自己內網的實際情況寫,指定受信任SMTP的列表,具體的說,受信任的SMTP客戶端允許通過Postfix傳遞郵件

將#home_mailbox = Maildir前面的‘#’去掉,改為

home_mailbox = Maildir/ //設定郵箱路徑與使用者目錄有關,也可以指定要使用的郵箱風格。

將#smtpd_banner = $myhostnameESMTP $mail_name ($mail_version)前面的‘#’去掉,改為

smtpd_banner = $myhostname ESMTP unknow //不顯示SMTP伺服器的相關資訊

在配置檔案的最後追加如下內容:

#smtpd

smtpd_sasl_auth_enable = yes //使用smtp認證

broken_sasl_auth_clients = yes //讓不支援RFC2554smtpclient也可以跟postfix做互動。

smtpd_sasl_local_domain = $myhostname //指定SMTP認證的本地域名

smtpd_sasl_security_options = noanonymous //取消匿名登陸方式

smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated, reject_unauth_destination //設定郵件中有關收件人部分的限制

5安裝cyrus-sasl、cyrus-imapd相關包

[[email protected] ~]#yum -y install cyrus*

因為我之前安裝過,所提提示已經安裝。

6配置cyrus-sasl

Cyrus-sasl的配置檔案路徑:/etc/sasl2/smtpd.conf

[[email protected] postfix]# vim /etc/sasl2/smtpd.conf

在檔案尾部追加

log_level: 3 //記錄log的模式

saslauthd_path:/var/run/saslauthd/mux //設定一下smtp尋找cyrus-sasl的路徑

下面是我/etc/sasl2/smtpd.conf的內容:

pwcheck_method: saslauthd

mech_list: plain login

log_level: 3

saslauthd_path: /var/run/saslauthd/mux

7啟動postfix、cyrus-sasl、cyrus-imapd

[[email protected] postfix]# /etc/init.d/postfix restart

Shutting down postfix:                                     [  OK  ]

Starting postfix:                                          [ OK  ]

[[email protected] postfix]# /etc/init.d/saslauthd restart

Stopping saslauthd:                                        [  OK  ]

Starting saslauthd:                                        [  OK  ]

[[email protected] postfix]# /etc/init.d/cyrus-imapd restart

Shutting down cyrus-imapd:                                 [  OK  ]

Exporting cyrus-imapd databases:                           [  OK  ]

Importing cyrus-imapd databases:                           [  OK  ]

Starting cyrus-imapd:                                      [  OK  ]

檢視smtp啟動情況:

[[email protected] postfix]# netstat -tpnl | grep 25

tcp       0      0 0.0.0.0:25                  0.0.0.0:*                   LISTEN      1714/master

檢視imap啟動情況:

[[email protected] postfix]# netstat -tpnl | grep cyrus

tcp       0      0 0.0.0.0:110                0.0.0.0:*                  LISTEN      2687/cyrus-master  

tcp       0      0 0.0.0.0:143                0.0.0.0:*                  LISTEN      2687/cyrus-master  

tcp       0      0 0.0.0.0:4190                0.0.0.0:*                   LISTEN      2687/cyrus-master  

tcp       0      0 0.0.0.0:993                 0.0.0.0:*                   LISTEN      2687/cyrus-master  

tcp       0      0 0.0.0.0:995                 0.0.0.0:*                   LISTEN      2687/cyrus-master

8設定postfix、cyrus-sasl、cyrus-imapd開機自啟動

[[email protected] postfix]# chkconfig postfix on

[[email protected] postfix]# chkconfigpostfix --list

postfix              0:off 1:off 2:on 3:on 4:on 5:on 6:off

[[email protected] postfix]# chkconfig saslauthd on

[[email protected] postfix]# chkconfigsaslauthd --list

saslauthd           0:off 1:off 2:on 3:on 4:on 5:on 6:off

[[email protected] postfix]# chkconfig cyrus-imapd on

[[email protected] postfix]# chkconfig cyrus-imapd--list

cyrus-imapd         0:off 1:off 2:on 3:on 4:on 5:on 6:off

9測試cyrus-sasl

新增賬號、密碼 system | system

[[email protected] postfix]# useradd system

[[email protected] postfix]# passwd system

Changing password for user system.

New password:

BAD PASSWORD: it is based on a dictionaryword

BAD PASSWORD: is too simple

Retype new password:

passwd: all authentication tokens updatedsuccessfully.

測試是否可用

 [[email protected]]# testsaslauthd -u system -p system

0: OK "Success."

10測試cyrus-imapd

安裝完cysus-imapd會自動產生一個管理賬號cyrus,所屬使用者組是mail

[[email protected] tank]# id cyrus

uid=76(cyrus) gid=12(mail)groups=12(mail),76(saslauth)

將賬戶system的所在組切換到mail組

[[email protected] tank]# usermod -g 12 system

[[email protected]8whZ tank]# id system

uid=502(system) gid=12(mail)groups=12(mail)

新增測試賬號:

[[email protected]]# cyradm -u cyrus localhost --auth plain

相關推薦

基於CentOS搭建SMTP伺服器

1環境 [[email protected]]# uname –a [[email protected]]# cat /etc/issue 2安裝posfix 檢視posfix的版本 [[email protected]]# postcon

CentOS 7下基於Docker搭建GitLab伺服器

作業系統:CentOS 7.2核心版本:3.10.0-693.21.1.el7.x86_64為了使以後的維護更方便,在備份和遷移Git時,不需要重新搭建環境,使用Docker來構建Git服務,將Git下的資料掛在Docker的宿主機,日後只需要要拷貝Docker映象和掛在的資

基於 CentOS 搭建 WordPress 個人博客

setting his using values eas centos chang init ogg   示例代碼:/etc/wordpress/wp-config.php <?php/** * The base configuration for WordPr

基於 CentOS 搭建 FTP 文件服務

str 上傳文件 需要 local href 規則 iptables AD RM 在萬網服務器搭建的時候,會出現無法連接超時的現象,是因為沒有打開21端口,需要在在萬網的安全組,安全組規則,打開21端口, 就可以順利連接了 本文測試環境 1、CentOS 7 2、

阿里雲CentOS搭建SVN伺服器及許可權管理

  linux(centos)下SVN伺服器如何搭建?說到SVN伺服器,想必大家都知道,可以是在LINUX下如何搭建SVN伺服器呢?那麼今天給大家分享一下linux(centos)搭建SVN伺服器的思路!    雖然在windows上搭建SVN很簡單,但是效能卻不高,

基於CentOS搭建WordPress(筆記)

準備 LNMP 環境 LNMP 是 Linux、Nginx、MySQL 和 PHP 的縮寫,是WordPress 部落格系統依賴的基礎執行環境。我們先來準備 LNMP 環境 安裝 Nginx 使用 yum 安裝 Nginx: yum install nginx -y 修改 /etc/n

centos 搭建 svn伺服器 [防錯篇]

1.先把源換成epel源 centos# yum install epel-release centos# cd /etc/yum.repos.d centos# wget -O /etc/yum.repos.d/epel.repo http://mirror

CentOS搭建KMS伺服器

安裝 使用命令: #CentOS,Redhat,Fedora等請選擇CentOS指令碼 wget https://raw.githubusercontent.com/dakkidaze/one-key-kms/master/one-key-kms-centos.sh chmod +x one-key-km

CentOS搭建FTP伺服器(轉)

https://www.linuxidc.com/Linux/2017-11/148518.htm   本文測試環境  1、CentOS 7  2、測試伺服器IP 192.168.1.170 1、安裝並啟動 FTP 服務 1.1 安裝 VSFT

基於docker搭建oracle伺服器

拉取映象 docker pull wnameless/oracle-xe-11g 這個比較耗時,中間可能會中斷,繼續拉取即可 啟動例項 注意將selinux關掉,不然例項啟動失敗 修改/etc/selinux/config檔案,設定為disable # dis

CentOS搭建SVN伺服器,並通過Apache HTTP方式訪問(轉載至上品物語)

摘要:本文主要講述了在centos 6.5環境下搭建svn伺服器,可通過svn:\\IP方式訪問。同時由於部分公司內網埠限制,並不能訪問外網的svn伺服器,所以特地結合了apache伺服器,使得可以通過http方式http://IP方式訪問svn伺服器。 環境準備:

CentOS搭建tftp伺服器

CentOS7搭建tftp伺服器 安裝必要元件 安裝xinetd,tftp和tftp-server 配置tftp引數 修改目錄許可權 防火牆設定 防火牆放行tftp服務,預設埠為69,採用udp協議 啟動相關服務 安裝完之後會啟動,但是修改了配置之後需要

搭建Git CentOS搭建Git伺服器及許可權管理

CentOS搭建Git伺服器及許可權管理   宣告:本教程,僅作為配置的記錄,細節不展開,需要您有一點linux的命令基礎,僅作為配置參考。 1. 系統環境 系統: Linux:CentOS 7.2 64位 由於CentOS已經內建了OpenSSH,如果您的

CentOS 搭建 Git伺服器

GitHub是一個免費託管開原始碼的遠端倉庫,但是有時候我們既不想公開原始碼,又不想給GitHub交保護費。如果這時候我們有一臺自己的伺服器,那我們就可以把這個伺服器搭建成一臺Git伺服器作為私有倉庫使

基於Spring搭建檔案伺服器

檔案伺服器的搭建架構有很多種,如基於nginx+vsftp、nginx+fastDFS等架構,其中vsftp或fastDFS用於檔案讀寫、上傳儲存、下載,nginx用於對映檔案 ,方便http訪問靜態檔案,實現線上預覽圖片或下載等功能。這種架構使用起來很方便,

基於 CentOS 搭建 FTP 檔案服務

安裝並啟動 FTP 服務 任務時間:5min ~ 10min 安裝 VSFTPD 使用 yum 安裝 [vsftpd]: yum install vsftpd -y vsftpd 是在 Linux 上被廣泛使用的 FTP 伺服器,根據其官網介紹,它可

[原始碼和文件分享]基於MFC的SMTP伺服器

一、實驗目的及任務 編寫一個簡單的SMTP伺服器,要求實現的功能如下所示: 實現的伺服器應能與outlook express等現有的客戶端進行簡單的互動 記錄瀏覽器與服務的互動過程 在螢幕上直接顯示接收到的郵件內容 將郵件附件中的影象(如bmp或jpg影

centos搭建MQTT伺服器Mosquitto

1.安裝工具 yum install gcc gcc-c++ yum install openssl-devel yum install c-ares-devel yum install libuuid-devel yum install wget yum ins

CentOS搭建Git伺服器及許可權管理

宣告:本教程,僅作為配置的記錄,細節不展開,需要您有一點linux的命令基礎,僅作為配置參考。 1. 系統環境 系統: Linux:CentOS 7.2 64位 由於CentOS已經內建了OpenSSH,如果您的系統沒有,請自行安裝。 檢視ssh版本 $ ssh

centos搭建svn伺服器以及hdwiki

SVN:直接參考百度經驗 注意以下兩點: 百度經驗中提到的vi authz中一定記得要加上:[/] 以及使用者的許可權 我伺服器重啟發現訪問不了一直在waiting for initialing