標籤:stmp服務補錄
[STMP補錄]
一.
1)【禁止指定ip遠程對我的STMP操作】
cd /etc/postfix/
vim access [在最後一行做如下添加]
172.25.254.60 REJECT
postmap access [重新整理檔案]【這時,該目錄下會多處一個access.db檔案】【postconf -d | grep client,可以查看參數】
650) this.width=650;" src="http://s2.51cto.com/wyfs02/M00/8B/40/wKioL1hILyWRpYLfAABRbRiQTjg046.png" title="1.png" alt="wKioL1hILyWRpYLfAABRbRiQTjg046.png" />postconf -e "smtpd_client_restrictions = check_client_access hash:/etc/postfix/access"【在/etc/postfix下的
mian.cf(主設定檔)中最後加入檢索access檔案的參數指令】
systemctl restart postfix [重啟]
【測試】用172.25.254.60 發送郵件,mail from:[email protected] rcpt to:[email protected] ;出現"554 5.7.1 <unknown[172.25.254.60]>: Client hostrejected: Access denied(沒有許可權)"表示成功。
【撤銷禁止,刪除access檔案加入的東西,重新整理檔案,重啟服務】
2)【禁止指定ip遠程對指定使用者的STMP發送操作】
vim sender [在/etc/postfix/下建立該目錄]
[email protected] REJECT
postconf -e "smtpd_sender_restrictions = check_sender_accesshash:/etc/postfix/sender" 【在/etc/postfix下的
mian.cf(主設定檔)中最後加入檢索sender檔案的參數指令】
systemctl restart postfix [重啟]
【測試】 在telnet中,發送方用student發送,出現報錯為“Sender address rejected: Access denied”
650) this.width=650;" src="http://s2.51cto.com/wyfs02/M02/8B/40/wKioL1hIL1XxRrm1AABSkTQLWHY711.png" style="float:none;" title="2.png" alt="wKioL1hIL1XxRrm1AABSkTQLWHY711.png" />
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/8B/40/wKioL1hIL1XiWM64AAAkRZ_Z4zQ633.png" style="float:none;" title="3.png" alt="wKioL1hIL1XiWM64AAAkRZ_Z4zQ633.png" />
3)【禁止指定ip遠程對指定使用者的STMP收件操作】
vim recip
[email protected] REJECT
postmap recip
postconf -e "smtpd_recipient_restrictions = check_recipient_accesshash:/etc/postfix/recip"
systemctl restart postfix
【測試】
<[email protected]>: Recipient address rejected: Access denied [正常]
二.
1.)【Dovecot郵件伺服器,對這些郵件連接埠提供服務,imap143,pop3 110,imaps 993和pop3s 995。可以 cat /etc/services | grep imap/pop 查看】
yum install dovecot -y
vim /etc/dovecot/dovecot.conf [修改設定檔]
24 protocols = imap pop3 lmtp [允許服務的介面]
49 disable_plaintext_auth = no [允許純文字密碼驗證]
vim /etc/dovecot/conf.d/10-mail.conf
22 mail_location =mbox:~/mail:INBOX=/var/mail/%u
netstat -antlpe | grep dovecot [查看 993,995,110,143連接埠是否開啟]
yum install mutt -y [下載一個email程式]【此操作在另一個主機做的,看能不能接收到安裝了Dovecot服務機子的郵件】
mutt -f pop3://[email protected] [進入操作a]【在此項操作中,應先在stdent目錄中建立幾個檔案】
【詳細檔案建立操作】
(1) mkdir /home/student/mail/.imap/ -p
(2) touch /home/student/mail/.imap/INBOX
【在建立使用者的時候,使用者的家目錄檔案預設是拷貝root下的/etc/skel/,如果你需要很多使用者下都有這些檔案,就在這裡寫進去,一勞永逸。】
[完成,現在執行 mutt 則可以看到student受到的郵件]
650) this.width=650;" src="http://s2.51cto.com/wyfs02/M00/8B/43/wKiom1hIL6uTP8WkAADrmf8QTts555.png" style="float:none;" title="5.png" alt="wKiom1hIL6uTP8WkAADrmf8QTts555.png" />
650) this.width=650;" src="http://s2.51cto.com/wyfs02/M00/8B/40/wKioL1hIL6zCnLNfAADq6gRg5UM409.png" style="float:none;" title="6.png" alt="wKioL1hIL6zCnLNfAADq6gRg5UM409.png" />
650) this.width=650;" src="http://s4.51cto.com/wyfs02/M02/8B/40/wKioL1hIL6zBl-fpAAENn1RQgGA664.png" style="float:none;" title="7.png" alt="wKioL1hIL6zBl-fpAAENn1RQgGA664.png" />
650) this.width=650;" src="http://s4.51cto.com/wyfs02/M01/8B/43/wKiom1hIL63B78DMAAC1ArOhABg888.png" style="float:none;" title="8.png" alt="wKiom1hIL63B78DMAAC1ArOhABg888.png" />
650) this.width=650;" src="http://s4.51cto.com/wyfs02/M00/8B/43/wKiom1hIL62R2JlYAAA3Ympn_m8850.png" style="float:none;" title="9.png" alt="wKiom1hIL62R2JlYAAA3Ympn_m8850.png" />
650) this.width=650;" src="http://s4.51cto.com/wyfs02/M01/8B/40/wKioL1hIL63Dc8MEAACgs0NKoYA624.png" style="float:none;" title="10.png" alt="wKioL1hIL63Dc8MEAACgs0NKoYA624.png" />
2.)【使用電子郵件應用程式,實現遠程收發郵件】
【前置:在區別於以上兩個的主機上下載安裝好thunderbird-31.4.0.tar.bz2,這是一個可用目錄,tar jxf ~解壓後,在 thunderbird/目錄下,./thunderbird執行,按照提示,依次查詢安裝包(yumwhatProvides ~)並安裝,這個有十多個,慢慢安裝,安裝好,就有了一個圖形介面工具
vim /etc/dovecot/dovecot.conf [修改設定檔]
48 login_trusted_networks= 0.0.0.0/0 [允許接受的ip段的郵件]
【配置圖形介面的使用者添加】;
因為是本機使用者,大名就為本機使用者名:student ; 電子郵件 [email protected];
收件:IMAP 172.25.254.161;連接埠:143;SSL:無;認證:普通密碼;
寄件:SMTP 172.25.254.161;連接埠:25;SSL:無;認證:普通密碼;
使用者名稱:student
[重新測定,確認;現在就可以受到了]
3.*)【使用資料庫,建立虛擬使用者,指定所有使用者的收件地址為/home/vmail/,實現郵件的收發】
【前置:yum install mariadb-server -y;yum install httpd;tarjxf phpMyAdmin-~.tar.bz2,修改名稱為 myadmin,放在/var/www/html/下,進入該目錄下,cp config.sample.inc.php config.inc.php,vim 該檔案,加入一個COOKIE任意值;初始資料庫資訊(mysql_secure_installation);在/etc/hosts 中添加 郵件首發的ip以及對應的網域名稱】
1.在資料庫中建立資訊表
在圖形應用中建立資料庫:email,資料結構項:username,password,domain,maildir。類型都為:varchar,長度:50 50 50 100;
建立表:muser表。(例子)username:[email protected];password:123;domain:hxl.org;mkdir:/hxl.org/admin/
2.在資料庫中建立一個使用者(字元介面),並授權
CREATE USER [email protected] by ‘postfix‘;
GRANT INSERT,UPDATE,SELECT on email.*to [email protected];
3.填寫關於篩選資訊的設定檔(cd /etc/pistfix/)
* vim mysql-users.cf
1.host = localhost
2.user = postfix
3.password = postfix
4.dbname = email
5.table = muser
6.select_field = username
7.where_field = username
[測試]
postmap -q "[email protected]"mysql:/etc/postfix/mysql-users.cf
[email protected]
* vim mysql-domain.cf
1.host = localhost
2.user = postfix
3.password = postfix
4.dbname = email
5.table = muser
6.select_field = domain
7.where_field = domain
[測試]
postmap -q "hxl.org"mysql:/etc/postfix/mysql-domain.cf
hxl.org,hxl.org
* vim mysql-maildir.cf
1.host = localhost
2.user = postfix
3.password = postfix
4.dbname = email
5.table = muser
6.select_field = maildir
7.where_field = username
[測試]
postmap -q "[email protected]"mysql:/etc/postfix/mysql-maildir.cf
hxl.org/admin/
4.項主設定檔中添加虛擬使用者,以及上述資訊
建立本機使用者vmail,指定uip 888,gip 888,並且是非互動模式
groupadd -g 888 vmail
useradd -g 888 -u 888 -s/sbin/nologin vmail
[向主設定檔(/etc/postfix/main.cf)添加資訊]
postconf -e "virtual_gid_maps =static:888"
postconf -e "virtual_uid_maps =static:888"
postconf -e "virtual_mailbox_base= /home/vmail"
postconf -e "virtual_alias_maps =mysql:/etc/postfix/mysql-users.cf"
postconf -e "virtual_alias_maps =mysql:/etc/postfix/mysql-domain.cf"
postconf -e "virtual_alias_maps =mysql:/etc/postfix/mysql-maildir.cf"
[測試]
mail [email protected] [向該ip發送一封郵件]
進入/home/vmail/admin,並且查看檔案中有 new目錄,查看 new 中的檔案是你所發的資訊,則表示成功
5.配置dovecot郵件接受服務
vim auth-sql.conf.ext [查看 樣本檔案/usr/share/doc/dovecot-2.2.10/example-config]
cp dovecot-sql.conf.ext/etc/dovecot/
vim /etc/dovecot/dovecot-sql.conf.ext[設定檔,修改如下]
31 # Database driver: mysql, pgsql,sqlite
32 driver = mysql
71 connect = host=localhost dbname=emailuser=postfix password=postfix
78 default_pass_scheme = PLAIN
107 password_query = \
108 SELECT username, domain, password \
109 FROM muser WHERE username = ‘%u‘ AND domain = ‘%d‘
125 user_query = SELECT maildir, 888 AS uid,888 AS gid FROM muser WHERE usernam e= ‘%u‘
vim /etc/dovecot/conf.d/10-mail.conf1
30 mail_location =maildir:/home/vmail/%d/%n
168 first_valid_uid = 888
175 first_valid_gid = 888
systemctl restart dovecot.service [重啟服務]
yum install dovecot-mysql
[測試]
遠程telnet172.25.254.161
[email protected]
pass 123
遠程測試成功就可以用服務應用測試了,
因為是資料庫中的虛擬使用者,大名就為本機使用者名:[email protected]; 電子郵件 [email protected];
收件:IMAP 172.25.254.161;連接埠:143;SSL:無;認證:普通密碼;
寄件:SMTP 172.25.254.161;連接埠:25;SSL:無;認證普通密碼;
使用者名稱:[email protected] 【你可以在資料庫中多建幾個使用者,然後互相發送,成功接受就OK】
650) this.width=650;" src="http://s1.51cto.com/wyfs02/M00/8B/40/wKioL1hIMAHjd3DdAAENA3rQeZk001.png" style="float:none;" title="11.png" alt="wKioL1hIMAHjd3DdAAENA3rQeZk001.png" />
650) this.width=650;" src="http://s1.51cto.com/wyfs02/M01/8B/44/wKiom1hIMAKy-B43AAEPuKTmNEw244.png" style="float:none;" title="12.png" alt="wKiom1hIMAKy-B43AAEPuKTmNEw244.png" />
650) this.width=650;" src="http://s2.51cto.com/wyfs02/M01/8B/40/wKioL1hIMALThmD5AAEnDJxuZsU982.png" style="float:none;" title="13.png" alt="wKioL1hIMALThmD5AAEnDJxuZsU982.png" />
650) this.width=650;" src="http://s1.51cto.com/wyfs02/M02/8B/40/wKioL1hIMAPztdiGAADmuVHvJio076.png" style="float:none;" title="14.png" alt="wKioL1hIMAPztdiGAADmuVHvJio076.png" />
【SMTP 補錄】