Postfix配置文件和命令

运维 系统运维
postfix是一种邮件传输代理软件,我们在使用postfix的同时,还应该熟悉postfix中的一些命令。这对于今后的维护是很有帮助的。本文主要分析的是postfix中的一些命令,这对今后维护postfix的工作是十分有必要的。

  熟悉postfix中的一些命令,对于今后的维护是很必要的。接下来会分析其中一些重要的配置文件和相关命令.

  一、总体说明

  引用

  /etc/postfix/main.cf

  这是postfix的主配置文件,几乎所有的配置都在这里设定。设定完毕后,需要用reload或restart重新读取配置信息。(涉及网络的配置,需要使用restart)

  引用

  /etc/postfix/master.cf

  这个是postfix子程序的运行状态设置,例如是否使用chroot等。

  引用

  /etc/postfix/access

  类似黑白名单的作用,设置完毕后,需要在main.cf中激活,并使用postmap生成相关的数据库。

  引用

  /etc/aliases

  别名的设置目录,同样,需要在main.cf中激活,并使用postalias生成相关数据库。

  二、main.cf文件

  该文件的配置比较规范,文件中也带了很详细的帮助说明。其主要包括几部分:

  1、“#”号开头,表示改行是注释;

  2、可以使用下面的形式给变量定义:

  引用

  变量 = 值

  请注意等号两边需要留一空格。并且变量最好符合Bash的规范。

  3、可以使用“$变量”来引用该变量的值;

  例如 myorigin = $myhostname,会等于 myorigin = linuxfly.org;

  4、如果变量使用两个以上的数据,可以用空格符或逗号来分隔,设置跨行也可以;

  例如:

  引用

  mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

  也可以写为:

  引用

  mydestination = $myhostname localhost.$mydomain localhost $mydomain

  或:

  引用

  mydestination = $myhostname,

  localhost.$mydomain,

  localhost,

  $mydomain

  结果是相同的。

  5、可以使用hash等格式进行更规范的设定;

  例如:

  引用

  alias_maps = hash:/etc/aliases

  那么,相关的值就可以写入/etc/aliases文件中。

  6、若重复设定某一变量的设定,则以最后出现的设定值为准~!

  三、/etc/postfix/access文件

  1、需要在main.cf中打开

  引用

  /etc/postfix/main.cf:

  smtpd_client_restrictions = check_client_access hash:/etc/postfix/access

  2、设定值

  例如:

  引用

  /etc/postfix/access:

  192.168.228.10 REJECT

  192.168.228.1 OK

  linuxfly.org OK

  3、生成数据库

  # postmap hash:/etc/postfix/access

  四、/etc/aliases文件

  1、同样需要在main.cf中打开

  引用

  /etc/postfix/main.cf:

  alias_database = hash:/etc/aliases

  alias_maps = hash:/etc/aliases

  2、设定值

  引用

  /etc/aliases:

  mailer-daemon: postmaster

  postmaster: root

  root: linuxing,root

  前面是键值,后面是真实的值。真实的值不要求是本地邮件,也可以是外面的邮箱,例如:linuxing@163.com等。

  3、生成数据库

  # postalias hash:/etc/aliases

  ※这会生成类似.db的数据库文件,主要是为了让postfix能快速的读取。其他可以使用多值的地方也可以该方式定义。默认会自动识别,但也可以用“hash:文件”指定格式。

  4、若是个人用户,可以设置主目录下的~/.forward文件,也可以设置别名,一行一个Email地址,例如:

  引用

  [linuxing@dc5test ~]$ cat .forward

  test

  test@test.com

  [linuxing@dc5test ~]$ chmod 644 .forward

  权限不要搞错了!

  五、postfix主要命令

  1、查看配置信息

  引用

  [root@dc5test postfix]# postconf -n

  alias_database = hash:/etc/aliases

  alias_maps = hash:/etc/aliases

  broken_sasl_auth_clients = yes

  command_directory = /usr/sbin

  config_directory = /etc/postfix

  daemon_directory = /usr/libexec/postfix

  debug_peer_level = 2

  html_directory = no

  inet_interfaces = $myhostname, localhost

  mail_owner = postfix

  mailq_path = /usr/bin/mailq.postfix

  manpage_directory = /usr/share/man

  mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

  mydomain = linuxfly.cn

  mynetworks = 192.168.218.0/24, 127.0.0.0/8

  myorigin = $mydomain

  newaliases_path = /usr/bin/newaliases.postfix

  queue_directory = /var/spool/postfix

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

  relay_domains = $mydestination

  sample_directory = /usr/share/doc/postfix-2.1.5/samples

  sendmail_path = /usr/sbin/sendmail.postfix

  setgid_group = postdrop

  smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination

  smtpd_sasl_auth_enable = yes

  smtpd_sasl_security_options = noanonymous

  unknown_local_recipient_reject_code = 550

  2、查看队列信息

  引用

  # mailq

  -Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------

  DB7678DA5 289 Wed Aug 22 16:46:28 root@linuxfly.org

  (Host or domain name not found. Name service error for name=linuxfly.org type=MX: Host not found, try again)

  root@linuxfly.org

  -- 0 Kbytes in 1 Request.

  或

  引用

  # postqueue -p

  -Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------

  DB7678DA5 289 Wed Aug 22 16:46:28 root@linuxfly.org

  (Host or domain name not found. Name service error for name=linuxfly.org type=MX: Host not found, try again)

  root@linuxfly.org

  -- 0 Kbytes in 1 Request.

  结果是一样的。

  3、强制发出邮件

  # postfix flush

  或

  # postqueue -f

  这会把队列中的邮件再发一次。可以处理一些临时的错误问题。

  4、查看在发邮件信息

  在发的邮件会放在/var/spool/postfix/deferred目录中,但其中含有一些postfix特定字符,可通过postcat查看:

  引用

  # postcat DB7678DA5

  *** ENVELOPE RECORDS DB7678DA5 ***

  message_size: 289 163 1 0

  message_arrival_time: Wed Aug 22 16:46:28 2007

  named_attribute: message_origin=local

  sender_fullname: root

  sender: root@linuxfly.org

  original_recipient: root@linuxfly.org

  recipient: root@linuxfly.org

  *** MESSAGE CONTENTS DB7678DA5 ***

  Received: by dc5test.linuxfly.org (Postfix, from userid 0)

  id DB7678DA5; Wed, 22 Aug 2007 16:46:28 +0800 (CST)

  To: root@linuxfly.org

  Subject: test

  Message-Id: <20070822084628.DB7678DA5@dc5test.linuxfly.org>

  Date: Wed, 22 Aug 2007 16:46:28 +0800 (CST)

  From: root@linuxfly.org (root)

  *** HEADER EXTRACTED DB7678DA5 ***

  *** MESSAGE FILE END DB7678DA5 ***

  5、一些Email测试用命令

  ◎mail,字符下的客户端

  $ mail -s 'subject' linuxing < ~/file

  把file中的内容作为邮件内容,以subject做标题,发给本地的linuxing用户。

  引用

  $ mail -s 'subject' linuxing

  test

  Ctrl-D保存退出

  Cc: root

  ●mail直接回车

  则是作为本地的邮件接收客户端,可以用d删除,回车查看,序号查看,help帮助或q退出等操作。

  引用

  # mail

  Mail version 8.1 6/6/93. Type ? for help.

  "/var/spool/mail/root": 2 messages 2 unread

  >U 1 root@linuxfly.org Tue Aug 21 11:56 94/2251 "LogWatch for dc5test"

  U 2 root@linuxfly.org Tue Aug 21 11:57 23/846 "Anacron job 'cron.daily'"

  ●使用mail发送附件

  # uuencode /root/install.log install.log|mail -s 'install log' linuxing

  uuencode后第一个参数的本地文件,第二个参数是邮件中的附件名称。

  ●字符下收信:

  引用

  $ mail

  Mail version 8.1 6/6/93. Type ? for help.

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

  >N 1 root@linuxfly.org Wed Aug 22 17:10 853/52344 "install log"

  & s 1 install.log

  "install.log" [New file]

  & exit

  会保存为install.log文件,然后再解压出来:

  $ uudecode install.log -o install.log

  uudecode: install.log: Short file

  ◎telnet,测试smtp和pop3服务

  ●smtp服务

  引用

  # telnet localhost 25

  Trying 127.0.0.1...

  Connected to localhost.localdomain (127.0.0.1).

  Escape character is '^]'.

  220 dc5test.linuxfly.org ESMTP Postfix

  ehlo localhost

  250-dc5test.linuxfly.org

  250-PIPELINING

  250-SIZE 10240000

  250-VRFY

  250-ETRN

  250-AUTH DIGEST-MD5 CRAM-MD5 NTLM LOGIN GSSAPI PLAIN

  250-AUTH=DIGEST-MD5 CRAM-MD5 NTLM LOGIN GSSAPI PLAIN

  250 8BITMIME

  mail from:"root"

  250 Ok

  rcpt to:

  250 Ok

  data

  354 End data with .

  A test mail.

  .

  250 Ok: queued as A27B38DAF

  quit

  221 Bye

  Connection closed by foreign host.

  ※内容后的“.”号表示内容的终结符。

  ●pop3服务

  引用

  # telnet localhost 110

  Trying 127.0.0.1...

  Connected to localhost.localdomain (127.0.0.1).

  Escape character is '^]'.

  +OK dovecot ready.

  user linuxing

  +OK

  pass password

  +OK Logged in.

  list

  +OK 1 messages:

  1 576

  retr 1

  +OK 576 octets

  Return-Path:

  X-Original-To: linuxing

  Delivered-To: linuxing@linuxfly.org

  Received: by dc5test.linuxfly.org (Postfix, from userid 0)

  id D6D728DB4; Wed, 22 Aug 2007 17:28:33 +0800 (CST)

  To: linuxing@linuxfly.org

  Subject: subject

  Message-Id: <20070822092833.D6D728DB4@dc5test.linuxfly.cn>

  Date: Wed, 22 Aug 2007 17:28:33 +0800 (CST)

  From: root@linuxfly.org (root)

  X-IMAPbase: 1187497071 28

  Status: O

  X-UID: 28

  Content-Length: 13

  X-Keywords:

  A test mail.

  quit

  +OK Logging out.

  Connection closed by foreign host.

【编辑推荐】

责任编辑:zhaolei 来源: 网络转载
相关推荐

2011-01-19 14:00:21

2010-05-07 11:55:13

Unix操作系统

2009-06-24 14:17:00

BackingBeanJSF配置文件

2010-01-04 10:28:47

Ubuntu Apac

2021-06-15 18:42:53

Rollup配置 JavaScript

2011-02-21 12:54:47

postfix命令

2012-02-06 13:34:49

HibernateJava

2010-02-24 14:50:33

Ubuntu vim

2011-01-13 16:27:26

Linux配置文件

2010-12-27 14:59:31

Outlook 配置文

2011-02-21 13:08:37

postfix配置

2011-01-19 09:16:48

Postfix配置

2010-12-28 16:35:32

Outlook 配置文

2010-06-02 17:36:31

postfix概述

2011-03-28 09:07:26

Nagios配置文件

2011-03-28 15:52:16

Nagios配置文件

2011-04-01 16:30:49

Nagios

2009-07-09 15:55:18

WebWork配置文件

2011-03-03 09:14:38

PureFTPd

2010-02-04 13:43:26

Linux vsFTP
点赞
收藏

51CTO技术栈公众号