温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2020-06-23 23:01:09 来源:网络 阅读:748 作者:Lyitx 栏目:数据库

SMTP服务部署-进阶篇

紧接着上周的内容。

一.远程登陆限制

由于当前所有虚拟机都可以远程连接实现发送邮件的服务,很明显这是步安全的。

如何实现登陆限制:

在我的客户机(desktop)上

1.cd /etc/postfix/

在最后一行添加:拒绝登陆的ip REJECT

如: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的最后面

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

5.重启服务

systemctl restart postfix.service

测试:

在我的ip50的主机上:

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

说明:这里的限制登陆实际上是可以通过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

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

以上操作在/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

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

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

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

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

根据提示输入密码后就可以看到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.

操作成功

五.用雷鸟接收邮件

打开雷鸟软件

 

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

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

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

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

这样就可以在软件中受到邮件了

 

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

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

 

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

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

详细设置如下:

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

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

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

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

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

 

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

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

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

lyitx.org/admin/

 

4.创建vmail用户,mail

groupadd -g 666 vmail

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

细节:参数不能少,如果出错要重新建立用户需要执行:

userdel -r vmail

5.写入配置文件

 

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

在配置文件/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连接上,就表示实验成功


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI