# Ubuntu LTS Email Server Setup This document assumes that you have set up a debian 9 or ubuntu LTS server(/container) set up and that postfix/email has been set up using tasksel. ## Dovecot (imap server) and Postfix (mail server) configure dovecot to use self signed ssl cert created by postfix. root@naomi:/etc/postfix# cd ../dovecot/conf.d/ root@naomi:/etc/dovecot/conf.d# nano 10-ssl.conf ## ## SSL settings ## # SSL/TLS support: yes, no, required. ssl = yes # PEM encoded X.509 SSL/TLS certificate and private key. They're opened before # dropping root privileges, so keep the key file unreadable by anyone but # root. Included doc/mkcert.sh can be used to easily generate self-signed # certificate, just make sure to update the domains in dovecot-openssl.cnf ssl_cert = >/etc/bind/zones/suspectdevices.hosts Fix the error in dns entry and increment the zones serial number root@naomi:/etc/opendkim/keys# nano /etc/bind/zones/suspectdevices.hosts @ IN SOA dns1.digithink.com. don.digithink.com ( 2018072200 10800 3600 3600000 86400 ) ...change.this. YYYYMMDDxx .... ... ... and change h=rsa-sha256 to h=sha256 ... ...as below... 201807._domainkey IN TXT ( "v=DKIM1; h=sha256; k=rsa; s=email; " "p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6ymvRll+pEDThA6fMersYbr6dB5HKIFl4SMSF3ORxkFmrYC//wm6/vrqWNft3AWy4zC7AQNiKyQGg7$ "BUpxeL2bSGUhMrcZ+OheWWzw7aF746IOYO0IR4oMTFNP9a6hrmwBrLmnA8ploFYUWCa2ETq/VYP6i14LU7P/yi8JhDMu4ZVI6ytlynBcLU42orcNWjWNLHqy/F3L$ Reload bind and check key root@naomi:/etc/opendkim/keys# service bind9 reload root@naomi:/etc/opendkim/keys# service bind9 status ● bind9.service - BIND Domain Name Server Loaded: loaded (/lib/systemd/system/bind9.service; enabled; vendor preset: enabled) .... Jul 25 22:35:15 naomi named[28512]: reloading zones succeeded .... root@naomi:/etc/opendkim/keys# opendkim-testkey -d suspectdevices.com -s 201807 -vvv opendkim-testkey: using default configfile /etc/opendkim.conf opendkim-testkey: checking key '201807._domainkey.suspectdevices.com' opendkim-testkey: key not secure .... ignore this .... opendkim-testkey: key OK Add entries to key.table signing.table and trusted hosts. ``` root@naomi:/etc/opendkim# nano key.table fromhell fromhell.com:201807:/etc/opendkim/keys/fromhell.private suspectdevices suspectdevices.com:201807:/etc/opendkim/keys/suspectdevices.private root@naomi:/etc/opendkim# nano signing.table *@fromhell.com fromhell *@suspectdevices.com suspectdevices root@naomi:/etc/opendkim# nano trusted.hosts 127.0.0.1 ::1 198.202.31.221 198.202.31.242 localhost *.fromhell.com *.suspectdevices.com ``` Configure socket file to communicate with postfix and add postfix to opendkim group. root@naomi:~# mkdir -p /var/spool/postfix/var/run/opendkim root@naomi:~# chown -R opendkim:opendkim /var/spool/postfix/var/run/opendkim root@naomi:~# touch /var/spool/postfix/var/run/opendkim/opendkim.sock root@naomi:~# chmod 775 /var/spool/postfix/var/run/opendkim/opendkim.sock root@naomi:~# usermod -a -G opendkim postfix root@naomi:~# nano /etc/default/opendkim ... DAEMON_OPTS="-vvvv" SOCKET="local:/var/spool/postfix/var/run/opendkim/opendkim.sock" RUNDIR=/var/spool/postfix/var/run/opendkim USER=opendkim GROUP=opendkim PIDFILE=$RUNDIR/$NAME.pid EXTRAAFTER= ... Add filter to postfix and restart both services. root@naomi:~# nano /etc/postfix/main.cf ... milter_protocol = 6 milter_default_action = accept smtpd_milters = unix:/var/run/opendkim/opendkim.sock non_smtpd_milters = unix:/var/run/opendkim/opendkim.sock ... root@naomi:~# service opendkim reload root@naomi:~# service postfix reload Send test mail root@naomi:~# echo "dkim test" |mail -testopendkim check-auth@verifier.port25.com #### adding signatures to relayed hosts To relay mail from other hosts on the local networks requires the following additions to postfix's main.cf root@naomi:~# nano /etc/postfix/main.cf ... mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128, 198.202.31.128/25 ... masquerade_domains = suspectdevices.com, fromhell.com #### openDKIM/SPF links * https://www.cioby.ro/2013/11/14/configuring-opendkim-to-sign-postfix-emails/ * https://linuxaria.com/howto/using-opendkim-to-sign-postfix-mails-on-debian * http://www.openspf.org/SPF_Record_Syntax * https://blog.whabash.com/posts/send-outbound-email-postfix-dkim-spf-ubuntu-16-04 * https://www.linode.com/docs/email/postfix/configure-spf-and-dkim-in-postfix-on-debian-8/ * https://www.linuxbabe.com/mail-server/setting-up-dkim-and-spf * https://tools.ietf.org/html/rfc6376 * https://tweenpath.net/opendkim-postfix-smtp-relay-server-on-debian-7/ * https://qureshi.me/how-to-setup-postfixdkimspfdmarc-on-ubuntu-plesk-onyx/ ## Configure root/notification mail from other systems (esp bs2020) Systems need to be able send email to notify us of issues such as security updates (apticron) etc. In order for email to be signed by opendkim and validated by spf the email needs to strip the hostname from mail sent from it before being relayed through the mail server. root@bs2020:~# apt-get install mailutils apticron ... select satellite server when asked ... root@bs2020:~# nano /etc/postfix/main.cf ... add the following ... relayhost = naomi.suspectdevices.com compatibility_level=2 masquerade_domains = suspectdevices.com Since all systems will be striped of their machine names insure the full name of common accounts is made to be uniq root@bs2020:~# chfn -f "Root at BS2020" * http://www.postfix.org/STANDARD_CONFIGURATION_README.html * https://www.tecmint.com/setup-postfix-mail-server-smtp-using-null-client-on-centos/ _Todo:_ * I think postfix is a little heavy handed to run a null client. Investigate simpler secure solution. * add amivis,and other filters linked in at https://help.ubuntu.com/community/MailServer * make procmail do some work since its enabled by default * make damned sure that it wont accept mail from the entire c-block