[SOLVED] fail2ban mail problems.

Discussion in 'Server Operation' started by Taxick, Oct 3, 2022.

Tags:
  1. Taxick

    Taxick Member

    Hi :)
    I have just installed my new server that runs Ubuntu 22.04 (It's hosted with hetzner.de).
    But I have a problem with fail2ban.
    When my server boot, fail2ban make some errors and don't send mails.
    If I run "systemctl status fail2ban" it gives me this error:
    mailgun-error.jpg
    If I then run "systemctl restart fail2ban" and then "systemctl status fail2ban" its working fine..
    mailgun-fix.jpg
    I hope you can help me out here.. If you need any info.. Just say it, and i will post it.
    EDIT:
    I use ssmtp as mail relay, that sending to mailgun. - I have attached my jail.local and my fail2ban.conf
     
    Last edited: Oct 3, 2022
  2. Taleman

    Taleman Well-Known Member HowtoForge Supporter

    The first error message looks like fail2ban starts too soon, before name resolving works. Have you modified the startup file or files? Are you using systemd or modified Ubuntu to use some other startup script handler for booting?
    Maybe try to debug the booting sequence, or undo your changes if you have done any for the booting.
     
  3. Taxick

    Taxick Member

  4. Taxick

    Taxick Member

    Hi agian
    I fixed the error by open "/lib/systemd/system/fail2ban.service"
    and put this code in it: ExecStartPre=/bin/sleep 30
    Thanks for the help.
     
  5. pyte

    pyte Well-Known Member HowtoForge Supporter

    Uhh that is quiet hacky. Your way is working but it is not a good practice to just wait x seconds because we assume network is present then. Use the builit "After" feature is much more reliable. Fix the systemd unit like this:

    There is a line in the unitfile under the "[Unit]" section which starts with "After=", just add
    "After=network-online.target ..." and you should be good to go.

    don't forget the systemctl daemon-reload afterwards :)
     
  6. Taxick

    Taxick Member

    HI..
    Thanks for your big help. I have used the solution you provided and it works perfectly!
    Thanks
     
    pyte likes this.

Share This Page