Hướng dẫn cài đặt server mail postfix năm 2024

# yum -y install perl perl-core wget screenw3m elinks openssh-clients openssh-server bind bind-utils unzip nmap sednc sysstat libaio rsync telnet aspell

Chỉnh sửa file named.conf

# nano /etc/named.conf

Thêm chữ 'any'

options { listen-on port 53 { 127.0.0.1;any; }; listen-on-v6 port 53 { ::1; }; directory "/var/named"; dump-file "/var/named/data/cache_dump.db"; statistics-file "/var/named/data/named_stats.txt"; memstatistics-file "/var/named/data/named_mem_stats.txt"; allow-query { localhost;any; }; recursion yes;

Tạo đoạn ở dưới cùng của file named.conf như sau

zone "maxserver.net" IN { type master; file "db.maxserver.net"; allow-update { none; }; };

Tạo 1 thư mục và thêm quyền sử dụng nhóm

# touch /var/named/db.maxserver.net # chgrp named /var/named/db.maxserver.net # nano /var/named/db.maxserver.net

Tạo nội dung như sau

$TTL 1D @ IN SOA ns1.maxserver.net. root.maxserver.net. ( 0 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H ) ; minimum @ IN NS ns1.maxserver.net. @ IN MX 0 mail.maxserver.net. ns1 IN A 107.189.160.7 mail IN A 107.189.160.7

Khởi động lại dịch vụ & Kiểm tra cấu hình kết quả của DNS Server

# service named restart # chkconfig named on

Dùng lệnh nslookup và dig để kiểm tra

# nslookup mail.maxserver.net

Server: 107.189.160.7 Address: 107.189.160.7

53

Name: mail.maxserver.net Address: 107.189.160.7

# dig maxserver.net mx

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.37.rc1.el6_7.6 <<>> maxserver.net mx ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 29090 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2

;; QUESTION SECTION: ;maxserver.net. IN MX

;; ANSWER SECTION: maxserver.net. 86400 IN MX 0 mail.maxserver.net.

;; AUTHORITY SECTION: maxserver.net. 86400 IN NS ns1.maxserver.net.

;; ADDITIONAL SECTION: mail.maxserver.net. 86400 IN A 107.189.160.7 ns1.maxserver.net. 86400 IN A 107.189.160.7

;; Query time: 0 msec ;; SERVER: 107.189.160.7

53(107.189.160.7)

;; WHEN: Tue Mar 15 23:16:50 2016 ;; MSG SIZE rcvd: 106

Tiến hành

1.Cài đăt postfix

Thường postfix đã đc cài dặt sẵn, nếu chưa có ta dùng lệnh

# yum install postfix -y

# nano /etc/postfix/main.cf

Ấn ctrl+w để tìm chữ

Tìm chữ 'myhostname' và thêm dòng sau

myhostname = host.domain.tld

myhostname = virtual.domain.tld

myhostname = mail.maxserver.net

Tìm chữ 'mydomain' và thêm dòng sau

mydomain = domain.tld

mydomain = maxserver.net

Tìm chữ 'myoirgin' và bỏ dấu '#' ở dòng sau

myorigin = $myhostname

myorigin = $mydomain

Tìm chữ 'inet_interfaces' và sửa các dòng như sau

inet_interfaces = all

inet_interfaces = $myhostname

inet_interfaces = $myhostname, localhost

inet_interfaces = localhost

# Enable IPv4, and IPv6 if supported inet_protocols = all

Tìm chữ 'mydestination' thêm dấu '#' và bỏ dấu '#' như sau

mydestination = $myhostname, localhost.$mydomain, localhost

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

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

# mail.$mydomain, www.$mydomain, ftp.$mydomain

Tìm chữ 'mynetworks' bỏ dấu'#' và sửa ip

mynetworks = 107.189.160.7, 127.0.0.0/8

mynetworks = $config_directory/mynetworks

mynetworks = hash:/etc/postfix/network_table

Tìm chữ 'home_mailbox' bỏ dấu '#'

home_mailbox = Mailbox

home_mailbox = Maildir/

Khởi động lại postfix và cho chạy cùng hệ thống

# service postfix restart # chkconfig postfix on

Kiểm tra postfix

Tạo user và đặt mật khẩu cho user đó

# useradd maxserver # passwd maxserver

Dùng lệnh telnet để kiểm tra kết nối # telnet localhost smtp

[root@mail ~]# telnet localhost smtp Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. 220 mail.maxserver.net ESMTP Postfix ehlo localhost (gõ lệnh này) 250-mail.maxserver.net.net 250-PIPELINING 250-SIZE 10240000 250-VRFY 250-ETRN 250-ENHANCEDSTATUSCODES 250-8BITMIME 250 DSN mail from: ( Địa chỉ email người gửi) 250 2.1.0 Ok rcpt to: (Địa chỉ email người nhận) 250 2.1.5 Ok data (Bắt đầu vào nội dung tin nhắn email) 354 End data with . test thanh cong (Nội dung tin nhắn email) . (Nội dung tin nhắn email kết thúc bằng dấu '.' ) 250 2.0.0 Ok: queued as EB82554E2 quit (lệnh thoát) 221 2.0.0 Bye Connection closed by foreign host.

Bây giờ điều hướng đến user "maxserver" thư mục mail và kiểm tra thư mới:

# ls /home/maxserver/Maildir/new/

root@mail ~]# ls /home/maxserver/Maildir/new/ 1459484457.Vfc01I209f3M150354.mail.maxserver.net.net

Một thư mới cho user "maxserver". Để đọc mail, nhập vào lệnh sau đây:

# cat /home/maxserver/Maildir/new/1459484457.Vfc01I209f3M150354.mail.maxserver.net.net

[root@mail ~]# cat /home/maxserver/Maildir/new/1459484457.Vfc01I209f3M150354.mail.maxserver.net.net Return-Path: <[email protected]> X-Original-To: maxserver Delivered-To: [email protected] Received: from localhost (localhost [127.0.0.1]) by mail.maxserver.net.net (Postfix) with ESMTP id EB82554E2 for ; Fri, 1 Apr 2016 00:19:24 -0400 (EDT) Message-Id: <[email protected]> Date: Fri, 1 Apr 2016 00:19:24 -0400 (EDT) From: [email protected] To: undisclosed-recipients:;

test thanh cong

2.Cài đặt dovecot

Dovecot là một mã nguồn mở IMAP và POP3 mail server cho các hệ thống Unix / Linux. Để cài đặt:

# yum install dovecot -y

Chỉnh sửa cấu hình dovecot

# nano /etc/dovecot/dovecot.conf

Tìm chữ 'Protocols' và bỏ dấu '#' ở dòng sau

# Protocols we want to be serving. protocols = imap pop3 lmtp

# nano /etc/dovecot/conf.d/10-mail.conf

Tìm chữ 'mail_location' và bỏ dấu '#' ở dòng sau

# See doc/wiki/Variables.txt for full list. Some examples:

mail_location = maildir:~/Maildir # mail_location = mbox:~/mail:INBOX=/var/mail/%u # mail_location = mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%n

# nano /etc/dovecot/conf.d/10-auth.conf

Tìm chữ 'disable_plaintext_auth' và bỏ dấu '#'

# Disable LOGIN command and all other plaintext authentications unless # SSL/TLS is used (LOGINDISABLED capability). Note that if the remote IP # matches the local IP (ie. you're connecting from the same computer), the # connection is considered secure and plaintext authentication is allowed. disable_plaintext_auth = yes

Tìm chữ 'auth_mechanisms' thêm chữ 'login' vào dòng đó

# Space separated list of wanted authentication mechanisms: # plain login digest-md5 cram-md5 ntlm rpa apop anonymous gssapi otp skey # gss-spnego # NOTE: See also disable_plaintext_auth setting. auth_mechanisms = plain login

# nano /etc/dovecot/conf.d/10-master.conf

Tìm chữ 'mode = 0600' bỏ dấu '#' và thêm user = postfix , group = postfix

unix_listener auth-userdb {

mode = 0600

user = postfix group = postfix }

Khởi động dovecot và cho chạy cùng hệ thống

# service dovecot start # chkconfig dovecot on

Kiểm tra dovecot

# telnet localhost pop3​

[root@mail ~]# telnet localhost pop3 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. +OK Dovecot ready. user maxserver (đăng nhập user maxserver) +OK pass matkhau (mật khẩu của usre maxserver là matkhau) +OK Logged in. retr 1 +OK 475 octets Return-Path: <[email protected]> X-Original-To: maxserver Delivered-To: [email protected] Received: from localhost (localhost [127.0.0.1]) by mail.maxserver.net (Postfix) with ESMTP id EB82554E2 for ; Fri, 1 Apr 2016 00:19:24 -0400 (EDT) Message-Id: <[email protected]> Date: Fri, 1 Apr 2016 00:19:24 -0400 (EDT) From: [email protected] To: undisclosed-recipients:;

test thanh cong . quit +OK Logging out. Connection closed by foreign host.

3.Cài đặt squirrelmail

Cài đặt SquirreMail sử dụng lệnh sau đây:

# yum install squirrelmail -y

Điều hướng đến thư mục / usr / share / SquirreMail / config / và chạy lệnh conf.pl lệnh:

# cd /usr/share/squirrelmail/config/ # ./conf.pl

Trình hướng dẫn sau đây sẽ mở ra. Nhập lựa chọn "1" để thiết lập chi tiết tổ chức của bạn:

[root@mail ~]# cd /usr/share/squirrelmail/config/ [root@mail config]# ./conf.pl SquirrelMail Configuration : Read: config.php (1.4.0) --------- Main Menu -- 1. Organization Preferences 2. Server Settings 3. Folder Defaults 4. General Options 5. Themes 6. Address Books 7. Message of the Day (MOTD) 8. Plugins 9. Database 10. Languages

  1. Set pre-defined settings for specific IMAP servers

C Turn color off S Save data Q Quit

Command >> 1

Trình hướng dẫn sau đây sẽ mở ra. Nhập "1" một lần nữa thay đổi các chi tiết tổ chức của bạn:

SquirrelMail Configuration : Read: config.php (1.4.0) ---------Organization Preferences 1.  Organization Name      : SquirrelMail 2.  Organization Logo      : ../images/sm_logo.png 3.  Org. Logo Width/Height : (308/111) 4.  Organization Title     : SquirrelMail $version 5.  Signout Page           : 6.  Top Frame              : _top 7.  Provider link          : 8.  Provider name          : SquirrelMail R   Return to Main Menu C   Turn color off S   Save data Q   Quit Command >> 1

Đặt tên Organization của bạn và nhấn Enter:

We have tried to make the name SquirrelMail as transparent as possible. If you set up an organization name, most places where SquirrelMail would take credit will be credited to your organization.

If your Organization Name includes a '$', please precede it with a \. Other '$' will be considered the beginning of a variable that must be defined before the $org_name is printed. $version, for example, is included by default, and will print the string representing the current SquirrelMail version.

[SquirrelMail]: maxserver

Bằng cách này, thiết lập tất cả các chi tiết như tên tổ chức, logo, tên nhà cung cấp trong chương trình trên. Khi bạn làm xong, nhấn "S" để lưu các thay đổi và nhấn "R" để trở lại menu chính của bạn: