Install A Mail Server On Debian ?

Father

Professional
Messages
2,601
Reputation
4
Reaction score
633
Points
113
First of all you need to configure a DNS. If you take a look into the `/etc/hosts`file you should have following lines:
Code:
┌──(father㉿cardingcrew)-[~]
└─$ cat /etc/hosts
127.0.0.1 localhost
127.0.1.1 viperzcrew

If you change 127.0.0.1 to
Code:
127.0.0.1 google.com

And you have an Apache service running, your browser will save google.com if you are typing it but the default apache2 page will be shown.

Let's assume OUR new DNS is for example : mrblackx.service.com
Code:
echo "mrblackx.service.com" > /etc/hostname

hostname "mrblackx.mail.server.com"

sudo apt install -y -q postfix opendkim opendkim-tools

Let's add the users 'postifx' and 'opendkim'.
Code:
adduser postfix opendkim

Now you are creating a file > /etc/opendkim.conf and paste following:
(Make sure you use your own created domain name)
Code:
Syslog  yes
UMask   002
Domain  father.service.com
Keyfile /etc/mail.private
InternalHosts   /etc/opendkim.TrustedHosts
Selector        mail
OversignHeaders From
Canonicalization        relaxed/relaxed

Use a tab between the values.

Let's add trusted host:
Code:
echo -e "127.0.0.1\nlocalhost\nmrblackx.service.com" > /etc/opendkim.TrustedHosts

Note: I used \n for a new line, make sure you are using the -e for escaped characters.
Code:
echo 'SOCKET="inet:8891@localhost"' >> /etc/default/opendkim

Let's generate an opendkim key:
Code:
opendkim-genkey --domain=mrblackx.service.com --restrict --selector=mail --subdomain --directory=/etc
chown opendkimpendkim /etc/mail.private

To configure postfix we use postconf command:
Code:
postconf -e "milter_default_action = accept"
postconf -e "milter_protocol = 6"
postconf -e "smtpd_milters = inet:localhost:8891"
posfconf -e "non_smtpd_milters = inet:localhost:8891"

Adding our mailserver to the mailname :
Code:
echo "mrblackx.service.com" >> /etc/mailname

Starting services:
Code:
sudo service opendkim start
sudo service postfix start

Now head over to your DNS board and add following entry for SPF:
Code:
Record : mrblackx.service.com
Value : v=spf1 a:mrblackx.service.com -all

Use your domain!!

DMARC record:
Code:
Record : _dmarc.mrblackx.service.com
Value : v=DMARC1; p=none

DKIM Record:
Code:
Record : mail._domainkey.mrblackx.service.com
 (http://mail._domainkey.mrblackx.service.com/)Value : v=DKIM1; k=rsa; s=email; p=MIIB....

The .... means you have a different MIIB than me. If you need help watch this video :


Depending on the mail server it takes 15 minutes to 72 hours.

(BONUS) IP Rotate for sending:

For each public IP adress, for example 200.200.200.200 run this command
Code:
iptables -t nat -I POSTROUTING -m state --state NEW -p tcp --dport 25 -o eth0 -m
statistic --mode nth --every 5 -j SNAT --to-source 200.200.200.200

Repeat it for each public IP.
 
Top