Until Corona i never had big problems with my mailserver but in the last weeks i got very big incoming Traffic - that was too much for my server and i had to manually reboot it every time ...
I know DDoS protection solutions for websites like Cloudflare - but as far as i know Cloudflare doesn't work with mailserver because of the reverse DNS lookup which is needed to communicate with big email providers.
So does anyone had the same problems and found a solution for it? (A solution other than just switching to Gmail or other big players)
Edit: i changed my fail2ban settings and found out i was primarily targeted by brute force attacks which i should be able to protect against with tools like fail2ban
Inbound mail traffic should be routed through lightweight MX servers. It's a common mistake to put an MX and a mail store on the same system. You can deploy new MX endpoints all day long and just update your DNS for it and email will still work pretty well.
Although there are perfectly reasonable arguments against it, Fail2Ban or similar can shut down nuisance traffic on a mail store. You should beware though that it's difficult to ensure that Fail2Ban or other active-response log monitoring can't itself be abused to ruin your day.
If your mail store is just getting hammered, it's a tricky problem to solve without a lot of resources. If you're the only user on your system, there's no reason to publish a dns record for your mail store, so move it to a new ip and update your settings. If you can't do that and Fail2Ban can't resolve it, you get to start thinking about things like distributed mail storage. I've been wanting to check out dbmail for years (https://github.com/dbmail/dbmail/), maybe you can give that a whirl and link a writeup of your experiences with it.
I have experimented a bit here and there with dovecot-on-mysql and multi-master percona and all that and it's not fun or reliable.
If you're getting mind-blowing amounts of spam -- especially if it's newsletter signups -- it's possible you're being mailbombed. That sucks, there aren't a lot of good solutions for that right now, even Gmail users can be victimized by it. It seems to often be associated with some financial fraud, probably because those suspicious activity notifications kinda disappear when you're getting 20,000+ messages a day. I'm working on some software for this, it's in limited testing now but still really rough. Email is hard to write good software for.
Some of the simpler DDoS attacks can be mitigated by kernel settings and iptables (see e.g. https://javapipe.com/blog/iptables-ddos-protection/), but that won't help you much against larger attacks.
Most common one is just to dump too much traffic, so network can't handle it.
Others are less common but can cause server to become unresponsive due to exhausting some other resource than network (cpu, file descriptors, huge amount of swap, ...)
For the first type of attack you can't do much on your own you have to either work with your isp (or CDN for web traffic)
If your server is still reachable over network but unresponsive that means you are suffering from second type. That you can usually do something about.
You could put firewall with rate limiting (sometimes called traffic shaping), connections to your mail server.
Setting up firewall is not something I can guide you in a comment so google for it.
Good free one is pfsense
Depending on how these ddos attacks are getting sent this might help.
Use iostat, netstat, lsof, top, strace. Locate problematic process, incoming and outgoing traffic, unexpected open ports, check mailboxes user and system folders....
In any case use the usual tools to narrow the problems by process, socket status, user, ips, scenarios.
If the problem fade with a reboot you can be the target or being part of a botnet.
We rely on Mailinabox, which has fail2ban but the server being on a DigitalOcean network, they claim to offer some kind of DDOS protection.
* don't reboot a server until its really necessary - like a kernel upgrade etc.
rebooting is never a solution, this is just pointless "panic mode":
if its still possible: investigate why the system becomes slowed down ... a hardware-problem/ram or other resource-constaints or "real" dos-problems like out-of-tcp-connections etc.
* for this: use proper monitoring - mainly graphing - as simple as munin or more complex like prometheus & grafana
hey ... its just a small mailsystem you don't need any of the latest and greatest paid service for this.
* personally i operate a small mailsystem since the ancient times of the internet - aka 90ties - sendmail/qmail/qmail-ldap and atm exim-ldap. around 300 mailboxes - more or less my friends & familly.
for example: i'm using dynamic blocking similar to fail2ban for smtp-auth brute-force - implemented in bash/python; spamassassin & clamav for spam - custom config: mainly blocked most of the "crap" TLDs like .icu etc...
You will lose your old IP address, but the DNS should be fully functional.
1) check that our MTA is up to date 2) check that we got fail2ban rules for POP&SMTP failed logins 3) use a haproxy and ban by subnet/country