{"id":1135,"date":"2017-02-21T09:11:31","date_gmt":"2017-02-21T03:41:31","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=1135"},"modified":"2019-11-05T17:39:20","modified_gmt":"2019-11-05T12:09:20","slug":"dkim-setup-postfix-mailserver-centos-6-7","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/dkim-setup-postfix-mailserver-centos-6-7\/","title":{"rendered":"Dkim Setup on Postfix Mailserver &#8211; Centos 6\/7"},"content":{"rendered":"<p><strong>Date Posted:22-02-2017<\/strong><\/p>\n<p>Its a biggest challenge for a new mail server to reach popular mail provider user&#8217;s inbox. One of the best way is to sign the outgoing mail server using dkim. There are multiple ways to implement dkim signing. We are going to use <em>opendkim<br \/>\n<\/em>as a service to sign the mail and postfix as a mailserver.<\/p>\n<h5>Assumption:<\/h5>\n<ol>\n<li>Centos operating system.<\/li>\n<li>PostFix Mailserver<\/li>\n<\/ol>\n<p>Default installation of postfix would be sufficient.<\/p>\n<h5>Implementation:<\/h5>\n<p>Starts with installing epel repo to the server. Some server may have epel repo already enabled.<\/p>\n<p><strong>For Centos 6:<\/strong><\/p>\n<p><code>wget http:\/\/download.fedoraproject.org\/pub\/epel\/6\/x86_64\/epel-release-6-8.noarch.rpm<br \/>\nrpm -ivh epel-release-6-8.noarch.rpm<\/code><\/p>\n<p><strong>For Centos 7:<\/strong><\/p>\n<p><code>wget https:\/\/dl.fedoraproject.org\/pub\/epel\/epel-release-latest-7.noarch.rpm<\/code><\/p>\n<p><code>yum install epel-release-latest-7.noarch.rpm (or)<\/code><\/p>\n<p><code>rpm -ivh epel-release-latest-7.noarch.rpm<\/code><\/p>\n<p>Install opendkim application using yum<\/p>\n<p><code>yum install opendkim<\/code><\/p>\n<p>Delete all the content of \/etc\/opendkim.conf and add only the quoted text mentioned below.<\/p>\n<p><code>vi \/etc\/opendkim.conf<\/code><\/p>\n<blockquote><p>AutoRestart&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Yes<br \/>\nAutoRestartRate&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 10\/1h<br \/>\nLogWhy&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Yes<br \/>\nSyslog&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Yes<br \/>\nSyslogSuccess&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Yes<br \/>\nMode&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sv<br \/>\nCanonicalization&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; relaxed\/simple<br \/>\nExternalIgnoreList&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; refile:\/etc\/opendkim\/TrustedHosts<br \/>\nInternalHosts&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; refile:\/etc\/opendkim\/TrustedHosts<br \/>\nKeyTable&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; refile:\/etc\/opendkim\/KeyTable<br \/>\nSigningTable&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; refile:\/etc\/opendkim\/SigningTable<br \/>\nSignatureAlgorithm&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rsa-sha256<br \/>\nSocket&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; inet:8892@localhost<br \/>\nPidFile&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/var\/run\/opendkim\/opendkim.pid<br \/>\nUMask&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 022<br \/>\nUserID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; opendkim:opendkim<br \/>\nTemporaryDirectory&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/var\/tmp<\/p><\/blockquote>\n<p>Create keys for the domain. Replace <em>domain.tld <\/em>with our domain name.<\/p>\n<p><code>mkdir \/etc\/opendkim\/keys\/domain.tld<br \/>\nopendkim-genkey -D \/etc\/opendkim\/keys\/domain.tld\/ -d domain.tld -s default<br \/>\nchown -R opendkim: \/etc\/opendkim\/keys\/domain.tld<br \/>\nmv \/etc\/opendkim\/keys\/domain.tld\/default.private \/etc\/opendkim\/keys\/domain.tld\/default<\/code><\/p>\n<p>Open the file <em>\/etc\/opendkim\/KeyTable <\/em> and add the following content.<\/p>\n<p><code>vi \/etc\/opendkim\/KeyTable<\/code><\/p>\n<blockquote><p>default._domainkey.domain.tld domain.tld:default:\/etc\/opendkim\/keys\/domain.tld\/default<\/p><\/blockquote>\n<p>Open the file&nbsp; <em>\/etc\/opendkim\/SigningTable <\/em> and add the below lines. * represents all the email accounts associated with domain.tld.<\/p>\n<p><code>vi \/etc\/opendkim\/SigningTable<\/code><\/p>\n<blockquote><p>*@domain.tld default._domainkey.domain.tld<\/p><\/blockquote>\n<p>Add the trusted hosts to the file <em>\/etc\/opendkim\/TrustedHosts<\/em><\/p>\n<p><code>vi \/etc\/opendkim\/TrustedHosts<\/code><\/p>\n<blockquote><p>domain.tld<\/p><\/blockquote>\n<p>Repeat the same steps if you want opendkim to sign the different domains.<\/p>\n<p>Now, the final steps to add the DNS record on the <em>Nameserver<\/em>. We need to add TXT record on the nameserver of the domain.tld.<\/p>\n<p><code>cat \/etc\/opendkim\/keys\/domain.tld\/default.txt<\/code><\/p>\n<blockquote><p>default._domainkey&nbsp;&nbsp; &nbsp;IN&nbsp;&nbsp; &nbsp;TXT&nbsp;&nbsp; &nbsp;( &#8220;v=DKIM1; k=rsa; &#8221;<br \/>\n&#8220;p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCzkmrP3nbiXJNXU4UKAJAQX9JPtKhe5+EgfWkkc4mUsFfftGyKMW3oNkM40qldg4XhazCbW1BruQKaXwH\/qWSGdFBQMem9ytF+xZwLDraNKVtRto9bPBpf+VEU34t3Pwarm179\/anahErnSIWENfAeP\/nWrf5qIHBjwsTtF59XgwIDAQAB&#8221; )<\/p><\/blockquote>\n<p>DNS changes normally requires 12 to 24 hours to reflect all over the world.<\/p>\n<p>We can verify the DNS changes using the below commands.<\/p>\n<p><code>host -ttxt default._domainkey.domain.tld<\/code><\/p>\n<p><code>dig txt +short default._domainkey.tld<\/code><\/p>\n<h5>Configure Postfix:<\/h5>\n<p>So far, we have installed opendkim and now we are going to integrate opendkim with postfix application<\/p>\n<p>Open the configuration \/etc\/postfix\/main.cf and add the opendkim integration code.<\/p>\n<p><code>vi \/etc\/postfix\/main.cf<\/code><\/p>\n<blockquote><p>smtpd_milters&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = inet:127.0.0.1:8892<br \/>\nnon_smtpd_milters&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = $smtpd_milters<br \/>\nmilter_default_action&nbsp;&nbsp; = accept<br \/>\nmilter_protocol&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 2<\/p><\/blockquote>\n<p>Restart the opendkim, postfix services.<\/p>\n<p><code>service opendkim start<br \/>\nchkconfig opendkim on<br \/>\nservice postfix restart<\/code><\/p>\n<h5>Verification:<\/h5>\n<p>Now, send mail from your domain.tld either using application and check the results on the log.<\/p>\n<pre> Feb 20 12:12:58 server opendkim[5644]: 5FF7E161215: DKIM-Signature field added (s=default, d=<\/pre>\n<p><strong>domain.tld<\/strong><\/p>\n<pre>)<\/pre>\n<p>We can send emails to <em>check-auth@verifier.port25.com <\/em> and you will receive a notification whether dkim signature added or not.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Date Posted:22-02-2017 Its a biggest challenge for a new mail server to reach popular mail provider user&#8217;s inbox. One of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1019],"tags":[161,286,171],"class_list":["post-1135","post","type-post","status-publish","format-standard","hentry","category-cloud-aws","tag-centos","tag-opendkim","tag-postfix","psol-cat-cloud-aws"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-ij","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1135","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=1135"}],"version-history":[{"count":0,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1135\/revisions"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=1135"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=1135"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=1135"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}