设为首页 收藏本站
查看: 1223|回复: 0

[经验分享] 搭建postfix邮件服务器

[复制链接]

尚未签到

发表于 2015-11-24 09:13:02 | 显示全部楼层 |阅读模式
  需要安装的软件包:postfix
  环境为:redhat 6.1 32bit
  
  主配置文件 /etc/postfix/main.cf

运行参数配置/etc/postfix/master.cf

访问控制文件 /etc/postfix/access

别名数据库文件/etc/aliases

虚拟别名域库文件/etc/postfix/virtual



这次实验实现了收发邮件的基本功能,还有指定别名实现群发。  具体过程如下:
  [iyunv@localhost etc]# cd /var/named/chroot/var/named/
[iyunv@localhost named]# ls
1.zone  data     named.ca     named.localhost  slaves
chroot  dynamic  named.empty  named.loopback
[iyunv@localhost named]# vim 1.zone#先修改DNS域名服务器,使之能够解析邮件服务器地址

$TTL 1D
@       IN SOA example.com. root. (
0       ; serial
1D      ; refresh
1H      ; retry
1W      ; expire
3H )    ; minimum
NS      chen
@       MX      10      mail#@ 指在本域内,即example.com,MX为邮件服务器解析,10优先级,mail为邮件服务器的hostname
mail    A       192.169.1.100#解析到自己
example.com.    A       192.169.1.100
station1        A       192.169.1.100
www             A       192.169.1.100
chen            A       192.169.1.100
ftp             CNAME   www


[iyunv@localhost named]# service named restart
停止 named:..^C
[iyunv@localhost named]# ps aux|grep named
root      6205  0.0  0.0 103244   860 pts/12   S+   11:04   0:00 grep named
named    30927  0.0  2.9 235964 30508 ?        Ssl  01:36   0:05 /usr/sbin/named -u named -t /var/named/chroot
[iyunv@localhost named]# kill -9 30927
[iyunv@localhost named]# service named start
启动 named:                                               [确定]
[iyunv@localhost named]# nslookup www.example.com
Server:192.169.1.100
Address:192.169.1.100#53
Name:www.example.com
Address: 192.169.1.100
[iyunv@localhost named]# nslookup mail.example.com#可以正常解析
Server:192.169.1.100
Address:192.169.1.100#53
Name:mail.example.com
Address: 192.169.1.100
[iyunv@localhost named]# hostname
localhost.localdomain
[iyunv@localhost named]# hostname mail.example.com#修改hostname
[iyunv@localhost named]# vim /etc/sysconfig/network#写入配置文件
NETWORKING=yes
HOSTNAME=mail.example.com
[iyunv@localhost named]# yum -y install postfix#安装postfix包
Loaded plugins: refresh-packagekit, rhnplugin
This system is not registered with RHN.
RHN support will be disabled.
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package postfix.i686 2:2.6.6-2.2.el6_1 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package        Arch        Version                    Repository          Size
================================================================================
Updating:
postfix        i686        2:2.6.6-2.2.el6_1          rhel-source        2.0 M
Transaction Summary
================================================================================
Install       0 Package(s)
Upgrade       1 Package(s)
Total download size: 2.0 M
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Updating       : 2:postfix-2.6.6-2.2.el6_1.i686                           1/2
Cleanup        : 2:postfix-2.6.6-2.el6.i686                               2/2
Updated:
postfix.i686 2:2.6.6-2.2.el6_1                                                
Complete!
[iyunv@localhost named]# cd /etc/postfix/
[iyunv@localhost postfix]# ls
access     generic        main.cf    relocated  virtual
canonical  header_checks  master.cf  transport
[iyunv@localhost postfix]# vim main.cf#修改主配置文件

#主要配置如下几个地方
myhostname = mail.example.com#本机主机名
mydomain = example.com#域名
myorigin = $mydomain#设置由本机寄出去的邮件所使用的域名或主机名
inet_interfaces = all#postfix所监听的网络
mydestination = $myhostname, localhost.$mydomain, localhost, example.com#设置可接受邮件的主机名和域名
mynetworks = 192.169.1.0/24#设置在什么网络内收发邮件
relay_domains = $mydestination#设置在什么网域内收发邮件

[iyunv@localhost postfix]# service postfix restart
关闭 postfix:                                             [确定]
启动 postfix:                                             [确定]
[iyunv@localhost postfix]# id user1
uid=502(user1) gid=502(user1) 组=502(user1)
[iyunv@localhost postfix]# mail user1
Subject: hello user1
nihao
EOT
[iyunv@localhost postfix]# su - user1
[user1@mail ~]$ mail
Heirloom Mail version 12.4 7/29/08.  Type ? for help.
"/var/spool/mail/user1": 1 message 1 new
>N  1 root                  Mon Aug 13 11:14  18/551   "hello user1"
& 1
Message  1:
From root@example.com  Mon Aug 13 11:14:57 2012
Return-Path: <root@example.com>
X-Original-To: user1
Delivered-To: user1@example.com
Date: Mon, 13 Aug 2012 11:14:57 +0800
To: user1@example.com
Subject: hello user1
User-Agent: Heirloom mailx 12.4 7/29/08
Content-Type: text/plain; charset=us-ascii
From: root@example.com (root)
Status: R
nihao
& quit
Held 1 message in /var/spool/mail/user1
[user1@mail ~]$

------------------群发,指定别名-------------------
[iyunv@localhost postfix]# pwd
/etc/postfix
[iyunv@localhost postfix]# ls
access     generic        main.cf    relocated  virtual
canonical  header_checks  master.cf  transport
[iyunv@localhost postfix]# vim main.cf

#指定别名数据库,第386和397行要打开,指定别名数据库
385 #alias_maps = dbm:/etc/aliases
386 alias_maps = hash:/etc/aliases
387 #alias_maps = hash:/etc/aliases, nis:mail.aliases
388 #alias_maps = netinfo:/aliases
389
390 # The alias_database parameter specifies the alias database(s) that
391 # are built with &quot;newaliases&quot; or &quot;sendmail -bi&quot;.  This is a separate
392 # configuration parameter, because alias_maps (see above) may specify
393 # tables that are not necessarily all under control by Postfix.
394 #
395 #alias_database = dbm:/etc/aliases
396 #alias_database = dbm:/etc/mail/aliases
397 alias_database = hash:/etc/aliases
398 #alias_database = hash:/etc/aliases, hash:/opt/majordomo/aliases

[iyunv@localhost postfix]# vim /etc/aliases
You have new mail in /var/spool/mail/root

92 # trap decode to catch security attacks
93 decode:         root
94 jinpeng.chen:   user1, user2#增加这行,jinpeng.chen为其他所有用户到别名
95 # Person who should get root's mail
96 #root:          marc

[iyunv@localhost postfix]# newaliases#刷新别名数据库
[iyunv@localhost postfix]# mail jinpeng.chen
Subject: qunfa
hello,everyone...
.
EOT
[iyunv@localhost postfix]# su - user1
[user1@mail ~]$ mail
Heirloom Mail version 12.4 7/29/08.  Type ? for help.
&quot;/var/spool/mail/user1&quot;: 2 messages 1 new
1 root                  Mon Aug 13 11:14  19/562   &quot;hello user1&quot;
>N  2 root                  Mon Aug 13 11:35  18/578   &quot;qunfa&quot;
& 2
Message  2:
From root@example.com  Mon Aug 13 11:35:36 2012
Return-Path: <root@example.com>
X-Original-To: jinpeng.chen
Delivered-To: jinpeng.chen@example.com
Date: Mon, 13 Aug 2012 11:35:36 +0800
To: jinpeng.chen@example.com
Subject: qunfa
User-Agent: Heirloom mailx 12.4 7/29/08
Content-Type: text/plain; charset=us-ascii
From: root@example.com (root)
Status: R
hello,everyone...
& quit
Held 2 messages in /var/spool/mail/user1
[user1@mail ~]$ exit
logout
[iyunv@localhost postfix]# su - user2
[user2@mail ~]$ mail
Heirloom Mail version 12.4 7/29/08.  Type ? for help.
&quot;/var/spool/mail/user2&quot;: 1 message 1 new
>N  1 root                  Mon Aug 13 11:35  18/578   &quot;qunfa&quot;
& 1
Message  1:
From root@example.com  Mon Aug 13 11:35:37 2012
Return-Path: <root@example.com>
X-Original-To: jinpeng.chen
Delivered-To: jinpeng.chen@example.com
Date: Mon, 13 Aug 2012 11:35:36 +0800
To: jinpeng.chen@example.com
Subject: qunfa
User-Agent: Heirloom mailx 12.4 7/29/08
Content-Type: text/plain; charset=us-ascii
From: root@example.com (root)
Status: R
hello,everyone...
& quit
Held 1 message in /var/spool/mail/user2
[user2@mail ~]$

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-142909-1-1.html 上篇帖子: 整理一下杂七杂八的postfix+extmail的mail服务器架设维护笔记 下篇帖子: 解决 /etc/postfix/main.cf: No such file or directory
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表