Bài hướng dẫn này sẽ giới thiệu đến các bạn cách setup một local mail server sử dụng Postfix, hoặc Dovecot hoặc Squirrelmail trên nền tảng CentOS 7. Và ở nội dung bài lab này, chúng ta chỉ setup “ local mail server “. Bạn sẽ không thể dùng mail server này để gửi hoặc nhận mail ra ngoài giống Yahoo Mail hoặc Gmail. Để gửi hoặc nhận mail ra ngoài, bạn cần cấu hình mail server với một IP Public, yêu cầu ISP cấu hình MX Record của mail server của bạn trên DNS của họ.
Bài Lab được thực hiện trên hệ điều hành CentOS 64 bit. Trước tiên chúng ta cần chuẩn bị hệ thống máy :
- Hệ điều hành : CentOS 7 64bit minimal server
- Địa chỉ IP : 192.168.1.150/24
- Hostname : server1.anninhmang.local
Nào chúng ta cùng bắt đầu.
- Đầu tiên, chúng ta cần phải remove bất kì MTA ( Mail Transfer Agent ) nào đang có sẵn trên máy. Với bản minimal thì mặc định sendmail không được cài đặt sẵn, vì vậy bạn có thể bỏ qua bước này.
yum remove sendmail
- Cấu hình DNS Server, để add MX Record của Mail Server vào forward và reverse zone. Xem cách cấu hình DNS Server tại đây. Và đừng quên hỏi ISP của bạn để trỏ IP mặt ngoài vào mail domain.
3. Add thêm các thông tin vào file /etc/hosts :
vi /etc/hosts
Add tên miền đầy đủ ( FQDN )
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.150 server1.anninhmang.local server1
- Tiếp tục Disable SELinux để giảm độ phức tạp cấu hình postfix.
Sử dụng lệnh :
vi /etc/sysconfig/selinux
Đổi SELINUX=enforcing thành SELINUX=disabled
SELINUX=disabled
- Cài đặt Repel Repository :
Squirrelmail webmail client không có sẵn trên các repository của CentOS. Vì vậy chúng ta cần enable EPEL repository :
yum install epel-release
- Mở port Apache cổng 80 trên firewall/router :
firewall-cmd –permanent –add-port=80/tcp
Sử dụng lệnh Restart Firewall :
firewall-cmd –reload
Tiến hành restart server để toàn bộ thay đổi có hiệu lực.
Cài đặt Postfix :
Postfix là một chương trình mail transfer agent miễn phí ( MTA ), opensource và hoàn toàn miễn phí. Chương trình có tốc độ nhanh, bảo mật và dễ quản trị. Trên hệ điều hành Red Hat, đây là MTA mặc định.
Tiến hành cài đặt Postfix sử dụng lệnh :
yum install postfix
Cấu hình Postfix :
Edit file /etc/postfix/main.cf :
vi /etc/postfix/main.cf
Tìm và chỉnh sửa những dòng sau :
## Line no 77 – Bỏ comment và đặt lại FQDN ##
myhostname = server1.anninhmang.local
## Line 85 – Bỏ comment và Set domain name ##
mydomain = anninhmang.local
## Line 101 – Bỏ comment ##
myorigin = $mydomain
## Line 115 – Bỏ comment và Set ipv4 ##
inet_interfaces = all
## Line 121 – chuyển thành all ##
inet_protocols = all
## Line 166 – Comment ##
#mydestination = $myhostname, localhost.$mydomain, localhost,
## Line 167 – Bỏ comment ##
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
## Line 266 – Bỏ comment và add IP range ##
mynetworks = 192.168.1.0/24, 127.0.0.0/8
## Line 421 – Bỏ comment ##
home_mailbox = Maildir/
Lưu và thoát file.
Start/ Restart dịch vụ Postfix :
systemctl enable postfix
systemctl restart postfix
Tiến hành Test Mail server Postfix :
Đầu tiên, tạo user với tên “sk” :
useradd sk
Set Password cho user :
passwd sk
Truy cập Server thông qua Telnet và nhập lệnh thủ công :
telnet localhost smtp
Lưu ý nếu máy không truy cập được Telnet thì chúng ta cần tiến hành cài thêm Telnet.
Kết quả trả về :
Trying ::1…
Connected to localhost.
Escape character is ‘^]’.
220 server1.anninhmang.local ESMTP Postfix
ehlo localhost ## nhập dòng này ##
250-server1.anninhmang.local
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from:<sk> ## nhập vào địa chỉ mail gửi ##
250 2.1.0 Ok
rcpt to:<sk> ## nhập vào địa chỉ mail nhận##
250 2.1.5 Ok
data ## nhập vào để chuyển đến nội dung của mail ##
354 End data with <CR><LF>.<CR><LF>
Welcome to anninhmang mail server ## nội dung của mail ##
. ## đặt dấu (.) sau khi hoàn thành email ##
250 2.0.0 Ok: queued as E2B522032F93
quit ## Gõ quit để thoát khỏi trình soạn##
221 2.0.0 Bye
Connection closed by foreign host.
Tiếp theo chuyển sang hộp thư của user sk để kiểm tra xem mail đã được chuyển đến chưa.
ls /home/sk/Maildir/new/
Kết quả trả về :
1437722056.Vfd01I203e3e7M938078.server1.anninhmang.local
Như vậy là chúng ta đã gửi nhận mail thành công với user “ sk ”.
Để đọc mail, nhập lệnh :
cat/home/sk/Maildir/new/1437722056.Vfd01I203e3e7M938078.server1.anninhmang.local
Kết quả trả về :
Return-Path: <[email protected]>
X-Original-To: sk
Delivered-To: [email protected]
Received: from localhost (localhost [IPv6:::1])
by server1.anninhmang.local (Postfix) with ESMTP id E2B522032F93
for <sk>; Fri, 24 Jul 2015 12:42:36 +0530 (IST)
Message-Id: <[email protected]>
Date: Fri, 24 Jul 2015 12:42:36 +0530 (IST)
From: [email protected]
Welcome to anninhmang mail server
Done. Như vậy là chúng ta đã hoàn thành cài đặt và cấu hình, gửi nhận mail thành công trên Postfix.
Cài đặt Dovecot :
Dovecot cũng là chương trình Open Source mail server POP3 và IMAP dùng cho hệ thống Linux/Unix System.
Để cài đặt, chạy dòng lệnh :
yum install dovecot
Cấu hình Dovecot :
Edit file /etc/dovecot/dovecot.conf :
vi /etc/dovecot/dovecot.conf
Bỏ comment những dòng sau :
## Line 24 – bỏ comment ##
protocols = imap pop3 lmtp
Edit file /etc/dovecot/conf.d/10-mail.conf :
vi /etc/dovecot/conf.d/10-mail.conf
Thay đổi dòng :
## Line 24 – bỏ comment ##
mail_location = maildir:~/Maildir
Edit file /etc/dovecot/conf.d/10-auth.conf :
vi /etc/dovecot/conf.d/10-auth.conf
Thay đổi những dòng sau :
## line 10 – bỏ comment##
disable_plaintext_auth = yes
## Line 100 – thêm từ: “login” ##
auth_mechanisms = plain login
Edit file /etc/dovecot/conf.d/10-master.conf :
vi /etc/dovecot/conf.d/10-master.conf
Tiến hành thay đổi dòng :
## Line 91, 92 – bỏ comment và thêm “postfix”
#mode = 0600
user = postfix
group = postfix
[…]
Tiến hành dịch vụ Dovecot :
systemctl enable dovecot
systemctl start dovecot
Test Dovecot service :
Nhập lệnh telnet :
telnet localhost pop3
Thêm lần lượt những dòng lệnh khu vực được tô đậm :
Trying ::1…
Connected to localhost.
Escape character is ‘^]’.
+OK Dovecot ready.
user sk ## nhập vào mail username ##
+OK
pass centos ## nhập vào password ##
+OK Logged in.
retr 1 ## nhập lệnh để xem mail ##
+OK 415 octets
Return-Path: <[email protected]>
X-Original-To: sk
Delivered-To: [email protected]
Received: from localhost (localhost [IPv6:::1])
by server1.anninhmang.local (Postfix) with ESMTP id E2B522032F93
for <sk>; Fri, 24 Jul 2015 12:42:36 +0530 (IST)
Message-Id: <[email protected]>
Date: Fri, 24 Jul 2015 12:42:36 +0530 (IST)
From: [email protected]
Welcome to anninhmang mail server
.
quit ## Type ‘quit’ to exit ##
+OK Logging out.
Connection closed by foreign host.
Với kết quả bên trên, Dovecot đã hoạt động.
Install Squirrelmail :
Đối với người dùng bình thường, thì việc gửi và nhận mail bằng command line xem ra rất khó khăn. Sẽ dễ dàng hơn cho họ nếu có giao diện đồ họa. Squirrelmail được xem là giải pháp hoàn hảo khắc phục những nhược điểm của việc gửi nhận mail bằng command line.
Trước tiên, đảm bảo rằng bạn đã cài đặt và enable EPEL repository.
Sau đó, cài đặt Squirrelmail bằng dòng lệnh :
yum install squirrelmail
Cấu hình Squirrelmail :
Di chuyển đến thư mục /usr/share/squirrelmail/config/
cd /usr/share/squirrelmail/config/
và chạy dòng lệnh để mở và cấu hình Squirrelmail :
./conf.pl
Bảng lựa chọn sẽ hiển thị, nhấn phím “1” để thiết lập chi tiết :
SquirrelMail Configuration : Read: config.php (1.4.0)
———————————————————
Main Menu —
- Organization Preferences
- Server Settings
- Folder Defaults
- General Options
- Themes
- Address Books
- Message of the Day (MOTD)
- Plugins
- Database
- Languages
- Set pre-defined settings for specific IMAP servers
C Turn color off
S Save data
Q Quit
Command >> 1
Bảng Wizard kế tiếp sẽ hiển thị, chọn “ 1 “ tiếp tục để thiết lập thông tin tổ chức :
SquirrelMail Configuration : Read: config.php (1.4.0)
———————————————————
Organization Preferences
- Organization Name : SquirrelMail
- Organization Logo : ../images/sm_logo.png
- Org. Logo Width/Height : (308/111)
- Organization Title : SquirrelMail $version
- Signout Page :
- Top Frame : _top
- Provider link : http://squirrelmail.org/
- Provider name : SquirrelMail
R Return to Main Menu
C Turn color off
S Save data
Q Quit
Command >> 1
Đặt tên tổ chức của bạn và chọ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]: anninhmang
Tương tự, thiết lập tiếp các thông tin khác như Title, Logo, nhà cung cấp tên miền ở bảng bên dưới. Một khi đã hoàn thành, bấm nút “ S “ để lưu lại thay đổi, và bấm “ R “ để trở về menu chính :
SquirrelMail Configuration : Read: config.php (1.4.0)
———————————————————
Organization Preferences
- Organization Name : anninhmang
- Organization Logo : ../images/sm_logo.png
- Org. Logo Width/Height : (308/111)
- Organization Title : SquirrelMail $version
- Signout Page :
- Top Frame : _top
- Provider link : http://squirrelmail.org/
- Provider name : anninhmang Mail
R Return to Main Menu
C Turn color off
S Save data
Q Quit
Command >> S
Tiếp theo, bấm “ 2 “ , để setup cho mail server các thông số như domain name, mail agent…
SquirrelMail Configuration : Read: config.php (1.4.0)
———————————————————
Main Menu —
- Organization Preferences
- Server Settings
- Folder Defaults
- General Options
- Themes
- Address Books
- Message of the Day (MOTD)
- Plugins
- Database
- Languages
- Set pre-defined settings for specific IMAP servers
C Turn color off
S Save data
Q Quit
Command >> 2
Chọn “ 1 “, nhập vào domain name của bạn ( VD : anninhmang.local ), và bấm Enter :
SquirrelMail Configuration : Read: config.php (1.4.0)
———————————————————
Server Settings
General
——-
- Domain : localhost
- Invert Time : false
- Sendmail or SMTP : Sendmail
- Update IMAP Settings : localhost:143 (uw)
- Change Sendmail Config : /usr/sbin/sendmail
R Return to Main Menu
C Turn color off
S Save data
Q Quit
Command >> 1
The domain name is the suffix at the end of all email addresses. If
for example, your email address is [email protected], then your domain
would be example.com.
[localhost]: anninhmang.local
Chọn “ 3 “ để chuyển từ Sendmail sang Postfix MTA :
SquirrelMail Configuration : Read: config.php (1.4.0)
———————————————————
Server Settings
General
——-
- Domain : anninhmang.local
- Invert Time : false
- Sendmail or SMTP : Sendmail
- Update IMAP Settings : localhost:143 (uw)
- Change Sendmail Config : /usr/sbin/sendmail
R Return to Main Menu
C Turn color off
S Save data
Q Quit
Command >> 3
Nhấn “ 2 “ để chuyển từ sendmail MTA sang Postfix :
You now need to choose the method that you will use for sending
messages in SquirrelMail. You can either connect to an SMTP server
or use sendmail directly.
- Sendmail
- SMTP
Your choice [1/2] [1]: 2
Xong chúng ta nhấn “ S “ tiếp theo là “ Q “ để save và exit bảng cấu hình Squirrelmail.
Tạo một squirrelmail vhost trong file httpd.conf
vi /etc/httpd/conf/httpd.conf
tại cuối file, thêm vào những dòng này :
Alias /webmail /usr/share/squirrelmail
<Directory /usr/share/squirrelmail>
Options Indexes FollowSymLinks
RewriteEngine On
AllowOverride All
DirectoryIndex index.php
Order allow,deny
Allow from all
</Directory>
Restart lại Apache Server :
systemctl restart httpd
Tạo mail user :
Chúng ta cần tạo user để test thử mail server. Ở đây người viết tạo 2 user “senthil“ và “kumar“.
useradd senthil
passwd senthil
useradd kumar
passwd kumar
Truy cập Webmail :
Vào trình duyệt gõ http://ip-address/webmail hoặc http://domain-name/webmail :
Trang đăng nhập sẽ hiển thị. Nhập vào Username và Password của User mà chúng ta đã tạo ở trên :
Vậy là bây giờ bạn đã có thể truy cập được vào mail box :
Gửi thử mail :
Chúng ta sẽ tiến hành gửi mail từ user “senthil“ đến User “kumar“. Click vào link Compose ở trên đầu menu. Nhập vào địa chỉ Mail nhận ([email protected]), tạo nội dung, chủ đề cho mail và gửi.
Tiếp theo, log out khỏi user “senthil“ và Logon vào user “kumar“ để check mail đã đến chưa.
Như đã thấy, vậy là đã có mail từ user [email protected] nằm trong inbox
Để đọc mail, bấm vào nó. Chúng ta có thể đọc, trả lời, xóa, hoặc gửi một mail mới.
Như vậy là chúng ta đã hoàn thành xong việc cài đặt và cấu hình gửi nhận mail trên hệ điều hành CentOS 7. Mail server này sẽ phục vụ cho việc gửi nhận mail của User trong hệ thống mạng Lan. Hy vọng bài viết sẽ giúp ích được cho bạn.
- cài mail server trên centos
- cài mail server cho localhost
- cài đặt mail server
- cài đặt mail server trên centos 7
- cài đặt mail server nội bộ
- mail server free
- mail server postfix dovecot squirrelmail
- mail server postfix centos 7