Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
fail2ban not applying port/protocol to iptables [SOLVED]
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
hanj
Veteran
Veteran


Joined: 19 Aug 2003
Posts: 1500

PostPosted: Sat Aug 11, 2007 6:59 pm    Post subject: fail2ban not applying port/protocol to iptables [SOLVED] Reply with quote

Hello

Been playing around with fail2ban this morning.. like it. They did a great job over the last versions! I'm running across a problem though, it doesn't appear that the iptables rule created is using the port and protocol values in jail.conf.

For example.. I have this in jail.conf:
Code:
[spam]
enabled  = true
filter   = spam
action   = iptables[name=SPAM, port=25, protocol=tcp]
           mail-whois[name=SPAM, dest=abuse@comp.com]
logpath  = /var/log/mail.log
ignoreip = 127.0.0.1 xxx.xxx.xxx.xxx
maxretry = 2


I tried port=25 as well as port=smtp.. and the results are the same. When looking at what is created in iptables... I see the following:
Code:
Chain fail2ban-SPAM (1 references)
target     prot opt source               destination
DROP       all  --  xxx.126.1.68         0.0.0.0/0
DROP       all  --  xxx.88.229.7         0.0.0.0/0
DROP       all  --  xxx.4.23.37          0.0.0.0/0
RETURN     all  --  0.0.0.0/0            0.0.0.0/0


This isn't correct, since it's going to DROP all traffic to any port from the violating IP. Not what I want, I just want to drop 25. It should look like this:
Code:
Chain fail2ban-SPAM (1 references)
target     prot opt source               destination
DROP       tcp  --  xxx.126.1.68         0.0.0.0/0           tcp dpt:25
DROP       tcp  --  xxx.88.229.7         0.0.0.0/0           tcp dpt:25
DROP       tcp  --  xxx.4.23.37          0.0.0.0/0           tcp dpt:25
RETURN     all  --  0.0.0.0/0            0.0.0.0/0


Anyone know what I'm doing wrong? Here is my version:
Code:
net-analyzer/fail2ban-0.8.0-r1


Thanks!
hanji
_________________
Server Admin Blog - Uno-Code.com


Last edited by hanj on Sat Aug 11, 2007 7:23 pm; edited 1 time in total
Back to top
View user's profile Send private message
hanj
Veteran
Veteran


Joined: 19 Aug 2003
Posts: 1500

PostPosted: Sat Aug 11, 2007 7:22 pm    Post subject: Reply with quote

I figured this out.
Edit /etc/fail2ban/actions/iptables.conf

Change:
Code:
actionban = iptables -I fail2ban-<name> 1 -s <ip> -j DROP


To:
Code:
actionban = iptables -I fail2ban-<name> 1 -s <ip> -p <protocol> --dport <port> -j DROP


Now I see:
Code:
Chain fail2ban-SPAM (1 references)
target     prot opt source               destination
DROP       tcp  --  xxx.33.231.104        0.0.0.0/0           tcp dpt:25
DROP       tcp  --  xxx.237.113.8         0.0.0.0/0           tcp dpt:25
DROP       tcp  --  xxx.19.193.194        0.0.0.0/0           tcp dpt:25
DROP       tcp  --  xxx.36.147.159        0.0.0.0/0           tcp dpt:25
RETURN     all  --  0.0.0.0/0            0.0.0.0/0

HTH
hanji
_________________
Server Admin Blog - Uno-Code.com
Back to top
View user's profile Send private message
hanj
Veteran
Veteran


Joined: 19 Aug 2003
Posts: 1500

PostPosted: Sat Aug 11, 2007 7:52 pm    Post subject: Reply with quote

You'll need to change the actionunban as well:

FROM:
Code:
actionunban = iptables -D fail2ban-<name> -s <ip> -j DROP


TO:
Code:
actionunban = iptables -D fail2ban-<name> -s <ip> -p <protocol> --dport <port> -j DROP


hanji
_________________
Server Admin Blog - Uno-Code.com
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum