Blog | G5 Cyber Security

Block Anonymous SMTP Connections

TL;DR

This guide shows you how to stop email being sent through your server if someone tries to use it without logging in properly (using a username and password). This helps prevent spam and abuse.

Steps

  1. Understand the Problem
  2. Sometimes, people try to send emails through your server without having valid accounts. This is called anonymous SMTP relaying. It’s bad because:

We will configure the server to only accept connections from authenticated users.

  • Identify Your Mail Server Software
  • The steps vary depending on what software you’re using. Common options include:

    If you’re not sure, ask your hosting provider or check your server documentation.

  • Postfix Configuration (Example)
  • These instructions are for Postfix. If you use different software, see the next section for general guidance.

    1. Edit main.cf: Open the main configuration file with a text editor as root or using sudo.
      sudo nano /etc/postfix/main.cf
    2. Add/Modify Settings: Add these lines to your main.cf file (or modify them if they already exist):
      smtpd_tls_auth_only = yes
      smtp_sasl_auth_enable = yes
      smtp_sasl_security_options = noanonymous
    3. Restart Postfix: Apply the changes by restarting the service.
      sudo systemctl restart postfix
  • General Guidance for Other Mail Servers
  • Most mail servers have similar settings. Look for options like:

    Consult your mail server’s documentation for specific instructions.

  • Testing the Configuration
    1. Try to Send an Email Without Authentication: Use a command-line email client (like telnet or openssl s_client) or a simple email program and try sending an email without providing a username and password. It should fail.
      openssl s_client -starttls smtp -connect your.mail.server:25
    2. Send an Email With Authentication: Now, send an email with valid credentials. This should succeed.
    3. Check Logs: Examine your mail server’s logs for any errors or warnings related to authentication. The log location varies depending on the software (e.g., /var/log/mail.log for Postfix).
  • Firewall Considerations
  • Ensure your firewall allows connections on port 25 (SMTP), but consider restricting access to trusted IP addresses if possible.

    Exit mobile version