I installed fail2ban from EPEL using yum install, and then proceeded to screw up the configuration after forgetting to back up /etc/fail2ban.

Now I want the original configuration back.

First I tried yum reinstall fail2ban, but that was silly because yum install doesn't overwrite existing configuration files. Then I mved /etc/fail2ban somewhere else and tried yum reinstall fail2ban again, which according to some old blog post would give me the original configuration back. No such luck. I tried uninstalling with rpm -e and reinstalling. No such luck. I got frustrated and rm -rfed my /etc/fail2ban.backup directory, thinking maybe there was some kind of weird system discovery going on. Still nothing after reinstalling.

Finally I downloaded and unpacked the RPM source and rsynced the config directory to /etc/fail2ban, which got me most of the way there. But there are still a few differences in how the log files are set up and in how it integrates with systemd. Instead of Frankensteining something together, I really just want the original configuration back.

Is there a way to force a fresh install of an RPM package, including config and log files, either with YUM or some other tool? I'm using the standard Linode CentOS 7 image, if that matters at all.


I think yum is too conservative to do what you want. For best results, you should also be prepared to use some rpm commands.

this will scrub all of the files rpm (ergo yum) know/trust belong to the fail2ban package.

rpm -e --justdb --nodeps fail2ban

After that, you can remove/move your /etc files and yum will reinstall.

All the magic yum/rpm is doing with config files is in the RPM spec file in lines with the prefix "%config(noreplace)" with the macro "%{_sysconfdir}" which means '/etc' in your case. Just get those all out of the way, and the rpm will install all of its default config files.

%config(noreplace) %{_sysconfdir}/fail2ban
%config(noreplace) %{_sysconfdir}/logrotate.d/fail2ban
%config(noreplace) %{_sysconfdir}/fail2ban/jail.d/00-firewalld.conf
%config(noreplace) %{_sysconfdir}/fail2ban/action.d/hostsdeny.conf
%config(noreplace) %{_sysconfdir}/fail2ban/action.d/complain.conf
%config(noreplace) %{_sysconfdir}/fail2ban/action.d/mail-*.conf
%config(noreplace) %{_sysconfdir}/fail2ban/action.d/sendmail-*.conf
%config(noreplace) %{_sysconfdir}/fail2ban/action.d/shorewall.conf
%config(noreplace) %{_sysconfdir}/fail2ban/jail.d/00-systemd.conf

Have a look for yourself:

curl 'http://pkgs.fedoraproject.org/cgit/rpms/fail2ban.git/plain/fail2ban.spec?h=epel7' |
 grep '^%config(noreplace)'
  • This didn't work. rpm -e --justdb --nodeps fail2ban succeeded silently, rm -rf /etc/fail2ban went as expected, but then yum install fail2ban didn't replace the files I deleted. Thanks for the tip about the spec file, though. – shadowtalker Mar 5 '17 at 6:14
  • Did you get any /etc/fail2ban files when reinstalling? Did you notice that you also need to clean out /etc/logrotate.d/fail2ban? The next step is for you to download the fail2ban rpm and install it with "rpm -i -vv --allfiles --force fail2ban-0.9.6-3.el7.noarch.rpm" – Jeremy Mar 7 '17 at 14:41
  • it turns out the config files were regenerated when I installed the dependency packages. See my answer (unix.stackexchange.com/a/349231/73256). Not sure what exactly happened but I'm happy it's fixed. – shadowtalker Mar 7 '17 at 15:29

On my system, fail2ban is actually spread across several packages:

  • fail2ban
  • fail2ban-firewalld
  • fail2ban-systemd
  • fail2ban-sendmail
  • fail2ban-server
  • systemd-python

Evidently, the configuration files don't get generated unless some or all of the above are installed. yum autoremove got rid of them, and then yum install fail2ban restored the original config files.


I needed to do this steps to solve the same problem:

sudo yum autoremove fail2ban -y
sudo yum autoremove fail2ban-server -y
sudo yum install fail2ban -y

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.