配置DNS

[[email protected] ~]# yum install bind -y

[[email protected] ~]# systemctl start named

[[email protected] ~]# vim /etc/named.conf

 

 

11 //      listen-on port 53 { 127.0.0.1; };

12 //      listen-on-v6 port 53 { ::1; };

17 //      allow-query     { localhost; };

32         dnssec-validation no;

 

 

[[email protected] ~]# vim /etc/named.rfc1912.zones

 

 

zone "westos.com" IN {

        type master;

        file "westos.com.zone";

        allow-update { none; };

};

 

zone "qq.com" IN {

        type master;

        file "qq.com.zone";

        allow-update { none; };

};

 

 

[[email protected] ~]# cd /var/named/

[[email protected] named]# ls

data  dynamic  named.ca  named.empty  named.localhost  named.loopback  slaves

[[email protected] named]# cp -p named.localhost westos.com.zone

[[email protected] named]# vim westos.com.zone

 

 

$TTL 1D

@       IN SOA  dns.westos.com. root.westos.com. (

                                        0       ; serial

                                        1D      ; refresh

                                        1H      ; retry

                                        1W      ; expire

                                        3H )    ; minimum

                NS      dns.westos.com.

dns             A       172.25.254.104

westos.com.     MX 1    172.25.254.104.

 

 

[[email protected] named]# cp -p westos.com.zone qq.com.zone

[[email protected] named]# vim qq.com.zone

 

 

$TTL 1D

@       IN SOA  dns.qq.com. root.qq.com. (

                                        0       ; serial

                                        1D      ; refresh

                                        1H      ; retry

                                        1W      ; expire

                                        3H )    ; minimum

                NS      dns.qq.com.

dns             A       172.25.254.104

qq.com.         MX 1    172.25.254.204.

 

 

[[email protected] named]# systemctl restart named

[[email protected] named]# vim /etc/resolv.conf

 

nameserver 172.25.254.104

 

 

[[email protected] named]# dig -t mx qq.com

 

[[email protected] named]# dig -t mx westos.com

 mail postfix postfix+mariadbmail postfix postfix+mariadbmail postfix postfix+mariadbmail postfix postfix+mariadbmail postfix postfix+mariadbmail postfix postfix+mariadbmail postfix postfix+mariadbmail postfix postfix+mariadb

[[email protected] ~]# mail [email protected]

Subject: hello

hello world

.                                   ##用"."来结束录入内容并发送

EOT

[[email protected] ~]# mailq       ##查看邮件队列

Mail queue is empty

postqueue -f       ##重新处理邮件队列   

 mail postfix postfix+mariadb

如果邮件发送不过去   在邮件接收端进行配置

1.postfix提供smtp协议用来投递邮件

默认端口是25

默认情况下邮件只在127.0.0.1上开启

2.配置

westos-mail主机上

vim /etc/postfix/main.cf

116 inet_interfaces = all          ##25端口开启的网络接口

83 mydomain = westos.com                   ##指定mta的域名

76 myhostname = westos-mail.westos.com    ##指定mta主机名称

99 myorigin = westos.com                  ##指定邮件来源结尾(@后面的字符内容)

164 mydestination = $myhostname, $mydomain, localhost, ##接收邮件结尾字符的指定

 

qq-mail主机上

vim /etc/postfix/main.cf

116 inet_interfaces = all

83 mydomain = qq.com

76 myhostname = qq-mail.qq.com

99 myorigin = qq.com

164 mydestination = $myhostname, $mydomain, localhost,

配置完成后,分别重启服务,关闭火墙

systemctl restart postfix.service

systemctl stop firewalld

 mail postfix postfix+mariadbmail postfix postfix+mariadbmail postfix postfix+mariadb

 

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

[[email protected] ~]# systemctl restart postfix.service

[[email protected] ~]# systemctl stop firewalld

[[email protected] ~]# mail

Heirloom Mail version 12.5 7/5/10.  Type ? for help.

"/var/spool/mail/root": 1 message 1 new

>N  1 root                  Sat May 20 03:14  21/733   "hello"

&

Message  1:

From [email protected]  Sat May 20 03:14:06 2017

Return-Path: <[email protected]>

X-Original-To: [email protected]

Delivered-To: [email protected]

Date: Sat, 20 May 2017 03:14:05 -0400

To: [email protected]

Subject: hello

User-Agent: Heirloom mailx 12.5 7/5/10

Content-Type: text/plain; charset=us-ascii

From: [email protected] (root)

Status: R

 

hello world

 

New mail has arrived.

Loaded 1 new message

 N  2 root                  Sat May 20 03:17  21/741   "hello"

&

Message  2:

From [email protected]  Sat May 20 03:17:56 2017

Return-Path: <[email protected]>

X-Original-To: [email protected]

Delivered-To: [email protected]

Date: Sat, 20 May 2017 03:17:54 -0400

To: [email protected]

Subject: hello

User-Agent: Heirloom mailx 12.5 7/5/10

Content-Type: text/plain; charset=us-ascii

From: [email protected] (root)

Status: R

 

i come from youdian

 

& ^Z

[1]+  Stopped                 mail

You have mail in /var/spool/mail/root

 mail postfix postfix+mariadb

[[email protected] ~]# vim /etc/aliases

admin:          root

moreuser:       :include:/etc/postfix/moreuser

 

别名: 真名 ##邮件别名

别名: :include:filename ##邮件群发

 

[[email protected] ~]# vim filename

root

student

 

 

[[email protected] ~]# postalias /etc/aliases

测试

[[email protected] ~]# mail [email protected]

Subject: yeyeye

yeyeye

.

EOT

[[email protected] ~]# mail [email protected]

Subject: hohou

hohou

.

EOT

[[email protected] ~]# mailq

Mail queue is empty

 

 

[[email protected] ~]# mail

Heirloom Mail version 12.5 7/5/10.  Type ? for help.

"/var/spool/mail/root": 3 messages 2 new

    1 root                  Wed May 24 13:22  22/731   "ooo"

>N  2 root                  Wed May 24 13:41  21/728   "yeyeye"

 N  3 root                  Wed May 24 13:41  21/730   "hohou"

&

 

 

[[email protected] ~]# mail -u root

Heirloom Mail version 12.5 7/5/10.  Type ? for help.

"/var/mail/root": 6 messages 1 new 6 unread

 U  1 root                  Sat May 20 03:14  22/743   "hello"

 U  2 root                  Sat May 20 03:17  22/751   "hello"

 U  3 root                  Sat May 20 03:19  22/737   "hello gay"

 U  4 root                  Sat May 20 03:20  27/772   "hello boy"

 U  5 root                  Sat May 20 03:21  22/736   "hello"

>N  6 root                  Sat May 20 04:22  24/860   "ooo"

& ^Z

 

[[email protected] ~]# mail [email protected]

Subject: piu

piupiu

.

EOT

[[email protected] ~]# mailq

Mail queue is empty

 mail postfix postfix+mariadbmail postfix postfix+mariadbmail postfix postfix+mariadb

 

 

 

4.通过远程主机测试邮件服务

 

[[email protected] ~]# telnet 172.25.254.157

Trying 172.25.254.157...

telnet: connect to address 172.25.254.157: Connection refused

[[email protected] ~]# telnet 172.25.254.157 25

Trying 172.25.254.157...

Connected to 172.25.254.157.

Escape character is '^]'.

220 westos-mail.westos.com ESMTP Postfix

ehlo hello

250-westos-mail.westos.com

250-PIPELINING

250-SIZE 10240000

250-VRFY

250-ETRN

250-ENHANCEDSTATUSCODES

250-8BITMIME

250 DSN

mail from:[email protected]

250 2.1.0 Ok

rcpt to:[email protected]

250 2.1.5 Ok

data

354 End data with <CR><LF>.<CR><LF>

.

250 2.0.0 Ok: queued as D8B5D24664F

quit

221 2.0.0 Bye

Connection closed by foreign host.

 

 mail postfix postfix+mariadb

 

[[email protected] ~]# mail

Heirloom Mail version 12.5 7/5/10.  Type ? for help.

"/var/spool/mail/root": 4 messages 1 new 3 unread

    1 root                  Wed May 24 13:22  22/731   "ooo"

 U  2 root                  Wed May 24 13:41  22/738   "yeyeye"

 U  3 root                  Wed May 24 13:41  22/740   "hohou"

>N  4 [email protected]       Wed May 24 13:48  11/477   

& 4

Message  4:

From [email protected]  Wed May 24 13:48:27 2017

Return-Path: <[email protected]>

X-Original-To: [email protected]

Delivered-To: [email protected]

Status: R

 

&

 

 mail postfix postfix+mariadbmail postfix postfix+mariadb

 

##########限制用户发送##########

[[email protected] postfix]# postconf -e "smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/sender"

[[email protected] postfix]# vim /etc/postfix/sender

[email protected]  REJECT

[[email protected] postfix]# postmap /etc/postfix/sender

[[email protected]os-mail postfix]# cd /etc/postfix

[[email protected] postfix]# ls             ##生成sender.db文件

access     generic        main.cf    moreuser   sender     transport

canonical  header_checks  master.cf  relocated  sender.db  virtual

[[email protected] postfix]# systemctl restart postfix.service

 mail postfix postfix+mariadb

测试:

 

[[email protected] ~]# telnet 172.25.254.157 25

Trying 172.25.254.157...

Connected to 172.25.254.157.

Escape character is '^]'.

220 westos-mail.westos.com ESMTP Postfix

mail from:[email protected]

250 2.1.0 Ok

rcpt to:[email protected]

554 5.7.1 <[email protected]>: Sender address rejected: Access denied

 

 mail postfix postfix+mariadb

 

###########限制用户接受#########

[[email protected] postfix]# useradd westos

[[email protected] postfix]# postconf -e "smtpd_recipient_restrictions = check_recipient_access hash:/etc/postfix/recip"

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

[[email protected] postfix]# vim /etc/postfix/recip

[email protected] REJECT

[[email protected] postfix]# postmap /etc/postfix/recip

[[email protected] postfix]# systemctl restart postfix

 mail postfix postfix+mariadbmail postfix postfix+mariadb

 

 

测试

 

 

[[email protected] ~]# telnet 172.25.254.157 25

Trying 172.25.254.157...

Connected to 172.25.254.157.

Escape character is '^]'.

220 westos-mail.westos.com ESMTP Postfix

mail from:westos.westos.com

250 2.1.0 Ok

rcpt to:[email protected]

250 2.1.5 Ok

data

354 End data with <CR><LF>.<CR><LF>

hhh

.

250 2.0.0 Ok: queued as 7D9F924664F

quit

221 2.0.0 Bye

Connection closed by foreign host.

[[email protected] ~]# telnet 172.25.254.157 25

Trying 172.25.254.157...

Connected to 172.25.254.157.

Escape character is '^]'.

220 westos-mail.westos.com ESMTP Postfix

mail from:[email protected]

250 2.1.0 Ok

rcpt to:westos.westos.com

554 5.7.1 <[email protected]>: Recipient address rejected: Access denied

 mail postfix postfix+mariadb

 

#########出站地址伪装#########

[[email protected] ~]# postconf -e "smtp_generic_maps = hash:/etc/postfix/generic"

[[email protected] ~]# vim /etc/postfix/generic

   真实名字              虚拟名字

[email protected]     [email protected]

[[email protected] ~]# postmap /etc/postfix/generic

[[email protected] ~]# systemctl restart postfix

 mail postfix postfix+mariadb

 

测试

 

发送邮件

[[email protected] ~]# su - westos

[[email protected] ~]$ mail [email protected]

Subject: mamama

.

EOT

Null message body; hope that's ok

[[email protected] ~]$ postqueue -f

[[email protected] ~]$ mailq

Mail queue is empt

接收邮件

[[email protected] ~]# mail

Heirloom Mail version 12.5 7/5/10.  Type ? for help.

"/var/spool/mail/root": 5 messages 1 new 3 unread

    1 root                  Wed May 24 13:22  22/731   "ooo"

 U  2 root                  Wed May 24 13:41  22/738   "yeyeye"

 U  3 root                  Wed May 24 13:41  22/740   "hohou"

    4 [email protected]       Wed May 24 13:48  12/488   

>N  5 [email protected]          Wed May 24 18:49  21/709   "mama"

&

 mail postfix postfix+mariadb

 

 

############入站地址伪装############

 

DNS记录解析

[[email protected] ~]# vim /etc/named.rfc1912.zones

 

zone "sb.com" IN {

        type master;

        file "sb.com.zone";

        allow-update { none; };

};

 

[[email protected] ~]# cd /var/named

[[email protected] named]# ls

data     named.ca     named.localhost  qq.com.zone  westos.com.zone

dynamic  named.empty  named.loopback   slaves

[[email protected] named]# cp -p qq.com.zone sb.com.zone

[[email protected] named]# vim sb.com.zone

 

$TTL 1D

@       IN SOA  dns.sb.com. root.sb.com. (

                                        0       ; serial

                                        1D      ; refresh

                                        1H      ; retry

                                        1W      ; expire

                                        3H )    ; minimum

                NS      dns.sb.com.

dns             A       172.25.254.157

sb.com.         MX 1    172.25.254.157.

 

[[email protected] named]# systemctl restart named

 

测试DNS解析是否完成

