Linux 第十一周学习笔记(1)SMTP服务进阶篇

SMTP服务部署-进阶篇php

紧接着上周的内容。html

一.远程登录限制mysql

因为当前全部虚拟机均可以远程链接实现发送邮件的服务,很明显这是步安全的。linux

如何实现登录限制:ios

在个人客户机(desktop)上sql

1.cd /etc/postfix/数据库

在最后一行添加:拒绝登录的ip REJECTvim

如:172.25.254.50 REJECT浏览器

2.postmap access #加密文件,这样会生成一个access.db文件安全

3.postconf -d | grep client #筛选配置项目。并查询

4. postconf -e "smtpd_client_restrictions = check_client_access hash:/etc/postfix/access"#写入配置文件

这个配置文件在:/etc/postfix/main.cf的最后面

wKioL1hJgYvQl6YmAAIIQxhgDw4894.png-wh_50

5.重启服务

systemctl restart postfix.service

测试:

在个人ip50的主机上:

wKioL1hJgaKzcQ_sAAEoBeWWGhY649.png-wh_50

说明:这里的限制登录其实是能够经过telnet链接的,可是邮件是发不出去的

@还原操做:删除/etc/postfix/main.cf的最后一行,

Postmap access #从新加密,最后重启服务便可

二.冻结用户邮件服务

/etc/postfix/目录下

1.vim sender

输入内容:westos@lyitx.com REJECT

2.postmap sender

3.postconf -e "smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/sender"

4.systemctl restart postfix.service

测试:

在另一台虚拟机上测试:

[kiosk@foundation50 Desktop]$ telnet 172.25.254.166 25

Trying 172.25.254.166...

Connected to 172.25.254.166.

Escape character is '^]'.

220 maillyitx.lyitx.com ESMTP Postfix

mail from:westos@lyitx.com

250 2.1.0 Ok

rcpy to:root@linux.com

502 5.5.2 Error: command not recognized

rcpt to:root@linux.com

554 5.7.1 <westos@lyitx.com>: Sender address rejected: Access denied

 

 

三.拒绝用户接收邮件

1.vim recip  #写入要拒绝接收邮件的用户全名

westos@lyitx.com        REJECT

2.postmap recip#加密

3.postconf -e "smtpd_recipient_restrictions = check_recipient_access hash:/etc/postfix/recip"

4. systemctl restart postfix.service

测试:

50主机:

[kiosk@foundation50 Desktop]$ telnet 172.25.254.166 25

wKiom1hJgb-DgNc8AAHqx2rVD2Q186.png-wh_50

以上操做在/etc/postfix/main.cf的最后一行能够看到

readme_directory = /usr/share/doc/postfix-2.10.1/README_FILES

smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/sender

smtpd_recipient_restrictions = check_recipient_access hash:/etc/postfix/recip

@@不干扰后续实验,在这里进行操做的还原

具体方法:

删除/etc/postfix/main.cf文件的最后两行

而后重启服务便可

 

四.豆腐块(dovecot

desktop主机(172.25.254.166)上

1.yum install dovecot -y

2.vim /etc/dovecot/dovecot.conf

24行注释取消

24 protocols = imap pop3 lmtp

49 disable_plaintext_auth = no

 50 login_trusted_networks = 0.0.0.0/0#容许外网登录

3.cd /etc/dovecot/conf.d/

vim 10-mail.conf

加入如下内容

30行: mail_location = mbox:~/mail:INBOX=/var/mail/%u

4.systemctl start dovecot

@以上几步操做目的在于开放端口

wKioL1hJgeCB_OcUAAIpeYiDwdM078.png-wh_50

5.su - westos####在这里须要手动创建文件(已经存在的用户)

6.mkdir -p /home/westos/mail/.imap

7.touch /home/westos/mail/.imap/INBOX

8.su - root

这里有一个一劳永逸的方法:

在超级用户下:

cd /etc/skel/

mkdir mail/.imap/INBOX

(如此设置可让每个新建用户建立时系统都会自动建立目录)

最后重启服务:

systemctl restart dovecot.service

测试:

在其余主机上测试:

1.yum install mutt -y

2.mutt -f imap://westos@172.25.254.166

wKioL1hJgfSjGLANAAGD3QvjB6M335.png-wh_50

根据提示输入密码后就能够看到westos用户的邮件

[root@foundation50 Desktop]# telnet 172.25.254.166 110

Trying 172.25.254.166...

Connected to 172.25.254.166.

Escape character is '^]'.

+OK [XCLIENT] Dovecot ready.

user westos

+OK

pass redhat

+OK Logged in.

操做成功

五.用雷鸟接收邮件

打开雷鸟软件

 

wKiom1hJgg2w3zFzAAB0YKLkOuo753.png-wh_50

wKioL1hJgiLTc6gOAAD61jgSjjI319.png-wh_50

wKiom1hJgjTjHj32AAE-eITLXVg618.png-wh_50

wKioL1hJgkbBVnB9AAFKJOHHTIM016.png-wh_50

这样就能够在软件中受到邮件了

 

####数据库虚拟用户接收邮件###

1.安装数据库

yum install mysql-server -y

systemctl start mariadb

vim /etc/my.cnf

配置文件改成:

symbolic-links=1

systemctl restart mariadb##

mysql_secure_installation#安全初始化,设置root密码。而后一直空格

2.phpmyadmin的安装在网页上显示操做数据库

yum install httpd -y

systemctl start httpd

mv phpMyAdmin-3.4.0-all-languages.tar.bz2 /var/www/html/

cd /var/www/html/

tar -jxf phpMyAdmin-3.4.0-all-languages.tar.bz2  ##解压文件

mv phpMyAdmin-3.4.0-all-languages myadmin   ##改个简单的名字

systemctl stop firewalld.service ##关闭火墙

yum install php -y##安装php,没有php环境显示不了

systemctl restart httpd.service ##安装事后须要从新启http

cd myadmin/

cp -p config.sample.inc.php config.inc.php##将模板文件复制成一个真正的配置文件

vim config.inc.php  ##在文件中添加如cookie

$cfg['blowfish_secret'] = 'westos'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

yum install php-mysql.x86_64 -y##关联数据库

systemctl restart httpd.service

浏览器中输入:安装数据库的服务器的ip地址/myadmin

 

wKiom1hJgliwAci3AADt6baKrDw000.png-wh_50

在建立一个名为:email的数据库,建立一个为muser的表,字段数设置为4.

详细设置以下:

wKiom1hJgmqT4et3AAGLCGq90tY974.png-wh_50

wKioL1hJgnux6MqxAAJAg9E_9xQ309.png-wh_50

而后在本地数据库中新建用户:

MariaDB [(none)]> select * from email.muser;

+-----------------+----------+-----------+------------------+

| username        | password | domain    | maildir          |

+-----------------+----------+-----------+------------------+

| admin@lyitx.org | 123      | lyitx.org | lyitx.org/admin/ |

+-----------------+----------+-----------+------------------+

1 row in set (0.00 sec)

 

建立用户:CREATE USER postfix@localhost identified by ‘postfix’

再进行受权,(图中)

GRANT INSERTUPDATESELECT on emial.* to postfix@localhost;

而后退出

3.文件的编写:

再安装有数据库的主机上:

cd /etc/postfix/

vim mysql-users.cf

手动编写如下内容

hosts = localhost

user = postfix

password = postfix

dbname = email

table = muser

select_field = username

where_field = username

保存退出

 

vim mysql-domain.cf

编写:

hosts = localhost

user = postfix

password = postfix

dbname = email

table = muser

select_field = domain

where_field = domain

 

vim mysql-maildir.cf

hosts = localhost

user = postfix

password = postfix

dbname = email

table = muser

select_field = maildir

where_field = username

wKioL1hJgo3waSRNAAGqC8PKilY772.png-wh_50

 

而后对这三个文件进行加密处理

wKioL1hJgqCxBY1YAAFJxY4Xo5o702.png-wh_50

纠正一下:图中显示的内容应为

lyitx.org/admin/

 

4.建立vmail用户,mail

groupadd -g 666 vmail

useradd -g 666 -u 666 -s /sbin/nologin vmail

细节:参数不能少,若是出错要从新创建用户须要执行:

userdel -r vmail

5.写入配置文件

 

wKiom1hJgrajGCRMAAMspjCje4o156.png-wh_50

在配置文件/etc/postfix/main.cf的最后能够看到写入的内容

virtual_gid_maps = static:666

virtual_uid_maps = static:666

virtual_mailbox_base = /home/vmail

virtual_alias_maps = mysql:/etc/postfix/mysql-users.cf

virtual_mailbox_domains = mysql:/etc/postfix/mysql-domain.cf

virtual_mailbox_maps = mysql:/etc/postfix/mysql-maildir.cf

 

6.重启postfix服务

Systemctl restart postfix.severice

 

测试:就在当前主机给admin@lyitx.org 用户发送邮件

若是在/home/vmail/lyitx.org/admin/new目录下查看到邮件,说明操做成功!

 

[root@maillyitx new]# pwd

/home/vmail/lyitx.org/admin/new

[root@maillyitx new]# ls

1481167802.Vfd01I280a514M732414.maillyitx.lyitx.com

1481167902.Vfd01I280a515M599277.maillyitx.lyitx.com

1481167977.Vfd01I280a516M115286.maillyitx.lyitx.com

1481185764.Vfd01I280a51eM96871.maillyitx.lyitx.com

[root@maillyitx new]#

 

豆腐块&数据库

cp /usr/share/doc/dovecot-2.2.10/example-config/dovecot-sql.conf.ext /etc/dovecot/

cd /etc/dovecot

vim dovecot-sql.conf.ext

 32 driver = mysql

71 connect = host=localhost dbname=email user=postfix password=postfix

 78 default_pass_scheme = PLAIN

107 password_query = \

108   SELECT username, domain, password \

109   FROM muser WHERE username = '%n' AND domain = '%d'

125 user_query = SELECT maildir, 666 AS uid, 666 AS gid FROM muser WHERE userid = '%u'

 

Vim /etc/dovecot/conf.d/10-mail.conf

30 mail_location = maildir:/home/vmail/%d/%n

168 first_valid_uid = 666

175 first_valid_gid = 666

最后重启服务

Ststemctl restart dovecot

在其余主机上,用telnet链接上,就表示实验成功

相关文章
相关标签/搜索