/etc/postfix/main.cf
.
mail.falcot.com
. Pertanyaan ini yang diajukan secara default, namun konfigurasi yang diembannya tidak cukup lengkap untuk kebutuhan Falcot, karenanya administrator menjalankan perintah dpkg-reconfigure postfix
agar dapat menyesuaikan lebih banyak parameter.
localhost
, namun domain utama falcot.com
perlu ditambahkan sendiri. Lebih umumnya, pertanyaan ini seharusnya biasanya dijawab dengan seluruh nama domain yang mana mesin ini seharusnya melayani sebagai sebuah MX server; dengan kata lain, seluruh nama domain yang mana disebutkan DNS bahwa mesin ini akan menerima surel. Informasi ini berpangkal pada variabel mydestination
pada berkas konfigurasi Postfix — /etc/postfix/main.cf
.
192.168.0.0/16
ke jawaban default. Jika pertanyaan itu tidak muncul, variabel yang relevan dalam berkas konfigurasi adalah mynetworks
, seperti yang terlihat dalam contoh di bawah ini.
procmail
. This tool allows users to sort their incoming email according to rules stored in their ~/.procmailrc
file. Both Postfix and Exim4 suggest procmail by default, but there are alternatives like maildrop or Sieve filters.
Contoh 11.1. Berkas/etc/postfix/main.cf
awal
# See /usr/share/postfix/main.cf.dist for a commented, more complete version # Debian specific: Specifying a file name will cause the first # line of that file to be used as the name. The Debian default # is /etc/mailname. #myorigin = /etc/mailname smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU) biff = no # appending .domain is the MUA's job. append_dot_mydomain = no # Uncomment the next line to generate "delayed mail" warnings #delay_warning_time = 4h readme_directory = no # See http://www.postfix.org/COMPATIBILITY_README.html -- default to 2 on # fresh installs. compatibility_level = 2 # TLS parameters smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key smtpd_use_tls=yes smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache # See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for # information on enabling SSL in the smtp client. smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination myhostname = mail.falcot.com alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases myorigin = /etc/mailname mydestination = mail.falcot.com, falcot.com, localhost.localdomain, localhost relayhost = mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 192.168.0.0/16 mailbox_size_limit = 0 recipient_delimiter = + inet_interfaces = all inet_protocols = all
virtual_alias_domains
, dan mereferensi berkas pemetaan alamat dalam variabel virtual_alias_maps
.
virtual_alias_domains = falcotsbrand.com virtual_alias_maps = hash:/etc/postfix/virtual
/etc/postfix/virtual
menjelaskan pemetaan dengan sintaks yang agak sederhana: setiap baris berisi dua field yang dipisahkan oleh spasi; field pertama adalah nama alias, field kedua adalah daftar alamat surel tujuan pengalihan. Sintaks khusus @domain.com
mencakup semua sisa alias dalam suatu domain.
webmaster@falcotsbrand.com jean@falcot.com contact@falcotsbrand.com laure@falcot.com, sophie@falcot.com # The alias below is generic and covers all addresses within # the falcotsbrand.com domain not otherwise covered by this file. # These addresses forward email to the same user name in the # falcot.com domain. @falcotsbrand.com @falcot.com
/etc/postfix/virtual
the postfix table /etc/postfix/virtual.db
needs to be updated using sudo postmap /etc/postfix/virtual
.
virtual_mailbox_domains
, dan mereferensi ke berkas pemetaan kotak surat di virtual_mailbox_maps
. Parameter virtual_mailbox_base
berisi direktori di mana kotak pesan akan disimpan.
virtual_mailbox_domains = falcot.org virtual_mailbox_maps = hash:/etc/postfix/vmailbox virtual_mailbox_base = /var/mail/vhosts
virtual_uid_maps
(dan virtual_gid_maps
) mengacu ke berkas yang berisi pemetaan antara alamat surel dan sistem pengguna (dan kelompok) yang "memiliki" kotak surat yang sesuai. Agar semua kotak surat dimiliki oleh pemilik/kelompok yang sama, sintaks static:5000
menetapkan UID/GID tertentu (yang bernilai 5000 di sini).
/etc/postfix/vmailbox
cukup sederhana: dua field dipisahkan dengan spasi. Field pertama adalah alamat surel dalam salah satu domain virtual, dan field kedua adalah lokasi kotak surat yang terkait (relatif terhadap direktori yang ditentukan dalam virtual_mailbox_base). Jika nama kotak surat berakhir dengan garis miring (/
), surel akan disimpan dalam format maildir; jika tidak, format tradisional mbox akan digunakan. Format maildir menggunakan seluruh direktori untuk menyimpan kotak surat, masing-masing pesan disimpan dalam berkas terpisah. Dalam format mbox, seluruh kotak surat disimpan dalam satu berkas, dan setiap baris yang dimulai dengan "From
" (From
diikuti dengan spasi) menandai awal pesan baru.
# Surel Jean disimpan sebagai maildir, dengan # satu berkas per surel dalam suatu direktori # terdedikasi jean@falcot.org falcot.org/jean/ # Surel Sophie's disimpan dalam suatu berkas "mbox" # tradisional dengan semua surel disambung ke dalam # satu berkas tunggal sophie@falcot.org falcot.org/sophie
soft_bounce = yes
directive. By prepending a reject-type directive with warn_if_reject
only a log message will be recorded instead of rejecting the request.
smtpd_client_restrictions
mengendalikan mesin mana yang diperbolehkan untuk berkomunikasi dengan server surel.
Contoh 11.2. Pembatasan Berbasis Alamat Klien
smtpd_client_restrictions = permit_mynetworks, warn_if_reject reject_unknown_client_hostname, check_client_access hash:/etc/postfix/access_clientip, reject_rhsbl_reverse_client dbl.spamhaus.org, reject_rhsbl_reverse_client rhsbl.sorbs.net, reject_rbl_client zen.spamhaus.org, reject_rbl_client dnsbl.sorbs.net
permit_mynetworks
directive, used as the first rule, accepts all emails coming from a machine in the local network (as defined by the mynetworks
configuration variable).
warn_if_reject
modifier to the reject_unknown_client
directive: this modifier turns the rejection into a simple warning recorded in the logs. The administrators can then keep an eye on the number of messages that would be rejected if the rule were actually enforced, and make an informed decision later if they wish to enable such enforcement.
/etc/postfix/access_clientip
. Server di whitelist dianggap sebagai dipercaya, dan surel yang datang dari sana tidak diperiksa memakai aturan penyaringan berikut.
HELO
(or EHLO
) command, followed by the name of the sending email server. Checking the validity of this name can be interesting. To fully enforce the restrictions listed in smtpd_helo_restrictions
the smtpd_helo_required
option needs to be enabled. Otherwise clients could skip the restrictions by not sending any HELO
/EHLO
command.
Contoh 11.3. Pembatasan pada nama yang diumumkan di EHLO
smtpd_helo_required = yes smtpd_helo_restrictions = permit_mynetworks, reject_invalid_helo_hostname, reject_non_fqdn_helo_hostname, warn_if_reject reject_unknown_helo_hostname, check_helo_access hash:/etc/postfix/access_helo, reject_rhsbl_helo multi.surbl.org
permit_mynetworks
pertama memungkinkan semua mesin di jaringan lokal untuk memperkenalkan diri dengan bebas. Hal ini penting, karena beberapa program email tidak menghormati bagian dari protokol SMTP ini secara cukup memadai, dan mereka dapat memperkenalkan diri dengan nama-nama yang tidak masuk akal.
reject_invalid_helo_hostname
rule rejects emails when the EHLO
announce lists a syntactically incorrect hostname. The reject_non_fqdn_helo_hostname
rule rejects messages when the announced hostname is not a fully-qualified domain name (including a domain name as well as a host name). The reject_unknown_helo_hostname
rule rejects messages if the announced name does not exist in the DNS. Since this last rule unfortunately leads to too many rejections, the administrators turned its effect to a simple warning with the warn_if_reject
modifier as a first step; they may decide to remove this modifier at a later stage, after auditing the results of this rule.
reject_rhsbl_helo
allows to specify a black list to check the hostname against an RHSBL.
permit_mynetworks
as the first rule has an interesting side effect: the following rules only apply to hosts outside the local network. This allows blacklisting all hosts that announce themselves as part of the falcot.com
network, for instance by adding a falcot.com REJECT You are not in our network!
line to the /etc/postfix/access_helo
file.
MAIL FROM
dari protokol SMTP; sekali lagi, informasi ini dapat divalidasi dalam beberapa cara yang berbeda.
Contoh 11.4. Pemeriksaan pengirim
smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/access_sender, reject_unknown_sender_domain, reject_unlisted_sender, reject_non_fqdn_sender, reject_rhsbl_sender rhsbl.sorbs.net
/etc/postfix/access_sender
memetakan beberapa perlakuan khusus untuk beberapa pengirim. Ini biasanya berarti memasukkan beberapa pengirim ke daftar putih atau daftar hitam.
reject_unknown_sender_domain
memerlukan domain pengirim yang valid, karena dibutuhkan untuk alamat yang valid. Aturan reject_unlisted_sender
menolak pengirim lokal jika alamat tidak ada; hal ini mencegah surel dari yang dikirim dari alamat yang tidak valid dalam domain falcot.com
, dan pesan yang berasal dari joe.bloggs@falcot.com
hanya diterima jika alamat tersebut benar-benar ada.
reject_non_fqdn_sender
menolak surel yang mengaku berasal dari alamat tanpa fully-qualified domain name. Dalam prakteknya, ini berarti menolak surel yang datang dari user@machine
: alamat harus diumumkan sebagai user@machine.example.com
atau user@example.com
.
reject_rhsbl_sender
rule reject senders based on a (domain-based) RHSBL service.
RCPT TO
dalam protokol SMTP. Alamat ini juga memerlukan validasi, bahkan jika itu mungkin kurang relevan daripada pemeriksaan atas alamat pengirim.
Contoh 11.5. Pemeriksaan penerima
smtpd_recipient_restrictions = permit_mynetworks, reject_unauth_destination, reject_unlisted_recipient, reject_non_fqdn_recipient, permit
reject_unauth_destination
adalah aturan dasar yang mempersyaratkan pesan dari luar ditujukan kepada kami; pesan yang dikirim ke alamat yang tidak dilayani oleh server ini akan ditolak. Tanpa aturan ini, server menjadi relay terbuka yang memungkinkan spammer untuk mengirim surel yang tidak diinginkan; aturan ini wajib, dan itu paling baik disertakan di bagian awal dari daftar, sehingga tidak ada aturan lainnya mungkin mengotorisasi pesan sebelum tujuan telah diperiksa.
reject_unlisted_recipient
menolak pesan yang dikirim ke pengguna lokal yang tidak ada. Ini masuk akal. Akhirnya, aturan reject_non_fqdn_recipient
menolak alamat yang bukan fully-qualified; ini menjadikannya mustahil untuk mengirim surel ke jean
atau jean@machine
, dan memerlukan menggunakan alamat lengkap, seperti jean@machine.falcot.com
atau jean@falcot.com
.
permit
directive at the end is not necessary. But it can be useful at the end of a restriction list to make the default policy explicit.
DATA
SMTP dikirimkan sebelum isi pesan. Tidak memberikan informasi apapun per se, selain mengumumkan apa yang datang berikutnya. Masih bisa dipersyaratkan untuk pemeriksaan.
reject_unauth_pipelining
menyebabkan pesan ditolak jika pihak pengirim mengirim perintah sebelum balasan atas perintah sebelumnya dikirim. Ini penjaga terhadap optimasi yang umum digunakan oleh robot spammer, karena mereka biasanya tidak peduli isi balasan dan fokus hanya pada mengirim surel sebanyak mungkin dalam waktu sependek mungkin.
RCPT TO
command by default.
EHLO
yang tidak valid, Postfix tahu pengirim dan penerima ketika mengumumkan penolakan. Ini kemudian mencatat log pesan yang lebih eksplisit daripada yang bisa dilakukan jika transaksi telah terputus dari awal. Selain itu, sejumlah klien SMTP tidak mengharapkan kegagalan pada perintah SMTP awal, dan klien ini akan kurang terganggu oleh penolakan akhir ini.
smtpd_delay_reject
rule.
Contoh 11.7. Memfungsikan penyaring berbasis konten
header_checks = regexp:/etc/postfix/header_checks body_checks = regexp:/etc/postfix/body_checks
Contoh 11.8. Berkas contoh /etc/postfix/header_checks
/^X-Mailer: GOTO Sarbacane/ REJECT I fight spam (GOTO Sarbacane) /^Subject: *Your email contains VIRUSES/ DISCARD virus notification
GOTO Sarbacane
(software surel massal) ditemukan, pesan tersebut akan ditolak. Ekspresi kedua mengendalikan subjek pesan; jika itu menyebutkan pemberitahuan virus, kita bisa memutuskan untuk tidak menolak pesan tetapi untuk membuangnya segera sebagai gantinya.
check_policy_service
sebagai pembatasan tambahan:
smtpd_recipient_restrictions = permit_mynetworks, [...] check_policy_service inet:127.0.0.1:10023
postgrey
dan mengirim informasi mengenai pesan yang relevan. Pada sisinya, Postgrey mempertimbangkan triplet alamat IP/pengirim/penerima triplet dan memeriksa basis data apakah triplet yang sama telah terlihat baru-baru ini. Jika demikian, Postgrey menjawab bahwa pesan harus diterima; jika tidak, jawaban menunjukkan bahwa pesan harus ditolak untuk sementara, dan triplet dicatat dalam basis data.
smtpd_restriction_classes
, dan didefinisikan dengan cara yang sama sebagai smtpd_recipient_restrictions
. Direktif check_recipient_access
kemudian mendefinisikan tabel pemetaan penerima tertentu untuk seperangkat batasan.
Contoh 11.9. Mendefinisikan kelas pembatasan dalam main.cf
smtpd_restriction_classes = greylisting, aggressive, permissive greylisting = check_policy_service inet:127.0.0.1:10023 aggressive = reject_rbl_client sbl-xbl.spamhaus.org, check_policy_service inet:127.0.0.1:10023 permissive = permit smtpd_recipient_restrictions = permit_mynetworks, reject_unauth_destination, check_recipient_access hash:/etc/postfix/recipient_access
Contoh 11.10. Berkas /etc/postfix/recipient_access
# Unfiltered addresses postmaster@falcot.com permissive support@falcot.com permissive sales-asia@falcot.com permissive # Aggressive filtering for some privileged users joe@falcot.com aggressive # Special rule for the mailing-list manager sympa@falcot.com reject_unverified_sender # Greylisting by default falcot.com greylisting
clamav
untuk antivirus gratis mereka. Paket utama adalah clamav, tetapi mereka juga memasang beberapa paket tambahan seperti arj, unzoo, unrar, dan lha, karena mereka diperlukan oleh antivirus untuk menganalisis lampiran yang diarsipkan dalam salah satu format ini.
clamav-milter
. milter (singkatan dari mail filter) adalah sebuah program penyaringan yang dirancang khusus untuk menyambung dengan server surel. Suatu milter menggunakan standar antarmuka pemrograman aplikasi (API) yang memberikan kinerja lebih baik daripada filter eksternal ke server surel. Milters awalnya diperkenalkan oleh Sendmail, tetapi Postfix segera mengikutinya.
dpkg-reconfigure clamav-milter
. Ketika diminta untuk "Antarmuka komunikasi dengan Sendmail", jawablah "inet:10002@127.0.0.1
".
dpkg-reconfigure clamav-base
.
/etc/postfix/main.cf
:
# Virus check with clamav-milter smtpd_milters = inet:[127.0.0.1]:10002
systemctl reload postfix
should be run so that this change is taken into account.
include
directive it must have one.
Name: example.org Type: TXT TTL: 3600 Data: v=spf1 a mx -all
falcot.org
entry.
#
host -t TXT falcot.org
falcot.org descriptive text "v=spf1 ip4:199.127.61.96 +a +mx +ip4:206.221.184.234 +ip4:209.222.96.251 ~all"
postfix
mail server can check the SPF record for incoming emails using the postfix-policyd-spf-python package, a policy agent written in Python. The file /usr/share/doc/postfix-policyd-spf-python/README.Debian
describes the necessary steps to integrate the agent into postfix, so we won't repeat it here.
/etc/postfix-policyd-spf-python/policyd-spf.conf
, which is fully documented in policyd-spf.conf(5) and /usr/share/doc/postfix-policyd-spf-python/policyd-spf.conf.commented.gz
. The main configuration parameters are HELO_reject
and Mail_From_reject
, which configure if emails should be rejected (Fail
) or accepted with a header being appended (False
), if checks fail. The latter is often useful, when the message is further processed by a spam filter.
Header_Type
must be set to AR
.
postfix
, adds a digital signature associated with the domain name to the header of outgoing emails. The receiving party can validate the message body and header fields by checking the signature against a public key, which is retrieved from the senders DNS records.
opendkim-genkey -s SELECTOR -d DOMAIN
. SELECTOR must be a unique name for the key. It can be as simple as "mail" or the date of creation, if you plan to rotate keys.
Contoh 11.11. Create a private key for signing E-Mails from falcot.com
#
opendkim-genkey -s mail -d falcot.com -D /etc/dkimkeys
#
chown opendkim.opendkim /etc/dkimkeys/mail.*
/etc/dkimkeys/mail.private
and /etc/dkimkeys/mail.txt
and set the appropriate ownership. The first file contains the private key and the latter the public key, that needs to be added to the DNS:
Name: mail._domainkey Type: TXT TTL: 3600 Data: "v=DKIM1; h=sha256; k=rsa; s=email; p=[...]"
-b 1024
to chose a smaller keysize. If opendkim-testkey
succeeds, the entry has been successfully set up. The syntax of the entry is explained here:
SOCKET
and RUNDIR
must be chosen in /etc/default/opendkim
. Please note that SOCKET
must be accessible from postfix
in its chrooted environment. The further configuration is done in /etc/opendkim.conf
. The following is a configuration excerpt, which makes sure that the Domain
"falcot.com" and all subdomains (SubDomain
) are signed by the Selector
"mail" and the single private key (KeyFile
) /etc/dkimkeys/mail.private
. The "relaxed" Canonicalization
for both the header and the body tolerates mild modification (by a mailing list software, for example). The filter runs both in signing ("s") and verification ("v") Mode
. If a signature fails to validate (On-BadSignature
), the mail should be quarantined ("q").
[...] Domain falcot.com KeyFile /etc/dkimkeys/mail.private Selector mail [...] Canonicalization relaxed/relaxed Mode sv On-BadSignature q SubDomains yes [...] Socket inet:12345@localhost [...] UserID opendkim
KeyTable
), domains (SigningTable
) and to specify internal or trusted hosts (InternalHosts
, ExternalIgnoreList
), which may send mail through the server as one of the signing domains without credentials.
/etc/postfix/main.cf
make postfix
use the filter:
milter_default_action = accept non_smtpd_milters = inet:localhost:12345 smtpd_milters = inet:localhost:12345
/etc/postfix/master.cf
instead.
/usr/share/doc/opendkim/
directory and the manual pages opendkim(8) and opendkim.conf(5).
_dmarc
and the action, that should be taken, when emails, which contain your domain as sending host, fail to validate using DKIM and SPF.
#
host -t TXT _dmarc.gmail.com
_dmarc.gmail.com descriptive text "v=DMARC1; p=none; sp=quarantine; rua=mailto:mailauth-reports@google.com"
#
host -t TXT _dmarc.yahoo.com
_dmarc.yahoo.com descriptive text "v=DMARC1; p=reject; pct=100; rua=mailto:dmarc_y_rua@yahoo.com;"
reject
all emails pretending to be sent from a Yahoo account but missing or failing DKIM and SPF checks. Google Mail (Gmail) propagates a very relaxed policy, in which such messages from the main domain should still be accepted (p=none
). For subdomains they should be marked as spam (sp=quarantine
). The addresses given in the rua
key can be used to send aggregated DMARC reports to. The full syntax is explained here:
postfix
mail server can use this information too. The opendmarc package contains the necessary milter. Similar to opendkim SOCKET
and RUNDIR
must be chosen in /etc/default/opendmarc
(for Unix sockets you must make sure, that they are inside the postfix chroot to be found). The configuration file /etc/opendmarc.conf
contains detailed comments and is also explained in opendmarc.conf(5). By default, emails failing the DMARC validation are not rejected but flagged, by adding an appropriate header field. To change this, use RejectFailures true
.
smtpd_milters
and non_smtpd_milters
. If we configured the opendkim and opendmarc milters to run on ports 12345 and 54321, the entry in /etc/postfix/main.cf
looks like this:
non_smtpd_milters = inet:localhost:12345,inet:localhost:54321 smtpd_milters = inet:localhost:12345,inet:localhost:54321
/etc/postfix/master.cf
instead.
saslpasswd2
, yang memerlukan beberapa parameter. Opsi -U
mendefinisikan domain otentikasi, yang harus cocok dengan parameter smtpd_sasl_local_domain
dalam konfigurasi Postfix. Opsi -C
memungkinkan membuat pengguna, dan -f
menetapkan berkas yang akan dipakai jika basis data SASL perlu disimpan di lokasi yang berbeda dari default (/etc/sasldb2
).
#
saslpasswd2 -u `postconf -h myhostname` -f /var/spool/postfix/etc/sasldb2 -c jean
[... ketikkan kata sandi jean dua kali ...]
/etc/sasldb2
menjadi link simbolik menunjuk pada basis data yang digunakan oleh Postfix, dengan perintah ln -sf /var/spool/postfix/etc/sasldb2 /etc/sasldb2
.
postfix
perlu ditambahkan ke grup sasl
, sehingga dapat mengakses basis data akun SASL. Beberapa parameter baru juga diperlukan untuk mengaktifkan SASL, dan parameter smtpd_recipient_restrictions
perlu dikonfigurasi untuk memungkinkan kilen terotentikasi-SASL untuk mengirim surel dengan bebas.
Contoh 11.12. Memfungsikan SASL di /etc/postfix/main.cf
# Enable SASL authentication smtpd_sasl_auth_enable = yes # Define the SASL authentication domain to use smtpd_sasl_local_domain = $myhostname [...] # Adding permit_sasl_authenticated before reject_unauth_destination # allows relaying mail sent by SASL-authenticated users smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination, [...]
/etc/postfix/master.cf
file. To turn off authentication at all for port 25 (smtpd
service) add the following directive:
smtp inet n - y - - smtpd [..] -o smtpd_sasl_auth_enable=no [..]
AUTH
command (some very old mail clients do), interoperability with them can be enabled using the broken_sasl_auth_clients
directive.