歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux技術 >> Linux怎麼安裝配置Postfix

Linux怎麼安裝配置Postfix

日期:2017/2/28 11:58:29   编辑:Linux技術

  Postfix是一款用法靈活的電子郵件應用程序,那麼大家知道Linux怎麼安裝配置Postfix嗎?今天學習啦小編與大家分享下Linux安裝配置Postfix的具體操作步驟,有需要的朋友不妨了解下。

  Linux安裝配置Postfix方法

  postfix的產生是為了替代傳統的sendmail.相較於sendmail,postfix在速度,性能和穩定性上都更勝一籌。現在目前非常多的主流郵件服務其實都在采用postfix. 當我們需要一個輕量級的的郵件服務器是,postfix不失為一種選擇。

  1. postfix是免費的:

  postfix想要作用的范圍是廣大的Internet用戶,試圖影響大多數的Internet上的電子郵件系統,因此它是免費的。

  2. 更快:

  postfix在性能上大約比sendmail快三倍。一部運行postfix的台式PC每天可以收發上百萬封郵件。

  3. 兼容性好:

  postfix是sendmail兼容的,從而使sendmail用戶可以很方便地遷移到postfix。Postfix支持/var[/spool]/mail、/etc/aliases、 NIS、和 ~/.forward 文件。

  4. 更健壯:

  postfix被設計成在重負荷之下仍然可以正常工作。當系統運行超出了可用的內存或磁盤空間時,postfix會自動減少運行進程的數目。當處理的郵件數目增長時,postfix運行的進程不會跟著增加。

  5. 更靈活:

  postfix是由超過一打的小程序組成的,每個程序完成特定的功能。你可以

  通過配置文件設置每個程序的運行參數。

  6. 安全性

  postfix具有多層防御結構,可以有效地抵御惡意入侵者。如大多數的postfix程序可以運行在較低的權限之下,不可以通過網絡訪問安全性相關的本地投遞程序等等。

  下面來介紹linux上如何搭建和配置postfix服務:

  1.關掉sendmail相關的所有服務,最好是直接卸載sendmail.

  # service sendmail stop

  # chkconfig sendmail off

  #rpm -qa | grep sendmail | xargs rpm -e

  2.安裝postfix.

  redhat6.0以上版本應該是默認集成了postfix服務的,假如沒有安裝的話,可以手動安裝。

  rpm -qa | grep postifx (查看是否安裝)

  yum install postfix

  3.安裝完成後,修改配置文件:/etc/postfix/main.cfg

  vi /etc/postfix/main.cf

  myhostname = sample.test.com  ← 設置系統的主機名

  mydomain = test.com  ← 設置域名(我們將讓此處設置將成為E-mail地址“@”後面的部分)

  myorigin = $mydomain  ← 將發信地址“@”後面的部分設置為域名(非系統主機名)

  inet_interfaces = all  ← 接受來自所有網絡的請求

  mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain  ← 指定發給本地郵件的域名

  home_mailbox = Maildir/  ← 指定用戶郵箱目錄

  <保存退出!>

  4.為本機添加DNS server.

  為什DNS Server?因為在郵件發送過程中,需要把郵件地址的domain地址轉化成IP地址,再去發送給對應的收件人,這裡涉及到DNS中的A記錄和MX記錄相關的知識,不熟悉的同學可以google或者百度 腦補一下 :-)

  如何添加DNS server呢,DNS server去哪裡尋找?

  vim /etc/resolv.conf

  添加如下行:

  nameserver 8.8.8.8

  nameserver 8.8.4.4

  上面用的8.8.8.8/8.8.4.4是Google Free DNS server,當然還有很多免費的DNS server供大家使用,可以google一下:-)

  5.測試一下郵件是否能夠發送成功

  命令行輸入$: > echo "Mail Content" | mail -s "Mail Subject" [email protected]

  Note:if you see below warings after you run above command.

  send-mail: warning: inet_protocols: IPv6 support is disabled: Address family not supported by protocol

  send-mail: warning: inet_protocols: configuring for IPv4 support only

  postdrop: warning: inet_protocols: IPv6 support is disabled: Address family not supported by protocol

  postdrop: warning: inet_protocols: configuring for IPv4 support only

  that means you don't have IPv6 configured in your OS's network stack, but your mailer (presumably postfix) is configured to use IPv6. Since there is no IPv6 for your mailer to use, it's warning you that it's only going to use IPv4.

  To disable the waring messsage, go to /etc/postfix/main.cf and change from:

  inet_protocols = all

  to:

  inet_protocols = ipv4

  This will only use ipv4 and the warning message will go away.

  You will have to issue a stop and start for postfix to register the change.

  service postfix restart

  6.查看log,確認郵件發送狀態:

  Postfix郵件的log位置是:/var/log/maillog

  發送成功的話,會返回250和OK,也可以去自己的郵件客戶端查收。

  一切OK的話,那Postfix mail service應該就搭建成功了。

  另外一些有用的postfix維護命令,一遍日常的檢測和維護:

  mailq :會列出當前在postfix發送隊列中的所有郵件

  postsuper -d ALL:刪除當前等待發送隊列的所有郵件,包括發送失敗的退信

  當然還有很多,就不一一列舉了,大家可以網上搜索擴展,Good Luck!

  7.Update Mail From sender

  echo "[email protected] [email protected]" >> /etc/postfix/generic

  echo "smtp_generic_maps = hash:/etc/postfix/generic" >>/etc/postfix/main.cf

  postmap /etc/postfix/generic

  service postfix restart

看過“Linux怎麼安裝配置Postfix”的人還看了:

Copyright © Linux教程網 All Rights Reserved