Mail Server
Mail Server
Mail Server
Note :
- Change IP Address with Your IP
- Change debian with Your Hostname
- Change linux.vmw with Your Domain
- Change debian.linux.vmw with Your FQDN Hostname
- Change /bkup with Your Directory
- Change **** with Your Password
cp /etc/hostname /bkup/hostname.ori
debian.linux.vmw
cp /etc/hosts /bkup/hosts.ori
sudo reboot
OK
Internet Site
cp /etc/default/spamassassin /bkup/spamassassin.ori
ENABLED=1
cp /etc/spamassassin/local.cf /bkup/local.cf.ori
10. Add clamav user to the amavis group and vice versa
cp /etc/amavis/conf.d/15-content_filter_mode /bkup/15-content_filter_mode.ori
@bypass_virus_checks_maps = ( \%bypass_virus_checks,
\@bypass_virus_checks_acl, \
$bypass_virus_checks_re);@bypass_spam_checks_maps = ( \
%bypass_spam_checks, \@bypass_spam_checks_acl, \
$bypass_spam_checks_re);
cp /etc/amavis/conf.d/20-debian_defaults /bkup/20-debian_defaults.ori
$final_spam_destiny = D_DISCARD;
cp /etc/amavis/conf.d/50-user /bkup/50-user.ori
@local_domains_acl = ( ".$mydomain" );
cp /etc/postfix/main.cf /bkup/main.cf.ori
1. Add
2. Edit
smtpd_tls_cert_file = /etc/postfix/ssl/smtpd.crtsmtpd_tls_key_file
= /etc/postfix/ssl/smtpd.keyrelayhost =
[smtp.gmail.com]:587mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104
[::1]/128 192.168.44.0/24 18.18.18.0/24 88.88.88.0/24
cp /etc/postfix/master.cf /bkup/master.cf.ori
[smtp.gmail.com]:587 steve.van.christie@gmail.com:*****
cd /etc/postfix/ssl/
sudo openssl genrsa -des3 -rand /etc/hosts -out smtpd.key 1024
sudo openssl x509 -req -days 3650 -in smtpd.csr -signkey smtpd.key -out
smtpd.crt
cp /etc/dovecot/dovecot.conf /bkup/dovecot.conf.ori
sudo vim /etc/dovecot/dovecot.conf
cp /etc/default/saslauthd /bkup/saslauthd.ori
START=yes
Include /etc/squirrelmail/apache.conf
cp /etc/php5/apache2/php.ini /bkup/php.ini.ori
sudo vim /etc/php5/apache2/php.ini
cp /etc/apache2/apache2.conf /bkup/apache2.conf.ori
sudo vim /etc/apache2/apache2.conf
or http://192.168.44.9/squirrelmail
telnet localhost 25
ehlo localhost
quit
0 logout
quit
ehlo localhost
quit
This tutorial describes how to set up a mail server where Postfix is the SMTP service, and Dovecot
provides IMAP and POP services. The users are virtual and user information is stored in a MySQL
database.
Pre-Configuration Requirements:
1. Hostname cnode1.rnd.pk with IP address (172.16.4.80) to eth0. (You can assign an IP address and
hostname of your choice.)
2. Create an alias eth0:0. Assign IP address (172.16.4.81). (You can assign an IP address of your
choice.)
1. First install dovecot. If you install postfix before dovecot, then dovecot will not be installed on
your system because of packages conflicts.
This will install dovecot along with dependencies (mysql and postgresql).
2. Then install postfix (with mysql support) and and mysql-server-5 from centosplus repos.
This will install postfix along with dependencies mysql-5 and postgresql. Our installation section is
complete now. Moving to our next section i.e. Configuration.
Configuration:
SMTP-AUTH/TLS
First we configure SMTP-AUTH and TLS. For this edit /usr/lib/sasl2/smtpd.conf with your
favorite editor.
vi /usr/lib/sasl2/smtpd.conf
and make changes as given below.
pwcheck_method: saslauthd
mech_list: plain login
Create directories, then private key and lastly the certificate.
mkdir -p /etc/ssl/mycompany/mailserver/
cd /etc/ssl/mycompany/mailserver/
openssl x509 -req -days 3650 -in smtpd.csr -signkey smtpd.key -out smtpd.crt
mv -f smtpd.key.unencrypted smtpd.key
openssl req -new -x509 -extensions v3_ca -keyout cakey.pem -out cacert.pem -days 3650
Private keys and certificates have been created. Later on we will tell postfix to use them.
MySQL:
We will now create a database named mail, for this we will issue commands given below; our first
step will be to set a password for the administrative user.
Replace newpassword phrase with your password. We will use user "mail" in our case for all
database related operations. (Select Update and Insert into Database.)
mysql -u root -p
Enter the password and you will be at the MySQL prompt (mysql>)
FLUSH PRIVILEGES;
quit
Set password for mail user. This will be done by the following statement.
mysql -u mail -p
show databases;
It will show all databases, including our "mail" database. We will use "mail".
USE mail;
CREATE TABLE domain ( domain varchar(255) NOT NULL default '', description varchar(255) NOT
NULL default '', aliases int(10) NOT NULL default '0', mailboxes int(10) NOT NULL default '0',
maxquota int(10) NOT NULL default '0', transport varchar(255) default NULL, backupmx tinyint(1)
NOT NULL default '0', created datetime NOT NULL default '0000-00-00 00:00:00', modified datetime
NOT NULL default '0000-00-00 00:00:00', active tinyint(1) NOT NULL default '1', PRIMARY KEY
(domain), KEY domain (domain) ) TYPE=MyISAM COMMENT=' Virtual Domains';
CREATE TABLE mailbox ( username varchar(255) NOT NULL default '', password varchar(255) NOT
NULL default '', name varchar(255) NOT NULL default '', maildir varchar(255) NOT NULL default '',
quota int(10) NOT NULL default '0', domain varchar(255) NOT NULL default '', created datetime NOT
NULL default '0000-00-00 00:00:00', modified datetime NOT NULL default '0000-00-00 00:00:00',
active tinyint(1) NOT NULL default '1', PRIMARY KEY (username), KEY username (username) )
TYPE=MyISAM COMMENT='Virtual Mailboxes';
CREATE TABLE alias ( address varchar(255) NOT NULL default '', goto text NOT NULL, domain
varchar(255) NOT NULL default '', created datetime NOT NULL default '0000-00-00 00:00:00',
modified datetime NOT NULL default '0000-00-00 00:00:00', active tinyint(1) NOT NULL default '1',
PRIMARY KEY (address), KEY address (address) ) TYPE=MyISAM COMMENT='Virtual Aliases';
quit
Postfix MySQL:
Postfix needs to know where and how it can look up all mailbox related information. For this
purpose we will create the following files under /etc/postfix. Recent versions of Postfix may use that
instead of the other statements, and in that case, just comment all lines out, and un-comment the
last one.
1. Create file mysql_virtual_alias_maps.cf for forwarding emails from one email address to another
vi /etc/postfix/mysql_virtual_alias_maps.cf
user = mail
password = mail
hosts = localhost
dbname = mail
table = alias
select_field = goto
where_field = address
additional_conditions = and active = '1'
#query = SELECT goto FROM alias WHERE address='%s' AND active = '1'
2. Create file mysql_virtual_domains_maps.cf, for the virtual domains mapping. Virtual domains are
queried using information provided in this file.
vi /etc/postfix/mysql_virtual_domains_maps.cf
user = mail
password = mail
hosts = localhost
dbname = mail
table = domain
select_field = domain
where_field = domain
additional_conditions = and backupmx = '0' and active = '1'
#query = SELECT domain FROM domain WHERE domain='%s' AND backupmx = '0' AND
active = '1'
3. Create the file mysql_virtual_mailbox_maps.cf. Which is usually the mapping of email addresses
to the location of the user's mailbox on your hard disk. If you saved incoming email to the hard disk
using Postfix' built-in virtual delivery agent then it would be queried to find out the mailbox path.
vi /etc/postfix/mysql_virtual_mailbox_maps.cf
user = mail
password = mail
hosts = localhost
dbname = mail
table = mailbox
select_field = CONCAT(domain,'/',maildir)
where_field = username
additional_conditions = and active = '1'
#query = SELECT CONCAT(domain,'/',maildir) FROM mailbox WHERE username='%s'
AND active = '1'
4. Lastly create file mysql_virtual_mailbox_limit_maps.cf which will be used for mapping users
mailboxes quota limit.
vi /etc/postfix/mysql_virtual_mailbox_limit_maps.cf
user = mail
password = mail
hosts = localhost
dbname = mail
table = mailbox
select_field = quota
where_field = username
additional_conditions = and active = '1'
#query = SELECT quota FROM mailbox WHERE username='%s' AND active = '1'
Postfix:
In the Postfix configuration section we will edit the main.cf file located in configuration directory of
postfix (/etc/postfix), to enter some basic information necessary for Postfix.
mv /etc/postfix/main.cf /etc/postfix/main.cf.orig
vi /etc/postfix/main.cf
############## Postfix###############
smtpd_banner = $myhostname
biff = no
append_dot_mydomain = no
relayhost =
mynetworks = 172.16.4.81
inet_interfaces = 172.16.4.81
mailbox_size_limit = 0
recipient_delimiter = +
alias_database = hash:/etc/postfix/aliases
alias_maps = $alias_database
myhostname = cnode1.rnd
mydomain = rnd
myorigin = $myhostname
mydestination = $myhostname, localhost.$mydomain, $transport_maps
mail_spool_directory = /var/spool/mail
debug_peer_level = 2
debugger_command =
PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
xxgdb $daemon_directory/$process_name $process_id & sleep 5
disable_vrfy_command = no
readme_directory = /usr/share/doc/postfix-2.2.10/README_FILES
sample_directory = /usr/share/doc/postfix-2.2.10/samples
sendmail_path = /usr/sbin/sendmail
html_directory = no
setgid_group = postdrop
command_directory = /usr/sbin
manpage_directory = /usr/share/man
daemon_directory = /usr/libexec/postfix
newaliases_path = /usr/bin/newaliases
mailq_path = /usr/bin/mailq
queue_directory = /var/spool/postfix
mail_owner = postfix
unknown_local_recipient_reject_code = 450
####################postfix section ends here###############
Postfix Virtual user information:
Again we will edit main.cf file to add support for virtual users. The “virtual_minimum_uid” and
“virtual_uid_maps” point to user id 150 in my case, which is a user I created specifically for handling
virtual mail. It uses the standard “mail” group with the default gid 12. So first create the user by
issuing the useradd command or adduser.
vi /etc/postfix/main.cf
vi /etc/postfix.main.cf
cp /etc/aliases* /etc/postfix/
newaliases
vi /etc/dovecot-mysql.conf
mv /etc/dovecot.conf /etc/dovecot.conf.orig
vi /etc/dovecot.conf
Squirrelmail configuration:
Go to squirrelmail config directory and run config.pl.
cd /usr/share/squirrelmail/config/
/conf.pl
Main Menu --
1. Organization Preferences
2. Server Settings
3. Folder Defaults
4. General Options
5. Themes
6. Address Books
8. Plugins
9. Database
10. Languages
C.Turn color on
S Save data
Save your settings and return to the main menu. Now at the command prompt type 2, and in server
settings menu provide information.
1. Domain : mail.rnd
Configuring squirrelmail is very easy as it is menu driven. Hope you will do it yourself.
HTTP Section:
To start using the mailserver web front end we will edit file /etc/httpd/conf/httpd.conf.
vi /etc/httpd/conf/httpd.conf
<VirtualHost 172.16.4.81:80>
DocumentRoot /usr/share/squirrelmail
ServerName mail.rnd
</VirtualHost>
Save the configuration and exit.
Creating Virtual users and domains:
Now we will create virtual domains and virtual users in our mail database.
mysql -u mail -p
USE mail;
First create a virtual domain in the domain table (mail.rnd) using the command given below.
Now create two virtual users in the mailbox table. I have created (mike@mail.rnd & john@mail.rnd)
as usernames for mike and john.
quit
Now that we have created virtual users and virtual domain, we want to test our mail server by
logging in and sending mail from one user account to another. So let's start Dovecot, Postfix, MySQL
and webserver daemons. Also we want that they should start themselves on next reboot. For this we
issue following commands.
/etc/init.d/saslauthd start
/etc/init.d/mysqld start
/etc/init.d/postfix start
/etc/init.d/dovecot start
/etc/init.d/httpd start
Finally fire-up the browser and go to http://mail.rnd and enter the username and password and then
click on Login. And enjoy playing with your mailserver.
phpMyAdmin:
phpMyAdmin is a powerful and easy to use frontend for MySQL. The rpm of phpMyAdmin exists in
the DAG repository. Go and add DAG repository. And install phpmyadmin and php-mysql if not
already installed.
After this fire up a browser and enter http://127.0.0.1 in the address bar. Enter the user name and
password and start using it. /etc/httpd/conf.d/phpmyadmin.conf has the information to locate
phpmyadmin. If it fails you can create a virual alias in /etc/httpd/conf/httpd.conf file by editing it.
vi /etc/httpd/conf/httpd.conf
<VirtualHost 127.0.0.1>
DocumentRoot /usr/share/phpmyadmin
ServerName localhost.localdomin
</VirtualHost>
Enjoy using phpMyAdmin for creating users, domain and aliases.
Postfix Mailserver Virtual dengan Authentikasi User
Mysql Debian Etch
Postfix Mailserver Virtual dengan Authentikasi User
Mysql Debian Etch
Filed under: Linux, Network by ujangawaludin — 3 Comments
June 23, 2008
Ini adalah tugas Pertamaku saat menjadi Network Engineer di Perusahaan dimana aku
bekerja sekarang, agak ribet siih tapi untungnya ada mbah google yang bantu. langsung aja ya
pren
TO mailuser@localhost
IDENTIFIED BY ‘password′;
) ENGINE = InnoDB;
) ENGINE = InnoDB;
) ENGINE = InnoDB;
virtual_users.password
FROM virtual_users
destination
FROM virtual_aliases
user = mailuser
password = password
hosts = 127.0.0.1
dbname = mailserver
user = mailuser
password = password
hosts = 127.0.0.1
dbname = mailserver
user = mailuser
password = password
hosts = 127.0.0.1
dbname = mailserver
user = mailuser
password = password
hosts = 127.0.0.1
dbname = mailserver
postconf -e virtual_mailbox_domains=mysql:/etc/postfix/mysql-virtual-mailbox-domains.cf
postconf -e virtual_mailbox_maps=mysql:/etc/postfix/mysql-virtual-mailbox-maps.cf
postconf -e virtual_alias_maps=mysql:/etc/postfix/mysql-virtual-alias-
maps.cf,mysql:/etc/postfix/mysql-email2email.cf
postconf -e virtual_transport=dovecot
postconf -e dovecot_destination_recipient_limit=1
postconf -e virtual_uid_maps=static:5000
postconf -e virtual_gid_maps=static:5000
groupadd -g 5000 vmail
useradd -g vmail -u 5000 vmail -d /home/vmail -m
chgrp postfix /etc/postfix/mysql-*.cf
chmod u=rw,g=r,o= /etc/postfix/mysql-*.cf
5. edit file pada /etc/postfix/master.cf
dovecot unix – n n – - pipe
flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/deliver -d ${recipient}
smtpd_client_restrictions =
permit_mynetworks
permit_sasl_authenticated
reject_unauth_pipelining
hopcount_limit = 10000
delay_notice_recipient = postmaster@example.com
bounce_notice_recipient = postmaster@example.com
2bounce_notice_recipient = postmaster@example.com
error_notice_recipient = postmaster@example.com
qmgr_message_recipient_limit = 50000
default_process_limit = 100000
default_destination_recipient_limit = 20
default_destination_concurrency_limit = 1000
luser_relay = postmaster@example.com
message_size_limit = 2048000
header_size_limit = 2048
bounce_size_limit = 500000
line_length_limit = 2048000
Instalasi aplikasi di server linux memang memiliki kesulitan tersendiri. Kalau pun kita
sudah “pernah”, pas dicoba 1x lagi pada distro yang berbeda atau walau cuma beda
versi, belum tentu hasilnya sama.
Pertama kali saya melakukan instalasi mail server adalah 2 tahun lalu saya melakukan
instalasi mail server diatas OS Linux Fedora 9, cara mudahnya adalah dengan cara copas dari
berbagai tutorial yang saya termukan di internet. Alhasil, setelah 1 minggu usah, punya juga
mail server. Sekarang, saya coba lagi melakukan yang sama pada Fedora 14. Cara praktisnya
adalah copas konfigurasi server lama ke server baru. Tapi ternyata … memang tidak semudah
yang dikira. Beberapa perbedaan versi pada aplikasi yang dipakai menjadikannya perlu
ada adaptasi agar konfigurasi lama yang saya pakai bisa digunakan kembali.
Berikut adalah beberapa catatan yang saya buat pada saat melakukan konfigurasi Mail Server
dengan Multiple Domain (Virtual Domain) di Linux.
Jika Anda pernah melakukan instalasi email server menggunakan MS Exchange Server,
semuanya mudah. 1 program untuk seluruh keperluan. Berbeda dengan Linux, Mail Server
terdiri dari program yang terpisah. Dengan demikian, untuk bisa memahaminya tentunya
harus mengetahui fungsi masing-masing program yang digunakan.
POSTFIX
POSTFIX adalah program yang berfungsi menerima dan mengirim email.
instalasi modul yang diperlukan untuk POSTFIX adalah:
yum install postfix
berikut adalah initial setting untuk POSTFIX yang saya gunakan (file: /etc/postfix/main.cf)
# uncomment for debugging if needed
soft_bounce=yes
debug_peer_level = 99
debug_peer_list = 127.0.0.1
# postfix main
mail_owner = postfix
setgid_group = postdrop
delay_warning_time = 4
# postfix paths
html_directory = no
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
queue_directory = /var/spool/postfix
sendmail_path = /usr/sbin/sendmail.postfix
newaliases_path = /usr/bin/newaliases.postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
# network settings
inet_interfaces = all
mydomain = example.com
myhostname = host.example.com
mydestination = $myhostname localhost.$mydomain
mynetworks = 127.0.0.0/8, 119.235.30.174/32
mynetworks_style = subnet
myorigin = example.com
relay_domains = example2.com #virtual domain
# mail delivery
recipient_delimiter = +
# mappings
alias_maps = mysql:/etc/postfix/mysql-aliases.cf
# virtual setup
virtual_alias_maps = mysql:/etc/postfix/mysql-virtual_alias_maps.cf
virtual_gid_maps = static:89
virtual_mailbox_base = /home/vmail
virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual_domains_maps.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual_mailbox_maps.cf
virtual_minimum_uid = 89 #UID user postfix. lihat di file /etc/group
virtual_transport = virtual
virtual_uid_maps = static:89 #UID user postfix. lihat di file /etc/group
# debugging
debug_peer_level = 5
debugger_command =
PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
xxgdb $daemon_directory/$process_name $process_id & sleep 5
# authentication
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
broken_sasl_auth_clients = yes
smtpd_helo_required = yes
unknown_local_recipient_reject_code = 550
disable_vrfy_command = yes
smtpd_data_restrictions = reject_unauth_pipelining
message_size_limit = 12582912
Seperti yang saya ungkapkan sebelumnya, ini adalah initial setup. Artinya konfigurasi “asal
jalan”. Untuk keamanan, tentunya konfigurasi tersebut harus di tweak lagi.
informasi yang menghubungkan antara POSTFIX dengan mysql diletakan pada file *.cnf. Isi
dari file-file tersebut adalah sebagai berikut:
/etc/postfix/mysql-aliases.cf
user = postfix
password = mypassword
dbname = postfix
table = postfix_alias
select_field = destination
where_field = alias
hosts = localhost
/etc/postfix/mysql-virtual_alias_maps.cf
hosts = localhost
user = postfix
password = mypassword
dbname = postfix
table = alias
select_field = goto
where_field = address
/etc/postfix/mysql-virtual_domains_maps.cf
hosts = localhost
user = postfix
password = buburayam
dbname = postfix
table = domain
select_field = domain
where_field = domain
additional_conditions = and backupmx = '0' and active = '1'
/etc/postfix/mysql-virtual_mailbox_maps.cf
hosts = localhost
user = postfix
password = buburayam
dbname = postfix
table = mailbox
select_field = maildir
where_field = username
MySQL
Ada banyak cara bagaimana Anda menyimpan data username & password. Namun untuk kali
ini, saya memilih menggunakan MySQL.
instalasi modul yang diperlukan untuk MySQL adalah:
yum install mysql mysql-server
Dovecot
POSTFIX hanya bertugas menerima dan mengirim. Sedangkan program yang melayani
aplikasi email client lewat protokol IMAP & POP (seperti MS Outlook, Mozilla Thunderbird
atau SquirellMail) ditangani oleh Dovecot.
instalasi modul yang diperlukan untuk Dovecot adalah:
yum install dovecot dovecot-mysql
# 2.0.9: /etc/dovecot/dovecot.conf
# OS: Linux 2.6.35.6-45.fc14.x86_64 x86_64 Fedora release 14 (Laughlin)
ext3
first_valid_uid = 89
log_path = /var/log/dovecot
disable_plaintext_auth = no
#debug option
#mail_debug = yes
#auth_debug_passwords=yes
#auth_debug=yes
#auth_verbose = yes
#auth_verbose_passwords=plain
#verbose_ssl = yes
mail_location = maildir:/home/vmail/%d/%n
protocols = pop3 imap
ssl_cert =
Dovecot pun perlu sambungan untuk membaca informasi user yang tersimpan di
MySQL. Konfigurasi untuk koneksi ke MySQL bisa dilihat di
/etc/dovecot/dovecot-mysql.conf
driver = mysql
connect = host=localhost dbname=postfix user=postfix password=mypassword
default_pass_scheme = PLAIN
Cyrus-SASL
Khusus untuk keperluan autentikasi (memeriksa apakah user yang login via Dovecot atau
POSTFIX adalah user yang valid) digunakan program Cyrus-SASL.
instalasi modul yang diperlukan untuk Cyrus-SASL adalah:
yum install cyrus-sasl cyrus-sasl-mysql cyrus-sasl-plain pam_mysql
pastikan /etc/sasl2/smtpd.conf seperti berikut:
pwcheck_method: saslauthd
mech_list: plain login
untuk keperluan Virtual Domain, pastikan Cyrus memeriksa realm pada saat memeriksa user.
Hal ini ditentukan oleh 2 file konfigurasi:
/etc/init.d/saslauthd pastikan memiliki baris:
PARAMS="${PARAMS} -a ${MECHANISMS} -r"
Coba restart MySQL, POSTFIX, Dovecot, dan Cyrus-SASL. … And see what happen!
Saya belum bisa menuliskan step by step yang lengkap untuk proses setting ini. Tapi,
mungkin Anda coba merujuk ke beberapa link berikut ini.