Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Will running both fail2ban and ufw cause problems? I noticed that fail2ban modifies iptables rules, but ufw already has a ton of iptables rules defined... so I'm not sure if fail2ban will mess these up.

share|improve this question
    
Which Ubuntu version? ('ufw' has improved slightly between 10.04 LTS and 11.x) –  david6 Dec 5 '11 at 22:06
    
@david6: sorry, I don't recall what version I was running when I originally asked the question. –  Adam Monsen May 21 at 20:15
add comment

2 Answers 2

up vote 12 down vote accepted
+50

You can use ufw and fail2b together, but as indicated earlier, the order of (ufw) rules is what is important.

Out of the box, fail2ban uses iptables and inserts rules first in the INPUT chain. This will not do any harm or conflict with ufw.

If you wish to fully integrate fail2ban to use ufw (rather then iptables). You will need to edit a number of files including

/etc/fail2ban/jail.conf

jail.conf is where you define your services , including what port they are listening on (think changing ssh to a non-default port) and what action to take.

Using ssh as an example, note the definition of a non-default port as well =)

[ssh]
enabled = true
banaction = ufw-ssh
port = 2992
filter = sshd
logpath = /var/log/auth.log
maxretry = 3

You then configure fail2ban to use ufw in (one .conf file for each service)

/etc/fail2ban/action.d/ufw-ssh.conf

The syntax is

[Definition]
actionstart =
actionstop =
actioncheck =
actionban = ufw insert 1 deny from <ip> to any app OpenSSH
actionunban = ufw delete deny from <ip> to any app OpenSSH

Note: You configure fail2ban to use ufw and to insert new rules FIRST using the "insert 1" syntax. The delete will find the rule regardless of order.

There is a nice blog post that goes into more detail here

http://blog.vigilcode.com/2011/05/ufw-with-fail2ban-quick-secure-setup-part-ii/

share|improve this answer
1  
So in short: without doing the integration as explained, both ufw and fail2ban work like they should. Fail2ban will insert its blocking definitions before ufw's rules are applied. On the other hand if one would like to have the blocks show up in ufw status, you need the integration. Besides having the blocks show up in ufw status, there would be no other benefit? Particularly because the author of the blog says the following: Out of the box Fail2ban works with iptables rules, however these don’t play nice with our simpler UFW commands(...) –  bouke Dec 5 '11 at 21:51
    
Exactly. "Don't play nice" equates to do not show up when you check them with ufw status. The benefits of integration are that you are using one tool , ufw, to manage and display your firewall rules. Nothing wrong with using fail2ban as is, out of the box, in terms of function. The problem would be that to see fail2ban rules you would need to use iptables -L -v -n , and as you can already see, when using ufw the output is long and difficult to follow. The advantage of integration is that the rules and the syntax is then easier to understand (assuming that is why you use ufw in the first place) –  bodhi.zazen Dec 5 '11 at 21:55
add comment

I have been using fail2ban and ufw for years on couple of different computers, and never had any problems. To setup fail2ban:

sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
sudo nano jail.local

Now edit the file as you wish, for example if you want to block unauthorized ssh find the lines:

[ssh]
enabled  = true
port     = ssh
filter   = sshd
logpath  = /var/log/auth.log
maxretry = 6

if "enabled" is set to "false", change it to "true" as noted here. After you set the rules you need to restart the fail2ban process:

sudo /etc/init.d/fail2ban restart

If you've opened the port 22 on your ufw firewall fail2ban will ban the clients that try to connect more than 6 times without success, it will not break your firewall.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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