Someone told me this is possible, but I can't find anything on google or man pages.
I need to ban IPs for a certain amount of time, and then have then unbanned automatically.
|
|
|
If you mean for iptables to completely remove the rule by itself you won't be able to do it, as far as I know. What's the purpose of this? If you need some kind of automatic temporary banning the standard solution is fail2ban. Alternatively you can use a cron job to remove the rule you're adding, or, better if you want to do it interactively, an
Also take a look at the |
|||||
|
|
Put a comment with a timestamp (probably seconds since the epoch) in the rules. Periodically sweep for expired rules. Note that the most recent linux kernel has support for dynamic loading of IPs into a cache consulted by iptable rules instead of as direct iptables rules. Example:
You can of course |
|||||||||
|
|
You can use fail2ban to ban ip addresses and configure the length of time an address will be banned for. |
|||
|
|
|
IPTables has a feature made expressly for this: IP Set. You make the rule once and it persists as usual but it checks in a set of ips (or ports) for matches. The cool thing is that this set can be dynamically and efficiently updated without disturbing the rest of the firewall. So, to use it, you would still have to use |
|||
|
|
|
Depending on what exactly you want to accomplish the either the netfilter recent or time modules could be used to accomplish this. Both are documented in the iptables man page. |
|||
|
|