[[email protected] ~]# dig -t mx sb.com

 

 mail postfix postfix+mariadbmail postfix postfix+mariadbmail postfix postfix+mariadb

#########入站地址转换##########

[[email protected] ~]# useradd hello

[[email protected] ~]# postconf -e "virtual_alias_maps = hash:/etc/postfix/virtual"

[[email protected] ~]# vim /etc/postfix/virtual

   虚拟名字           真实名字

 [email protected]    [email protected]

[[email protected] ~]# postmap /etc/postfix/virtual

[[email protected] ~]# systemctl restart postfix

[[email protected] ~]# su - westos

Last login: Sat May 20 22:41:58 EDT 2017 on pts/0

 

 mail postfix postfix+mariadb

测试

 

回复邮件

[[email protected] ~]# mail [email protected]

Subject: houhou

.

EOT

Null message body; hope that's ok

[[email protected] ~]# postqueue -f

[[email protected] ~]# mailq

Mail queue is empty

 

邮件接收

[[email protected] ~]$ mail

Heirloom Mail version 12.5 7/5/10.  Type ? for help.

"/var/spool/mail/westos": 1 message 1 new

>N  1 root                  Wed May 24 18:57  21/715   "houhou"

& 1

Message  1:

From [email protected]  Wed May 24 18:57:41 2017

Return-Path: <[email protected]>

X-Original-To: [email protected]

Delivered-To: [email protected]

Date: Wed, 24 May 2017 18:57:40 -0400

To: [email protected]

Subject: houhou

User-Agent: Heirloom mailx 12.5 7/5/10

Content-Type: text/plain; charset=us-ascii

From: [email protected] (root)

Status: R

 

 

&

 

 mail postfix postfix+mariadb

 

##############dovecot###############

 

1.

dovecot  用来提供收件协议

pop3       110

imap       143

imaps      993

pop3s      995

 

 

给定用户名称,用户密码,dovecot程序代我们去看这个用户的邮件文件

 

2.

[[email protected] ~]# yum install dovecot -y

[[email protected] ~]# systemctl start dovecot

[[email protected] ~]# vim /etc/dovecot/dovecot.conf

 

 24 protocols = imap pop3 lmtp

 48 login_trusted_networks = 0.0.0.0/0

 49 disable_plaintext_auth = no

 

[[email protected] ~]# vim /etc/dovecot/conf.d/10-mail.conf

 

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

 

[[email protected] ~]# systemctl restart dovecot.service

[[email protected] ~]# passwd westos

[[email protected] ~]# mkdir /home/westos/mail/.imap

[[email protected] ~]# touch /home/westos/mail/.imap/INBOX

[[email protected] ~]# mkdir /etc/skel/mail/.imap -p

[[email protected] ~]#touch /etc/skel/mail/.imap/INBOX

 mail postfix postfix+mariadbmail postfix postfix+mariadbmail postfix postfix+mariadbmail postfix postfix+mariadb

测试

 

[[email protected] ~]# yum install mutt -y

[[email protected] ~]# mutt -f pop://[email protected]

1 kept, 0 deleted.

 

 mail postfix postfix+mariadbmail postfix postfix+mariadbmail postfix postfix+mariadbmail postfix postfix+mariadb

 

############postfix+mariadb#############

[[email protected] ~]# mv /etc/postfix/main.cf /mnt/

[[email protected] ~]# yum reinstall postfix.x86_64 -y

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

[[email protected] ~]# systemctl restart postfix.service

[[email protected] ~]# yum install httpd php php-mysql mariadb-server -y

[[email protected] ~]# systemctl start mariadb

[[email protected] ~]# vim /etc/my.cnf

skip-networking=1

[[email protected] ~]# systemctl restart postfix.service

[[email protected] ~]# systemctl restart mariadb       

[[email protected] ~]# mysql_secure_installation

[[email protected] ~]# cd /var/www/html

[[email protected] html]# ls

[[email protected] html]# cd

下载phpMyAdmin-3.4.0-all-languages.tar.bz2安装包

[[email protected] html]# tar jxf phpMyAdmin-3.4.0-all-languages.tar.bz2  ##解压

[[email protected] html]# rm -fr *.bz2

[[email protected] html]# ls

phpMyAdmin-3.4.0-all-languages

[[email protected] html]# mv phpMyAdmin-3.4.0-all-languages/ myadmin

[[email protected] html]# ls

myadmin

[[email protected] html]# cd myadmin/

[[email protected] myadmin]# ls

browse_foreigners.php     main.php                server_status.php

bs_disp_as_mime_type.php  navigation.php          server_synchronize.php

bs_play_media.php         phpdoctor.ini           server_variables.php

ChangeLog                 phpinfo.php             setup

changelog.php             phpmyadmin.css.php      show_config_errors.php

chk_rel.php               pmd                     sql.php

config.sample.inc.php     pmd_common.php          tbl_addfield.php

contrib                   pmd_display_field.php   tbl_alter.php

CREDITS                   pmd_general.php         tbl_change.php

db_create.php             pmd_help.php            tbl_chart.php

db_datadict.php           pmd_pdf.php             tbl_create.php

db_export.php             pmd_relation_new.php    tbl_export.php

db_import.php             pmd_relation_upd.php    tbl_get_field.php

db_operations.php         pmd_save_pos.php        tbl_import.php

db_printview.php          prefs_forms.php         tbl_indexes.php

db_qbe.php                prefs_manage.php        tbl_move_copy.php

db_search.php             print.css               tbl_operations.php

db_sql.php                querywindow.php         tbl_printview.php

db_structure.php          README                  tbl_relation.php

db_tracking.php           README.VENDOR           tbl_replace.php

docs.css                  RELEASE-DATE-3.4.0      tbl_row_action.php

Documentation.html        robots.txt              tbl_select.php

Documentation.txt         schema_edit.php         tbl_sql.php

enum_editor.php           schema_export.php       tbl_structure.php

export.php                scripts                 tbl_tracking.php

favicon.ico               server_binlog.php       themes

import.php                server_collations.php   themes.php

import_status.php         server_databases.php    TODO

index.php                 server_engines.php      transformation_overview.php

INSTALL                   server_export.php       transformation_wrapper.php

js                        server_import.php       url.php

libraries                 server_privileges.php   user_password.php

LICENSE                   server_processlist.php  view_create.php

license.php               server_replication.php  view_operations.php

locale                    server_sql.php          webapp.php

[[email protected] myadmin]# cp config.sample.inc.php config.inc.php

[[email protected] myadmin]# vim config.inc.php

[[email protected] myadmin]# systemctl start httpd

 

 [[email protected] myadmin]# mysql -uroot -pwestos

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 51

Server version: 5.5.35-MariaDB MariaDB Server

 

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

MariaDB [(none)]> create user [email protected] identified by 'postuser';

Query OK, 0 rows affected (0.00 sec)

 

MariaDB [(none)]> grants select,update,insert on email.* to [email protected];

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'grants select,update,insert on email.* to [email protected]' at line 1

MariaDB [(none)]> grant select,update,insert on email.* to [email protected];

Query OK, 0 rows affected (0.00 sec)

 

MariaDB [(none)]> quit

Bye

[[email protected] myadmin]# mysql -upostuser -ppostuser

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 52

Server version: 5.5.35-MariaDB MariaDB Server

 

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

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

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

| username      | password | domain   | maidir              |

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

| [email protected] | haha     | haha.com | /mnt/haha.com/haha/ |

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

1 row in set (0.00 sec)

 

MariaDB [(none)]> quit

Bye

[[email protected] myadmin]# cd

[[email protected] ~]# vim /etc/postfix/mailuser.cf

hosts = localhost   ##用户名称查询

user = postuser      ##数据库所在主机

password = postuser   ##登陆数据库的用户

dbname = email         ##postfix要查询的名称

table = emailuser    ##postfix要查询的表的名称

select_field = username  ##postfix要查询的字段

where_field = username    ##用户给定postfix的查询条件

 

[[email protected] ~]# vim /etc/postfix/mailbox.cf  ##用户邮箱地址查询

hosts = localhost

user = postuser

password = postuser

dbname = email

table = emailuser

select_field = maildir

where_field = username

 

[[email protected] ~]# vim /etc/postfix/maildomain.cf  ##用户域名查询

hosts = localhost

user = postuser

password = postuser

dbname = email

table = emailuser

select_field = domain

where_field = domain

 

[[email protected] ~]# postmap -q "[email protected]" mysql:/etc/postfix/mailuser.cf

[email protected]

[[email protected] ~]# postmap -q "haha.com" mysql:/etc/postfix/maildomain.cf

haha.com

[[email protected] ~]# vim /etc/postfix/mailbox.cf

[[email protected] ~]# postmap -q "[email protected]" mysql:/etc/postfix/mailbox.cf

/mnt/haha.com/haha/

      mail postfix postfix+mariadbmail postfix postfix+mariadbmail postfix postfix+mariadbmail postfix postfix+mariadbmail postfix postfix+mariadbmail postfix postfix+mariadb

相关文章: