Difference between revisions of "Postfix: Setup DNS dkim"
Onnowpurbo (talk | contribs) |
Onnowpurbo (talk | contribs) (→Tables) |
||
(17 intermediate revisions by the same user not shown) | |||
Line 14: | Line 14: | ||
sudo gpasswd -a postfix opendkim | sudo gpasswd -a postfix opendkim | ||
− | sudo mkdir /etc/opendkim | + | sudo mkdir -p /etc/opendkim/keys/lms.onnocenter.or.id/ |
− | + | sudo chown -R opendkim: /etc/opendkim | |
− | sudo chown -R opendkim: | ||
sudo chmod go-rw /etc/opendkim/keys | sudo chmod go-rw /etc/opendkim/keys | ||
+ | |||
+ | |||
+ | ==Key generation dan setup DNS== | ||
+ | |||
+ | Generate key menggunakan perintah | ||
+ | |||
+ | mkdir -p /etc/opendkim/keys/lms.onnocenter.or.id/ | ||
+ | cd /etc/opendkim/keys/lms.onnocenter.or.id/ | ||
+ | opendkim-genkey -b 2048 -d lms.onnocenter.or.id -D /etc/opendkim/keys/lms.onnocenter.or.id -s lms -v | ||
+ | chown -R opendkim: /etc/opendkim/keys/lms.onnocenter.or.id/ | ||
+ | chmod -R 700 /etc/opendkim/keys/lms.onnocenter.or.id/ | ||
+ | |||
+ | Akan menghasilkan dua (2) file: | ||
+ | |||
+ | * lms.private - berisi private key. | ||
+ | * lms.txt - berisi entry DNS | ||
+ | |||
+ | Argumen | ||
+ | |||
+ | -s memberikan informasi selector yang digunakan | ||
+ | -d domain yang digunakan | ||
+ | -t menyatakan DKIM dalam test mode. | ||
+ | |||
+ | |||
+ | Tambahkan di DNS sesuai dengan krs.txt, kira2 sebagai berikut | ||
+ | |||
+ | lms._domainkey.lms.onnocenter.or.id IN TXT "v=DKIM1; g=*; k=rsa; | ||
+ | p=PpYHdE2tevfEpvL1Tk2dDYv0pF28/f5MxU83x/0bsn4R4p7waPaz1IbOGs/6bm5QIDAQAB" | ||
+ | |||
+ | Cek DNS menggunakan | ||
+ | |||
+ | sudo named-checkconf | ||
==Konfigurasi== | ==Konfigurasi== | ||
Line 37: | Line 68: | ||
# Sign for example.com with key in /etc/dkimkeys/dkim.key using | # Sign for example.com with key in /etc/dkimkeys/dkim.key using | ||
# selector '2007' (e.g. 2007._domainkey.example.com) | # selector '2007' (e.g. 2007._domainkey.example.com) | ||
− | Domain onnocenter.or.id | + | Domain lms.onnocenter.or.id |
KeyFile /etc/opendkim/dkim.key | KeyFile /etc/opendkim/dkim.key | ||
− | Selector | + | Selector lms |
+ | Socket inet:8891@localhost | ||
# Common settings. See dkim-filter.conf(5) for more information. | # Common settings. See dkim-filter.conf(5) for more information. | ||
Line 96: | Line 128: | ||
==Tables== | ==Tables== | ||
+ | |||
+ | Edit | ||
+ | |||
+ | sudo vi /etc/opendkim/dkim.key | ||
+ | |||
+ | *@lms.onnocenter.or.id:lms.onnocenter.or.id:/etc/opendkmi/keys/lms.onnocenter.or.id/lms.private | ||
+ | |||
+ | |||
+ | Edit | ||
sudo vi /etc/opendkim/signing.table | sudo vi /etc/opendkim/signing.table | ||
− | *@onnocenter.or.id | + | *@lms.onnocenter.or.id lms._domainkey.lms.onnocenter.or.id |
+ | |||
+ | Edit | ||
sudo vi /etc/opendkim/key.table | sudo vi /etc/opendkim/key.table | ||
− | + | lms._domainkey.lms.onnocenter.or.id lms.onnocenter.or.id:lms:/etc/opendkim/keys/lms.onocenter.or.id/lms.private | |
+ | |||
+ | Edit | ||
sudo vi /etc/opendkim/trusted.hosts | sudo vi /etc/opendkim/trusted.hosts | ||
Line 113: | Line 158: | ||
onnocenter.or.id | onnocenter.or.id | ||
*.onnocenter.or.id | *.onnocenter.or.id | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
==Startup== | ==Startup== | ||
Line 163: | Line 178: | ||
==Test== | ==Test== | ||
+ | |||
Test | Test | ||
− | opendkim-testkey -d onnocenter.or.id -k /etc/ | + | opendkim-testkey -d lms.onnocenter.or.id -k /etc/opendkim/keys/lms.onnocenter.or.id/lms.private -s lms -vvv |
Untuk testing, coba menggunakan tools: | Untuk testing, coba menggunakan tools: | ||
Line 174: | Line 190: | ||
check-auth@verifier.port25.com | check-auth@verifier.port25.com | ||
− | autorespond+dkim | + | autorespond+dkim@dk.elandsys.com |
− | |||
− | Common errors and fixes | + | ==Common errors and fixes== |
− | Missing signature | + | ===Missing signature=== |
If something is not functioning properly (emails are not being signed) look for errors in the log: | If something is not functioning properly (emails are not being signed) look for errors in the log: | ||
Line 231: | Line 246: | ||
==Referensi== | ==Referensi== | ||
+ | * https://tecadmin.net/setup-dkim-with-postfix-on-ubuntu-debian/ | ||
* https://www.linuxbabe.com/mail-server/setting-up-dkim-and-spf | * https://www.linuxbabe.com/mail-server/setting-up-dkim-and-spf | ||
* https://help.ubuntu.com/community/Postfix/DKIM | * https://help.ubuntu.com/community/Postfix/DKIM |
Latest revision as of 18:06, 29 April 2019
DomainKeys Identified Mail (DKIM) adalah metode untuk otentikasi e-mail, yang memungkinkan seseorang yang menerima email untuk memverifikasi bahwa pesan tersebut sebenarnya berasal dari domain yang diklaim berasal. Kebutuhan akan jenis otentikasi ini muncul karena spam sering kali memalsukan header.
DKIM menggunakan public-key cryptography untuk memungkinkan pengirim menandatangani email yang sah secara elektronik dengan cara yang dapat diverifikasi oleh penerima.
DKIM juga menjaga agar tidak merusak surat, menawarkan integritas end-to-end dari penandatanganan sampai verifikasi Mail transfer agent (MTA).
dkim-milter adalah aplikasi berbasis-milter (dkim-filter) yang terhubung ke Postfix untuk menyediakan layanan DomainKeys Identified Mail untuk server email Anda. dkim-milter tidak lagi dikembangkan, dan pembuat awalnya telah forked source-nya dan sekarang sedang mengembangkan opendkim. Untuk rilis Lucid dan yang lebih baru, opendkim lebih disukai daripada dkim-filter. Petunjuk pada halaman ini harus sama (hanya dengan nama paket yang disesuaikan sesuai kebutuhan).
Instalasi
Asumsi Postfix sudah di install. Instalasi opendkim menggunakan perintah,
sudo apt -y install opendkim opendkim-tools sudo gpasswd -a postfix opendkim
sudo mkdir -p /etc/opendkim/keys/lms.onnocenter.or.id/ sudo chown -R opendkim: /etc/opendkim sudo chmod go-rw /etc/opendkim/keys
Key generation dan setup DNS
Generate key menggunakan perintah
mkdir -p /etc/opendkim/keys/lms.onnocenter.or.id/ cd /etc/opendkim/keys/lms.onnocenter.or.id/ opendkim-genkey -b 2048 -d lms.onnocenter.or.id -D /etc/opendkim/keys/lms.onnocenter.or.id -s lms -v chown -R opendkim: /etc/opendkim/keys/lms.onnocenter.or.id/ chmod -R 700 /etc/opendkim/keys/lms.onnocenter.or.id/
Akan menghasilkan dua (2) file:
- lms.private - berisi private key.
- lms.txt - berisi entry DNS
Argumen
-s memberikan informasi selector yang digunakan -d domain yang digunakan -t menyatakan DKIM dalam test mode.
Tambahkan di DNS sesuai dengan krs.txt, kira2 sebagai berikut
lms._domainkey.lms.onnocenter.or.id IN TXT "v=DKIM1; g=*; k=rsa; p=PpYHdE2tevfEpvL1Tk2dDYv0pF28/f5MxU83x/0bsn4R4p7waPaz1IbOGs/6bm5QIDAQAB"
Cek DNS menggunakan
sudo named-checkconf
Konfigurasi
Ada dua (2) file yang penting, yaitu,
/etc/opendkim.conf /etc/default/opendkim
Edit /etc/opendkim.conf misalnya,
# Log to syslog Syslog yes # Required to use local socket with MTAs that access the socket as a non- # privileged user (e.g. Postfix) UMask 002 # Sign for example.com with key in /etc/dkimkeys/dkim.key using # selector '2007' (e.g. 2007._domainkey.example.com) Domain lms.onnocenter.or.id KeyFile /etc/opendkim/dkim.key Selector lms Socket inet:8891@localhost # Common settings. See dkim-filter.conf(5) for more information. AutoRestart yes Background yes Canonicalization relaxed/relaxed DNSTimeout 5 Mode sv SignatureAlgorithm rsa-sha256 SubDomains no #UseASPDiscard no #Version rfc4871 X-Header no OversignHeaders From TrustAnchorFile /usr/share/dns/root.key Nameservers 127.0.0.1,8.8.8.8,8.8.4.4,103.112.162.222 # Map domains in From addresses to keys used to sign messages KeyTable refile:/etc/opendkim/key.table SigningTable refile:/etc/opendkim/signing.table # Hosts to ignore when verifying signatures ExternalIgnoreList /etc/opendkim/trusted.hosts # A set of internal hosts whose mail should be signed InternalHosts /etc/opendkim/trusted.hosts
File /etc/opendkim.conf adalah yang paling penting. Ini memberi informasi yang diperlukan tentang selector (digunakan untuk DNS request dan verifikasi email) dan signing key yang digunakan (key yang digunakan untuk menandatangani email keluar).
Edit /etc/default/opendkim yang digunakan untuk menyambungkan milter ke MTA:
# Command-line options specified here will override the contents of # /etc/opendkim.conf. See opendkim(8) for a complete list of options. #DAEMON_OPTS="" # # Uncomment to specify an alternate socket # Note that setting this will override any Socket value in opendkim.conf # default: # SOCKET="local:/var/run/opendkim/opendkim.sock" # listen on all interfaces on port 54321: #SOCKET="inet:54321" # listen on loopback on port 12345: SOCKET="inet:8891@localhost" # Ubuntu default - listen on loopback on port 8891 # listen on 192.0.2.1 on port 12345: #SOCKET="inet:12345@192.0.2.1"
Edit /etc/postfix/main.cf, tambahkan setup berikut ini,
# DKIM milter_default_action = accept milter_protocol = 2 smtpd_milters = inet:localhost:8891 non_smtpd_milters = inet:localhost:8891
Tables
Edit
sudo vi /etc/opendkim/dkim.key
*@lms.onnocenter.or.id:lms.onnocenter.or.id:/etc/opendkmi/keys/lms.onnocenter.or.id/lms.private
Edit
sudo vi /etc/opendkim/signing.table
*@lms.onnocenter.or.id lms._domainkey.lms.onnocenter.or.id
Edit
sudo vi /etc/opendkim/key.table
lms._domainkey.lms.onnocenter.or.id lms.onnocenter.or.id:lms:/etc/opendkim/keys/lms.onocenter.or.id/lms.private
Edit
sudo vi /etc/opendkim/trusted.hosts
127.0.0.1 localhost onnocenter.or.id *.onnocenter.or.id
Startup
Start opendkim
sudo service opendkim start
Jika tidak jalan cek
grep -i dkim /var/log/mail.log
Atau jalankan langsung menggunakan perintah
/usr/sbin/opendkim -x /etc/opendkim.conf -u opendkim -p 8891
Restart postfix MTA,
sudo service postfix restart
Test
Test
opendkim-testkey -d lms.onnocenter.or.id -k /etc/opendkim/keys/lms.onnocenter.or.id/lms.private -s lms -vvv
Untuk testing, coba menggunakan tools:
http://www.sendmail.org/dkim/tools
Atau email ke
check-auth@verifier.port25.com autorespond+dkim@dk.elandsys.com
Common errors and fixes
Missing signature
If something is not functioning properly (emails are not being signed) look for errors in the log:
grep -i dkim /var/log/mail.log
The following error indicates the filter ran properly however could not match the outgoing email domain with a filter (and thus no signature was generated):
Nov 21 06:59:56 appname dkim-filter[2911]: 81AA7E688: no signature data
Consider changing the domain to a wildcard in /etc/opendkim.conf:
# Sign for example.com with key in /etc/mail/dkim.key using # selector '2007' (e.g. 2007._domainkey.example.com) Domain * KeyFile /etc/mail/dkim.key Selector mail
Using a domain of * will require putting the dkim key into EACH domain's DNS zone file for those domains that send email using this server. The dkim signing will work for your server, but without updating each DNS zone file, the public key will not be found by the recipient mail server.
Multiple signatures
If amavis-new is installed and dkim signs emails multiple times with same domain and selector, is the configuration error likely to be how you feed messages back to postfix from amavis.
Head to /etc/postfix/master.cf look for the section starting with:
127.0.0.1:10025 inet n - - - - smtpd
Find the option -o receive_override_options= and add ,no_milters to the end of that line. A corrected config could look something like this:
127.0.0.1:10025 inet n - - - - smtpd -o content_filter= -o local_recipient_maps= -o relay_recipient_maps= -o smtpd_restriction_classes= -o smtpd_delay_reject=no -o smtpd_client_restrictions=permit_mynetworks,reject -o smtpd_helo_restrictions= -o smtpd_sender_restrictions= -o smtpd_recipient_restrictions=permit_mynetworks,reject -o smtpd_data_restrictions=reject_unauth_pipelining -o smtpd_end_of_data_restrictions= -o mynetworks=127.0.0.0/8 -o smtpd_error_sleep_time=0 -o smtpd_soft_error_limit=1001 -o smtpd_hard_error_limit=1000 -o smtpd_client_connection_count_limit=0 -o smtpd_client_connection_rate_limit=0 -o receive_override_options=no_header_body_checks,no_unknown_recipient_checks,no_milters