Setup OpenDKIM With Postfix On Linux

This guide is going to work off the assumption that you already have a functional email server running with postfix on your server. This guide will show you how to setup OpenDKIM with postfix on a linux server

yum install epel-release
yum install opendkim

 

Now that opendkim is installed, you need to generate the dkim keys that you need to use to sign the emails with. There are multiple ways to do this. You can do it through the command line or you can use this service http://dkimcore.org/tools/keys.html.

mkdir /etc/opendkim/keys/example.com
chown -R opendkim:opendkim /etc/opendkim/keys/example.com
touch /etc/opendkim/keys/example.com/default

Open up this directory and open the file called “default”. Paste your private key into this file. For safe keeping you could also create another file called “public.txt” and pop the public key into this file so you can access it in the future if you need it.

Sometimes default permissions dont get correctly set. In the event that this happens run the following. There is no harm just running this query anyway.

chown -R opendkim:opendkim /etc/opendkim
chmod -R go-wrx /etc/opendkim/keys

Open up “/etc/opendkim.conf” and replace everything with the following

AutoRestart Yes
AutoRestartRate 10/1h
Canonicalization relaxed/simple
ExternalIgnoreList refile:/etc/opendkim/TrustedHosts
InternalHosts refile:/etc/opendkim/TrustedHosts
KeyTable refile:/etc/opendkim/KeyTable
LogWhy Yes
Mode sv
PidFile /var/run/opendkim/opendkim.pid
SignatureAlgorithm rsa-sha256
SigningTable refile:/etc/opendkim/SigningTable
Socket inet:8891@localhost
Syslog Yes
SyslogSuccess Yes
TemporaryDirectory /var/tmp
UMask 022
UserID opendkim:opendkim

You now need to add a key to the keytable. This file is located in /etc/opendkim/keytable

default._domainkey.example.com example.com:default:/etc/opendkim/keys/example.com/default

You will also need to add a line to the signing table.
If the file doesnt exist, create it. “/etc/opendkim/SigningTable”

*@example.com default._domainkey.example.com

Open or create “/etc/opendkim/TrustedHosts” and add the following.

127.0.0.1
hostname1.example1.com
example1.com
hostname1.example2.com
example2.com

Add the following to your postfix main.cf file. This will instruct postfix to sign the emails with the DKIM key you setup.

smtpd_milters = inet:127.0.0.1:8891
non_smtpd_milters = $smtpd_milters
milter_default_action = accept
milter_protocol = 2

Thats all thats needed. Now run opendkim and restart postfix and you should be good to go.

service opendkim start
service postfix restart

 

Related Articles

Related Questions

MERN vs. Django: Which Tech Stack Should I Choose?

I'm torn between choosing the MERN stack (MongoDB, ExpressJS, ReactJS, NodeJS) and Django, the Python-based framework. Considering I'm graduating in 2027, which one is...

Is it smart to invest in premium parts for my PC build?

I'm diving into my first PC build and trying to strike a balance between performance and budget since I'll need to save for a...

Help! My PC Keeps Restarting and There’s No Display – What Could Be Wrong?

Hey everyone! I'm facing a peculiar problem with my PC that's been happening lately, and I could use some guidance. When I press the...

1 COMMENT

  1. Hello, thanks for the detailed write up. I just tried this out, but after implementation I get this error SMTP Error: [451] 4.7.0 resource unavailable

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Latest Tools

Convert CSV To HTML Table

Need to quickly turn CSV data into an HTML table? Whether you're copying data from Excel, Google Sheets, or another spreadsheet, this tool makes...

Student Group Randomizer

Creating fair and balanced groups in the classroom can be time-consuming — especially when you're trying to avoid repetition, manage different skill levels, or...

Random Group Generator

Need to split a list of people, items, or ideas into random groups? Our free Random Group Generator makes it quick and easy. Whether...

Flip Text Upside Down – Free Online Tool

Ever wanted to flip your text upside down just for fun or to grab someone’s attention in a creative way? This free online Upside...

Raffle Ticket Generator

If you're running a fundraiser, charity draw, or local event and need raffle tickets fast, this free online tool lets you generate and print...

Random Number Generator – Create Multiple Random Numbers Instantly

Welcome to our free, browser-based Random Number Generator – a fast and flexible tool designed to help you generate as many random numbers as...

Latest Posts

Latest Questions